Ticket #35996: patch-libpng-1.5.diff

File patch-libpng-1.5.diff, 4.2 KB (added by mklein-de (Michael Klein), 12 years ago)
  • src/util/png.c

    # stolen from http://code.google.com/p/gnuxaos/issues/detail?id=55
    old new  
    33#include <aconfig.h>
    44#ifdef USE_PNG
    55#include <png.h>
     6#include <zlib.h>
    67#endif
    78#include <stdlib.h>
    89#include <stdio.h>
     
    3132    png_structp png_ptr;
    3233    png_infop info_ptr;
    3334    png_color palette[256];
     35    png_color_8 sig_bit;
     36    int color_type;
     37    int bit_depth;
    3438    volatile unsigned short a = 255;
    3539    volatile unsigned char *b = (volatile unsigned char *) &a;
    3640#ifdef _undefined_
     
    5963        png_destroy_write_struct(&png_ptr, (png_infopp) NULL);
    6064        return "No memory to create png info structure";
    6165    }
    62     if (setjmp(png_ptr->jmpbuf)) {
     66    if (setjmp(png_jmpbuf(png_ptr))) {
    6367        png_destroy_write_struct(&png_ptr, &info_ptr);
    6468        fclose(file);
    6569        return strerror(errno);
     
    7882    png_set_compression_window_bits(png_ptr, 15);
    7983    png_set_compression_method(png_ptr, 8);
    8084
    81     info_ptr->width = image->width;
    82     info_ptr->height = image->height;
    83     /*info_ptr->gamma=1.0; */
    84     info_ptr->gamma = 0.5;
    85     info_ptr->valid |= PNG_INFO_gAMA | PNG_INFO_pHYs;
    86     info_ptr->x_pixels_per_unit = (png_uint_32) (100 / image->pixelwidth);
    87     info_ptr->y_pixels_per_unit = (png_uint_32) (100 / image->pixelheight);
     85    switch (image->palette->type)
     86    {
     87    case C256:
     88        color_type = PNG_COLOR_TYPE_PALETTE;
     89        bit_depth = image->bytesperpixel * 8;
     90        break;
     91    case SMALLITER:
     92    case LARGEITER:
     93    case GRAYSCALE:
     94        color_type = PNG_COLOR_TYPE_GRAY;
     95        bit_depth = image->bytesperpixel * 8;
     96        break;
     97    case TRUECOLOR:
     98    case TRUECOLOR24:
     99    case TRUECOLOR16:
     100        color_type = PNG_COLOR_TYPE_RGB;
     101        bit_depth = 8;
     102        break;
     103    }
    88104
     105    png_set_IHDR (png_ptr, info_ptr, image->width, image->height, bit_depth,
     106                  color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
     107                  PNG_FILTER_TYPE_BASE);
    89108
    90109    switch (image->palette->type) {
    91110    case C256:
    92111        {
    93112            int i;
    94             info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
    95             info_ptr->bit_depth = image->bytesperpixel * 8;
    96             info_ptr->palette = palette;
    97             info_ptr->valid |= PNG_INFO_PLTE;
     113            png_color png_palette[257];
     114            int png_num_palette;
    98115            for (i = 0; i < image->palette->end; i++)
    99                 info_ptr->palette[i].red = image->palette->rgb[i][0],
    100                     info_ptr->palette[i].green = image->palette->rgb[i][1],
    101                     info_ptr->palette[i].blue = image->palette->rgb[i][2],
    102                     info_ptr->num_palette = image->palette->end;
     116                png_palette[i].red = image->palette->rgb[i][0],
     117                    png_palette[i].green = image->palette->rgb[i][1],
     118                    png_palette[i].blue = image->palette->rgb[i][2],
     119                    png_num_palette = image->palette->end;
     120            png_set_PLTE(png_ptr, info_ptr, png_palette, png_num_palette);
    103121        }
    104122        break;
    105     case SMALLITER:
    106     case LARGEITER:
    107     case GRAYSCALE:
    108         info_ptr->color_type = PNG_COLOR_TYPE_GRAY;
    109         info_ptr->bit_depth = image->bytesperpixel * 8;
    110         break;
    111123    case TRUECOLOR:
    112124    case TRUECOLOR24:
    113125    case TRUECOLOR16:
    114         info_ptr->color_type = PNG_COLOR_TYPE_RGB;
    115         info_ptr->bit_depth = 8;
    116         info_ptr->sig_bit.red = 8 - image->palette->info.truec.rprec;
    117         info_ptr->sig_bit.green = 8 - image->palette->info.truec.gprec;
    118         info_ptr->sig_bit.blue = 8 - image->palette->info.truec.bprec;
     126        sig_bit.red = 8 - image->palette->info.truec.rprec;
     127        sig_bit.green = 8 - image->palette->info.truec.gprec;
     128        sig_bit.blue = 8 - image->palette->info.truec.bprec;
     129        png_set_sBIT(png_ptr, info_ptr, &sig_bit);
    119130        break;
    120131    }
    121     info_ptr->interlace_type = 0;
     132
     133    png_write_info (png_ptr, info_ptr);
     134
    122135#ifdef _undefined_
    123136    png_set_text(png_ptr, info_ptr, comments,
    124137                 sizeof(comments) / sizeof(png_text));
    125138#endif
    126139
    127     png_write_info(png_ptr, info_ptr);
     140    png_set_gAMA(png_ptr, info_ptr, 0.5 /* 1.0 */);
     141    png_set_pHYs(png_ptr, info_ptr, (png_uint_32) (100 / image->pixelwidth),
     142                 (png_uint_32) (100 / image->pixelheight),
     143                 PNG_RESOLUTION_UNKNOWN);
     144
    128145    /*png_set_filler(png_ptr,0,PNG_FILLER_AFTER); */
    129146    png_set_packing(png_ptr);
    130147    if (image->palette->type & (TRUECOLOR | TRUECOLOR24 | TRUECOLOR16))
    131         png_set_shift(png_ptr, &(info_ptr->sig_bit));
     148        png_set_shift (png_ptr, &sig_bit);
    132149    if (*b == 255)
    133150        png_set_swap(png_ptr);
    134151    png_set_bgr(png_ptr);