source: trunk/dports/editors/xemacs/files/51ced9b8fb63e4be59ea611b58128c400e3df987.diff @ 97398

Last change on this file since 97398 was 97398, checked in by dports@…, 7 years ago

xemacs: add upstream patches to support libpng 1.5

File size: 2.4 KB
  • src/glyphs-eimage.c

    # HG changeset patch
    # User Vin Shelton <acs@xemacs.org>
    # Date 1323317837 18000
    # Node ID 51ced9b8fb63e4be59ea611b58128c400e3df987
    # Parent  032a91928d47b36ae3dd98885767d9e0202892f7
    Clean up PNG handling.  Fix crash in issue570.
    
    diff -r 032a91928d47b36ae3dd98885767d9e0202892f7 -r 51ced9b8fb63e4be59ea611b58128c400e3df987 src/glyphs-eimage.c
    a b  
    935935  png_read_info (png_ptr, info_ptr);
    936936
    937937  {
    938     int y;
     938    int y, padding;
    939939    unsigned char **row_pointers;
    940940    height = info_ptr->height;
    941941    width = info_ptr->width;
    942942
    943     /* Wow, allocate all the memory.  Truly, exciting. */
    944     unwind.eimage = xnew_array_and_zero (unsigned char, width * height * 3);
     943    /* Wow, allocate all the memory.  Truly, exciting.
     944       Well, yes, there's excitement to be had.  It turns out that libpng
     945       strips in place, so the last row overruns the buffer if depth is 16
     946       or there's an alpha channel.  This is a crash on Linux.  So we need
     947       to add padding.
     948       The worst case is reducing 8 bytes (16-bit RGBA) to 3 (8-bit RGB). */
     949
     950    padding = 5 * width;
     951    unwind.eimage = xnew_array_and_zero (unsigned char,
     952                                         width * height * 3 + padding);
     953
    945954    /* libpng expects that the image buffer passed in contains a
    946955       picture to draw on top of if the png has any transparencies.
    947956       This could be a good place to pass that in... */
     
    9961005    if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY ||
    9971006        info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
    9981007      png_set_gray_to_rgb (png_ptr);
    999     /* we can't handle alpha values */
    1000     if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
    1001       png_set_strip_alpha (png_ptr);
    10021008    /* tell libpng to strip 16 bit depth files down to 8 bits */
    10031009    if (info_ptr->bit_depth == 16)
    10041010      png_set_strip_16 (png_ptr);
     
    10111017          png_set_packing (png_ptr);
    10121018      }
    10131019
     1020    /* we can't handle alpha values
     1021       png_read_update_info ensures the alpha flag is set when one of
     1022       the transforms above causes an alpha channel to be generated */
     1023    png_read_update_info (png_ptr, info_ptr);
     1024    if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
     1025      png_set_strip_alpha (png_ptr);
     1026
    10141027    png_read_image (png_ptr, row_pointers);
    10151028    png_read_end (png_ptr, info_ptr);
    10161029
Note: See TracBrowser for help on using the repository browser.