modelize_property: use resolve_mtype_unchecked during build_signature
[nit.git] / lib / mnit_android / android_assets.nit
index 41e889b..8f61c90 100644 (file)
@@ -21,7 +21,7 @@
 # * The Android ndk
 # * zlib (which is included in the Android ndk)
 # * libpng which must be provided by the Nit compilation framework
-module android_assets
+module android_assets is ldflags "-lz"
 
 import mnit
 import android_app
@@ -129,8 +129,8 @@ redef class Opengles1Image
                int has_alpha;
 
                unsigned int row_bytes;
-               png_bytepp row_pointers;
-               unsigned char *pixels;
+               png_bytepp row_pointers = NULL;
+               unsigned char *pixels = NULL;
                unsigned int i;
 
                unsigned char sig[8];
@@ -168,14 +168,22 @@ redef class Opengles1Image
                                                &depth, &color_type, NULL, NULL, NULL);
                has_alpha = color_type & PNG_COLOR_MASK_ALPHA;
 
+               // If we get gray and alpha only, standardize the format of the pixels.
+               // GA is not supported by OpenGL ES 1.
+               if (!(color_type & PNG_COLOR_MASK_COLOR)) {
+                       png_set_gray_to_rgb(png_ptr);
+                       png_set_palette_to_rgb(png_ptr);
+                       png_read_update_info(png_ptr, info_ptr);
+               }
+
                LOGW("w: %i, h: %i", width, height);
 
                row_bytes = png_get_rowbytes(png_ptr, info_ptr);
                pixels = malloc(row_bytes * height);
-        row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
+               row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
 
-        for (i=0; i<height; i++)
-            row_pointers[i] = (png_byte*) malloc(row_bytes);
+               for (i=0; i<height; i++)
+                       row_pointers[i] = (png_byte*) malloc(row_bytes);
 
                png_read_image(png_ptr, row_pointers);
 
@@ -192,6 +200,15 @@ redef class Opengles1Image
                else
                        png_destroy_read_struct(&png_ptr, NULL, NULL);
 
+               if (pixels != NULL)
+                       free(pixels);
+
+               if (row_pointers != NULL) {
+                       for (i=0; i<height; i++)
+                               free(row_pointers[i]);
+                       free(row_pointers);
+               }
+
        close_stream:
                return recv;
        `}