style cleanup: png
authorCampbell Barton <ideasman42@gmail.com>
Wed, 9 May 2012 15:21:45 +0000 (15:21 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 9 May 2012 15:21:45 +0000 (15:21 +0000)
source/blender/imbuf/intern/png.c

index d39ab6f036e87d060d1777c3856a1c9d19cdedca..35a44635727e866f311e1b7a433166847b7fa344 100644 (file)
@@ -28,7 +28,7 @@
 /** \file blender/imbuf/intern/png.c
  *  \ingroup imbuf
  *
- * \todo Save floats as 16 bits per pixel, currently readonly.
+ * \todo Save floats as 16 bits per channel, currently readonly.
  */
 
 #include "png.h"
@@ -84,7 +84,7 @@ static void WriteData(png_structp png_ptr, png_bytep data, png_size_t length)
 
 static void ReadData(png_structp png_ptr, png_bytep data, png_size_t length)
 {
-       PNGReadStruct *rs= (PNGReadStruct *) png_get_io_ptr(png_ptr);
+       PNGReadStruct *rs = (PNGReadStruct *) png_get_io_ptr(png_ptr);
 
        if (rs) {
                if (length <= rs->size - rs->seek) {
@@ -111,12 +111,12 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
 
        /* use the jpeg quality setting for compression */
        int compression;
-       compression= (int)(((float)(ibuf->ftype & 0xff) / 11.1111f));
-       compression= compression < 0 ? 0 : (compression > 9 ? 9 : compression);
+       compression = (int)(((float)(ibuf->ftype & 0xff) / 11.1111f));
+       compression = compression < 0 ? 0 : (compression > 9 ? 9 : compression);
 
        /* for prints */
        if (flags & IB_mem)
-               name= "<memory>";
+               name = "<memory>";
 
        bytesperpixel = (ibuf->planes + 7) >> 3;
        if ((bytesperpixel > 4) || (bytesperpixel == 2)) {
@@ -125,7 +125,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
        }
 
        png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
-               NULL, NULL, NULL);
+                                         NULL, NULL, NULL);
        if (png_ptr == NULL) {
                printf("imb_savepng: Cannot png_create_write_struct for file: '%s'\n", name);
                return 0;
@@ -157,32 +157,32 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
        to = pixels;
 
        switch (bytesperpixel) {
-       case 4:
-               color_type = PNG_COLOR_TYPE_RGBA;
-               for (i = ibuf->x * ibuf->y; i > 0; i--) {
-                       to[0] = from[0];
-                       to[1] = from[1];
-                       to[2] = from[2];
-                       to[3] = from[3];
-                       to += 4; from += 4;
-               }
-               break;
-       case 3:
-               color_type = PNG_COLOR_TYPE_RGB;
-               for (i = ibuf->x * ibuf->y; i > 0; i--) {
-                       to[0] = from[0];
-                       to[1] = from[1];
-                       to[2] = from[2];
-                       to += 3; from += 4;
-               }
-               break;
-       case 1:
-               color_type = PNG_COLOR_TYPE_GRAY;
-               for (i = ibuf->x * ibuf->y; i > 0; i--) {
-                       to[0] = from[0];
-                       to++; from += 4;
-               }
-               break;
+               case 4:
+                       color_type = PNG_COLOR_TYPE_RGBA;
+                       for (i = ibuf->x * ibuf->y; i > 0; i--) {
+                               to[0] = from[0];
+                               to[1] = from[1];
+                               to[2] = from[2];
+                               to[3] = from[3];
+                               to += 4; from += 4;
+                       }
+                       break;
+               case 3:
+                       color_type = PNG_COLOR_TYPE_RGB;
+                       for (i = ibuf->x * ibuf->y; i > 0; i--) {
+                               to[0] = from[0];
+                               to[1] = from[1];
+                               to[2] = from[2];
+                               to += 3; from += 4;
+                       }
+                       break;
+               case 1:
+                       color_type = PNG_COLOR_TYPE_GRAY;
+                       for (i = ibuf->x * ibuf->y; i > 0; i--) {
+                               to[0] = from[0];
+                               to++; from += 4;
+                       }
+                       break;
        }
 
        if (flags & IB_mem) {
@@ -208,11 +208,11 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
 
 #if 0
        png_set_filter(png_ptr, 0,
-                      PNG_FILTER_NONE  | PNG_FILTER_VALUE_NONE |
-                      PNG_FILTER_SUB   | PNG_FILTER_VALUE_SUB  |
-                      PNG_FILTER_UP    | PNG_FILTER_VALUE_UP   |
-                      PNG_FILTER_AVG   | PNG_FILTER_VALUE_AVG  |
-                      PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|
+                      PNG_FILTER_NONE  | PNG_FILTER_VALUE_NONE  |
+                      PNG_FILTER_SUB   | PNG_FILTER_VALUE_SUB   |
+                      PNG_FILTER_UP    | PNG_FILTER_VALUE_UP    |
+                      PNG_FILTER_AVG   | PNG_FILTER_VALUE_AVG   |
+                      PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH |
                       PNG_ALL_FILTERS);
 #endif
 
@@ -231,16 +231,16 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
 
        /* image text info */
        if (ibuf->metadata) {
-               png_text*  metadata;
-               ImMetaDataiptr;
-               int  num_text = 0;
+               png_text *metadata;
+               ImMetaData *iptr;
+               int num_text = 0;
                iptr = ibuf->metadata;
                while (iptr) {
                        num_text++;
                        iptr = iptr->next;
                }
                
-               metadata = MEM_callocN(num_text*sizeof(png_text), "png_metadata");
+               metadata = MEM_callocN(num_text * sizeof(png_text), "png_metadata");
                iptr = ibuf->metadata;
                num_text = 0;
                while (iptr) {
@@ -278,8 +278,8 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
 
        // set the individual row-pointers to point at the correct offsets
        for (i = 0; i < ibuf->y; i++) {
-               row_pointers[ibuf->y-1-i] = (png_bytep)
-                       ((unsigned char *)pixels + (i * ibuf->x) * bytesperpixel * sizeof(unsigned char));
+               row_pointers[ibuf->y - 1 - i] = (png_bytep)
+                                               ((unsigned char *)pixels + (i * ibuf->x) * bytesperpixel * sizeof(unsigned char));
        }
 
        // write out the entire image data in one call
@@ -301,8 +301,7 @@ int imb_savepng(struct ImBuf *ibuf, const char *name, int flags)
        return(1);
 }
 
-struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
-{
+struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags){
        struct ImBuf *ibuf = NULL;
        png_structp png_ptr;
        png_infop info_ptr;
@@ -322,7 +321,7 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
        if (imb_is_a_png(mem) == 0) return(NULL);
 
        png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
-               NULL, NULL, NULL);
+                                        NULL, NULL, NULL);
        if (png_ptr == NULL) {
                printf("Cannot png_create_read_struct\n");
                return NULL;
@@ -331,7 +330,7 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
        info_ptr = png_create_info_struct(png_ptr);
        if (info_ptr == NULL) {
                png_destroy_read_struct(&png_ptr, (png_infopp)NULL, 
-                       (png_infopp)NULL);
+                                       (png_infopp)NULL);
                printf("Cannot png_create_info_struct\n");
                return NULL;
        }
@@ -355,33 +354,33 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
 
        png_read_info(png_ptr, info_ptr);
        png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, 
-               &color_type, NULL, NULL, NULL);
+                    &color_type, NULL, NULL, NULL);
 
        bytesperpixel = png_get_channels(png_ptr, info_ptr);
 
        switch (color_type) {
-       case PNG_COLOR_TYPE_RGB:
-       case PNG_COLOR_TYPE_RGB_ALPHA:
-               break;
-       case PNG_COLOR_TYPE_PALETTE:
-               png_set_palette_to_rgb(png_ptr);
-               if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
-                       bytesperpixel = 4;
-               }
-               else {
-                       bytesperpixel = 3;
-               }
-               break;
-       case PNG_COLOR_TYPE_GRAY:
-       case PNG_COLOR_TYPE_GRAY_ALPHA:
-               if (bit_depth < 8) {
-                       png_set_expand(png_ptr);
-                       bit_depth = 8;
-               }
-               break;
-       default:
-               printf("PNG format not supported\n");
-               longjmp(png_jmpbuf(png_ptr), 1);
+               case PNG_COLOR_TYPE_RGB:
+               case PNG_COLOR_TYPE_RGB_ALPHA:
+                       break;
+               case PNG_COLOR_TYPE_PALETTE:
+                       png_set_palette_to_rgb(png_ptr);
+                       if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+                               bytesperpixel = 4;
+                       }
+                       else {
+                               bytesperpixel = 3;
+                       }
+                       break;
+               case PNG_COLOR_TYPE_GRAY:
+               case PNG_COLOR_TYPE_GRAY_ALPHA:
+                       if (bit_depth < 8) {
+                               png_set_expand(png_ptr);
+                               bit_depth = 8;
+                       }
+                       break;
+               default:
+                       printf("PNG format not supported\n");
+                       longjmp(png_jmpbuf(png_ptr), 1);
        }
        
        ibuf = IMB_allocImBuf(width, height, 8 * bytesperpixel, 0);
@@ -393,15 +392,15 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
                else
                        ibuf->profile = IB_PROFILE_SRGB;
 
-               if (png_get_valid (png_ptr, info_ptr, PNG_INFO_pHYs)) {
+               if (png_get_valid(png_ptr, info_ptr, PNG_INFO_pHYs)) {
                        int unit_type;
                        png_uint_32 xres, yres;
 
                        if (png_get_pHYs(png_ptr, info_ptr, &xres, &yres, &unit_type))
-                       if (unit_type == PNG_RESOLUTION_METER) {
-                               ibuf->ppm[0]= xres;
-                               ibuf->ppm[1]= yres;
-                       }
+                               if (unit_type == PNG_RESOLUTION_METER) {
+                                       ibuf->ppm[0] = xres;
+                                       ibuf->ppm[1] = yres;
+                               }
                }
        }
        else {
@@ -429,7 +428,7 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
                        // set the individual row-pointers to point at the correct offsets
                        for (i = 0; i < ibuf->y; i++) {
                                row_pointers[ibuf->y - 1 - i] = (png_bytep)
-                                       ((png_uint_16 *)pixels16 + (i * ibuf->x) * bytesperpixel);
+                                                               ((png_uint_16 *)pixels16 + (i * ibuf->x) * bytesperpixel);
                        }
 
                        png_read_image(png_ptr, row_pointers);
@@ -496,8 +495,8 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
 
                        // set the individual row-pointers to point at the correct offsets
                        for (i = 0; i < ibuf->y; i++) {
-                               row_pointers[ibuf->y-1-i] = (png_bytep)
-                                       ((unsigned char *)pixels + (i * ibuf->x) * bytesperpixel * sizeof(unsigned char));
+                               row_pointers[ibuf->y - 1 - i] = (png_bytep)
+                                                               ((unsigned char *)pixels + (i * ibuf->x) * bytesperpixel * sizeof(unsigned char));
                        }
 
                        png_read_image(png_ptr, row_pointers);
@@ -544,7 +543,7 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
                }
 
                if (flags & IB_metadata) {
-                       png_texttext_chunks;
+                       png_text *text_chunks;
                        int count = png_get_text(png_ptr, info_ptr, &text_chunks, NULL);
                        for (i = 0; i < count; i++) {
                                IMB_metadata_add_field(ibuf, text_chunks[i].key, text_chunks[i].text);
@@ -556,9 +555,9 @@ struct ImBuf *imb_loadpng(unsigned char *mem, size_t size, int flags)
        }
 
        // clean up
-       if(pixels)
+       if (pixels)
                MEM_freeN(pixels);
-       if(pixels16)
+       if (pixels16)
                MEM_freeN(pixels16);
        MEM_freeN(row_pointers);
        png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);