Skip to content

Commit 390d0ad

Browse files
committed
[picload]
* cherry pick -> OpenViX/enigma2@b62523a
1 parent bdc2a42 commit 390d0ad

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/gdi/picload.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,14 @@ static void png_load(Cfilepara* filepara, uint32_t background, bool forceRGB = f
406406
filepara->ox = width;
407407
filepara->oy = height;
408408

409-
bool forceRGBA = false;
410-
411-
// This is a hack to support 8bit pngs with transparency since the detection is not really correct for some
412-
// reason....
409+
// When we have indexed (8bit) PNG convert it to standard 32bit png so to preserve transparency and to allow proper alphablending
413410
if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth == 8) {
414-
forceRGBA = true;
415411
color_type = PNG_COLOR_TYPE_RGBA;
412+
png_set_expand(png_ptr);
413+
png_set_palette_to_rgb(png_ptr);
414+
png_set_tRNS_to_alpha(png_ptr);
415+
bit_depth = 32;
416+
eTrace("[ePicLoad] Interlaced PNG 8bit -> 32bit");
416417
}
417418

418419
if (color_type == PNG_COLOR_TYPE_RGBA || color_type == PNG_COLOR_TYPE_GA) {
@@ -428,7 +429,7 @@ static void png_load(Cfilepara* filepara, uint32_t background, bool forceRGB = f
428429
filepara->transparent = (trans_alpha != NULL);
429430
}
430431

431-
if ((bit_depth <= 8) && (color_type == PNG_COLOR_TYPE_GRAY || color_type & PNG_COLOR_MASK_PALETTE || forceRGBA)) {
432+
if ((bit_depth <= 8) && (color_type == PNG_COLOR_TYPE_GRAY || color_type & PNG_COLOR_MASK_PALETTE)) {
432433
if (bit_depth < 8)
433434
png_set_packing(png_ptr);
434435

@@ -1693,6 +1694,7 @@ int ePicLoad::getData(ePtr<gPixmap>& result) {
16931694
int r = 0;
16941695
int g = 0;
16951696
int b = 0;
1697+
int a = 0;
16961698
int sq = 0;
16971699
irow = irowy + ixfac * (int)xind;
16981700
// average over all pixels in x by y block
@@ -1701,19 +1703,22 @@ int ePicLoad::getData(ePtr<gPixmap>& result) {
17011703
r += irow[0];
17021704
g += irow[1];
17031705
b += irow[2];
1706+
a += irow[3];
17041707
sq++;
17051708
irow += ixfac;
17061709
}
17071710
irow -= (xr + 1) * ixfac; // go back to starting point of this subrow
17081711
irow += iyfac;
17091712
}
1713+
if (sq == 0)
1714+
sq = 1;
17101715
srow[2] = r / sq;
17111716
srow[1] = g / sq;
17121717
srow[0] = b / sq;
17131718
if (m_filepara->bits < 32) {
17141719
srow[3] = 0xFF; // alpha opaque
17151720
} else {
1716-
srow[3] = irow[3]; // alpha
1721+
srow[3] = a / sq; // alpha
17171722
}
17181723
srow += 4;
17191724
xind += xscale;

0 commit comments

Comments
 (0)