]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - plugins/imagepng/plugin.cpp
Fix/add grayscale-to-RGB in PNG loader
[xonotic/netradiant.git] / plugins / imagepng / plugin.cpp
index 426c4f063e3bbb013e3a155794f89de0bb5ae98b..05aea74b47d08fd95fc838d8ba6f70e08345714f 100644 (file)
@@ -41,7 +41,7 @@ void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
 void user_error_fn(png_structp png_ptr, png_const_charp error_msg)
 {
   globalErrorStream() << "libpng error: " << error_msg << "\n";
 void user_error_fn(png_structp png_ptr, png_const_charp error_msg)
 {
   globalErrorStream() << "libpng error: " << error_msg << "\n";
-  longjmp(png_ptr->jmpbuf, 0);
+  longjmp(png_jmpbuf(png_ptr), 0);
 }
 
 void user_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
 }
 
 void user_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
@@ -89,7 +89,7 @@ Image* LoadPNGBuff (unsigned char* fbuffer)
   // configure the read function
   png_set_read_fn(png_ptr, (voidp)&p_fbuffer, (png_rw_ptr)&user_read_data);
 
   // configure the read function
   png_set_read_fn(png_ptr, (voidp)&p_fbuffer, (png_rw_ptr)&user_read_data);
 
-  if (setjmp(png_ptr->jmpbuf)) {
+  if (setjmp(png_jmpbuf(png_ptr))) {
     png_destroy_read_struct(&png_ptr, &info_ptr,
       &end_info);
     return 0;
     png_destroy_read_struct(&png_ptr, &info_ptr,
       &end_info);
     return 0;
@@ -104,11 +104,14 @@ Image* LoadPNGBuff (unsigned char* fbuffer)
   //   The following code transforms grayscale images of less than 8 to 8 bits, 
   //   changes paletted images to RGB, and adds a full alpha channel if there is 
   //   transparency information in a tRNS chunk.
   //   The following code transforms grayscale images of less than 8 to 8 bits, 
   //   changes paletted images to RGB, and adds a full alpha channel if there is 
   //   transparency information in a tRNS chunk.
-  if (color_type == PNG_COLOR_TYPE_PALETTE)
-   png_set_palette_to_rgb(png_ptr);
+
+  if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
+    png_set_gray_to_rgb(png_ptr);
+  else if (color_type == PNG_COLOR_TYPE_PALETTE)
+    png_set_palette_to_rgb(png_ptr);
 
   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
 
   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
-    png_set_gray_1_2_4_to_8(png_ptr);
+    png_set_expand_gray_1_2_4_to_8(png_ptr);
 
   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
     png_set_tRNS_to_alpha(png_ptr);
 
   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
     png_set_tRNS_to_alpha(png_ptr);
@@ -153,7 +156,7 @@ Image* LoadPNGBuff (unsigned char* fbuffer)
   png_read_end(png_ptr, info_ptr);
 
   /* free up the memory structure */
   png_read_end(png_ptr, info_ptr);
 
   /* free up the memory structure */
-  png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
+  png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
   free(row_pointers);
 
 
   free(row_pointers);