Skip to content

Commit

Permalink
Merge branch 'fix-17991'
Browse files Browse the repository at this point in the history
* fix-17991:
  Explain the purpose of introducing dt_imageio_png_read_header and dt_imageio_png_read_image
  We have restricted the call conditions of png_set_strip_alpha too much
  • Loading branch information
TurboGit committed Dec 23, 2024
2 parents 2ca30ac + eb91d4c commit 8e95981
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/imageio/imageio_png.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
#include "imageio_common.h"
#include "imageio_png.h"


// Reading of PNG files also takes place in the LUT 3D module in order to obtain
// LUTs encoded in this format. To minimize code duplication, we put the code
// common to both uses (reading the header and reading the image itself) into
// two functions, dt_imageio_png_read_header and dt_imageio_png_read_image.

gboolean dt_imageio_png_read_header(const char *filename, dt_imageio_png_t *png)
{
png->f = g_fopen(filename, "rb");
Expand Down Expand Up @@ -102,9 +108,10 @@ gboolean dt_imageio_png_read_header(const char *filename, dt_imageio_png_t *png)
png->bit_depth = 8;
}

// strip alpha channel
if(png->color_type & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha(png->png_ptr);
// To ensure that 4 channels will not be decoded instead of expected 3 we
// need to call png_set_strip_alpha. It wouldn't hurt if we always call
// this function. It just doesn't do anything when it's not needed.
png_set_strip_alpha(png->png_ptr);

// grayscale => rgb
if(png->color_type == PNG_COLOR_TYPE_GRAY || png->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
Expand Down

0 comments on commit 8e95981

Please sign in to comment.