< prev index next >

src/java.desktop/share/native/libsplashscreen/splashscreen_png.c

Print this page




  31 
  32 #define SIG_BYTES 8
  33 
  34 void PNGAPI
  35 my_png_read_stream(png_structp png_ptr, png_bytep data, png_size_t length)
  36 {
  37     png_uint_32 check;
  38 
  39     SplashStream * stream = (SplashStream*)png_get_io_ptr(png_ptr);
  40     check = stream->read(stream, data, length);
  41     if (check != length)
  42         png_error(png_ptr, "Read Error");
  43 }
  44 
  45 int
  46 SplashDecodePng(Splash * splash, png_rw_ptr read_func, void *io_ptr)
  47 {
  48     int stride;
  49     ImageFormat srcFormat;
  50     png_uint_32 i, rowbytes;





  51     png_bytepp row_pointers = NULL;
  52     png_bytep image_data = NULL;
  53     int success = 0;




  54     double gamma;
  55 
  56     png_structp png_ptr = NULL;
  57     png_infop info_ptr = NULL;
  58 
  59     png_uint_32 width, height;
  60     int bit_depth, color_type;
  61 
  62     ImageRect srcRect, dstRect;
  63 
  64     png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  65     if (!png_ptr) {
  66         goto done;
  67     }
  68 
  69     info_ptr = png_create_info_struct(png_ptr);
  70     if (!info_ptr) {
  71         goto done;
  72     }
  73 


 156         goto done;
 157     }
 158     splash->frames[0].delay = 0;
 159 
 160     /* FIXME: sort out the real format */
 161     initFormat(&srcFormat, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
 162     srcFormat.byteOrder = BYTE_ORDER_MSBFIRST;
 163 
 164     initRect(&srcRect, 0, 0, width, height, 1, rowbytes,
 165         image_data, &srcFormat);
 166     initRect(&dstRect, 0, 0, width, height, 1, stride,
 167         splash->frames[0].bitmapBits, &splash->imageFormat);
 168     convertRect(&srcRect, &dstRect, CVT_COPY);
 169 
 170     SplashInitFrameShape(splash, 0);
 171 
 172     png_read_end(png_ptr, NULL);
 173     success = 1;
 174 
 175   done:

 176     free(row_pointers);



 177     free(image_data);


 178     png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 179     return success;
 180 }
 181 
 182 int
 183 SplashDecodePngStream(Splash * splash, SplashStream * stream)
 184 {
 185     unsigned char sig[SIG_BYTES];
 186     int success = 0;
 187 
 188     stream->read(stream, sig, SIG_BYTES);
 189     if (png_sig_cmp(sig, 0, SIG_BYTES)) {
 190         goto done;
 191     }
 192     success = SplashDecodePng(splash, my_png_read_stream, stream);
 193 
 194   done:
 195     return success;
 196 }


  31 
  32 #define SIG_BYTES 8
  33 
  34 void PNGAPI
  35 my_png_read_stream(png_structp png_ptr, png_bytep data, png_size_t length)
  36 {
  37     png_uint_32 check;
  38 
  39     SplashStream * stream = (SplashStream*)png_get_io_ptr(png_ptr);
  40     check = stream->read(stream, data, length);
  41     if (check != length)
  42         png_error(png_ptr, "Read Error");
  43 }
  44 
  45 int
  46 SplashDecodePng(Splash * splash, png_rw_ptr read_func, void *io_ptr)
  47 {
  48     int stride;
  49     ImageFormat srcFormat;
  50     png_uint_32 i, rowbytes;
  51 
  52 #ifdef __GNUC__
  53 #pragma GCC diagnostic push
  54 #pragma GCC diagnostic ignored "-Wclobbered"
  55 #endif
  56     png_bytepp row_pointers = NULL;
  57     png_bytep image_data = NULL;
  58     int success = 0;
  59 #ifdef __GNUC__
  60 #pragma GCC diagnostic pop
  61 #endif
  62 
  63     double gamma;
  64 
  65     png_structp png_ptr = NULL;
  66     png_infop info_ptr = NULL;
  67 
  68     png_uint_32 width, height;
  69     int bit_depth, color_type;
  70 
  71     ImageRect srcRect, dstRect;
  72 
  73     png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  74     if (!png_ptr) {
  75         goto done;
  76     }
  77 
  78     info_ptr = png_create_info_struct(png_ptr);
  79     if (!info_ptr) {
  80         goto done;
  81     }
  82 


 165         goto done;
 166     }
 167     splash->frames[0].delay = 0;
 168 
 169     /* FIXME: sort out the real format */
 170     initFormat(&srcFormat, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
 171     srcFormat.byteOrder = BYTE_ORDER_MSBFIRST;
 172 
 173     initRect(&srcRect, 0, 0, width, height, 1, rowbytes,
 174         image_data, &srcFormat);
 175     initRect(&dstRect, 0, 0, width, height, 1, stride,
 176         splash->frames[0].bitmapBits, &splash->imageFormat);
 177     convertRect(&srcRect, &dstRect, CVT_COPY);
 178 
 179     SplashInitFrameShape(splash, 0);
 180 
 181     png_read_end(png_ptr, NULL);
 182     success = 1;
 183 
 184   done:
 185     if (row_pointers != NULL) {
 186       free(row_pointers);
 187       row_pointers = NULL;
 188     }
 189     if (image_data != NULL) {
 190       free(image_data);
 191       image_data = NULL;
 192     }
 193     png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 194     return success;
 195 }
 196 
 197 int
 198 SplashDecodePngStream(Splash * splash, SplashStream * stream)
 199 {
 200     unsigned char sig[SIG_BYTES];
 201     int success = 0;
 202 
 203     stream->read(stream, sig, SIG_BYTES);
 204     if (png_sig_cmp(sig, 0, SIG_BYTES)) {
 205         goto done;
 206     }
 207     success = SplashDecodePng(splash, my_png_read_stream, stream);
 208 
 209   done:
 210     return success;
 211 }
< prev index next >