Commit 8c174228 authored by ROOL's avatar ROOL 🤖
Browse files

Fix missing column bug

Detail:
  In 1/2/4bpp modes the loop could potentially read off the end of the input buffer
  (causing an abort if the next page isn't mapped in), or cause the rightmost column to be
  lost.
  Refactor the loop to count in destination bits to avoid both problems.
Admin:
  Submission for PNG bounty.

Version 0.07. Tagged as 'CompressPNG-0_07'
parent 2be571c3
/* (0.06)
/* (0.07)
*
* This file is automatically maintained by srccommit, do not edit manually.
*
*/
#define Module_MajorVersion_CMHG 0.06
#define Module_MajorVersion_CMHG 0.07
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 17 Mar 2021
#define Module_Date_CMHG 10 May 2021
#define Module_MajorVersion "0.06"
#define Module_Version 6
#define Module_MajorVersion "0.07"
#define Module_Version 7
#define Module_MinorVersion ""
#define Module_Date "17 Mar 2021"
#define Module_Date "10 May 2021"
#define Module_ApplicationDate "17-Mar-21"
#define Module_ApplicationDate "10-May-21"
#define Module_ComponentName "CompressPNG"
#define Module_FullVersion "0.06"
#define Module_HelpVersion "0.06 (17 Mar 2021)"
#define Module_LibraryVersionInfo "0:6"
#define Module_FullVersion "0.07"
#define Module_HelpVersion "0.07 (10 May 2021)"
#define Module_LibraryVersionInfo "0:7"
......@@ -431,26 +431,19 @@ _kernel_oserror *compresspng_writeline(_kernel_swi_regs *r)
}
if (opt->palette_bits < 8)
{ /* compact the stream by combining pixels into bytes */
{ /* compact the stream by combining pixels into bytes in situ */
int src, dest;
for (src = 0, dest = 0; src < opt->width; src += 8 / opt->palette_bits, dest += 1)
{ switch (opt->palette_bits)
{ case 1:
*(dest + rowbuffer) = (*(src + rowbuffer + 0) << 7) | (*(src + rowbuffer + 1) << 6) |
(*(src + rowbuffer + 2) << 5) | (*(src + rowbuffer + 3) << 4) |
(*(src + rowbuffer + 4) << 3) | (*(src + rowbuffer + 5) << 2) |
(*(src + rowbuffer + 6) << 1) | (*(src + rowbuffer + 7) << 0);
break;
case 2:
*(dest + rowbuffer) = (*(src + rowbuffer + 0) << 6) | (*(src + rowbuffer + 1) << 4) |
(*(src + rowbuffer + 2) << 2) | (*(src + rowbuffer + 3) << 0);
break;
case 4:
*(dest + rowbuffer) = (*(src + rowbuffer + 0) << 4) | (*(src + rowbuffer + 1) << 0);
break;
}
int pixmask = (1 << opt->palette_bits) - 1;
int sourcepixel;
for (src = 0, dest = 0; src < opt->width; src++, dest += opt->palette_bits)
{ /* obtain pixel and shunt up into place */
sourcepixel = *(rowbuffer + src) & pixmask;
sourcepixel = sourcepixel << ((8 - opt->palette_bits) - (dest & 7));
if ((dest % 8) == 0)
*(rowbuffer + (dest / 8)) = sourcepixel; /* starting a new byte */
else
*(rowbuffer + (dest / 8)) |= sourcepixel; /* add to existing byte */
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment