Fix regression in display of PPM images
Problem reported by Roland Winkler (Bug#28824#35). Based on a patch proposed by Andy Moreton (Bug#28824#38). * src/image.c (pbm_scan_index): New function. (pbm_load): Use it to decode raw data correctly when its top bit is set.
This commit is contained in:
parent
1ca9ae7069
commit
3205b12a78
1 changed files with 25 additions and 15 deletions
40
src/image.c
40
src/image.c
|
@ -5277,6 +5277,25 @@ pbm_scan_number (char **s, char *end)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Scan an index from *S and return it. It is a one-byte unsigned
|
||||||
|
index if !TWO_BYTE, and a two-byte big-endian unsigned index if
|
||||||
|
TWO_BYTE. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
pbm_scan_index (char **s, bool two_byte)
|
||||||
|
{
|
||||||
|
char *p = *s;
|
||||||
|
unsigned char c0 = *p++;
|
||||||
|
int n = c0;
|
||||||
|
if (two_byte)
|
||||||
|
{
|
||||||
|
unsigned char c1 = *p++;
|
||||||
|
n = (n << 8) + c1;
|
||||||
|
}
|
||||||
|
*s = p;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Load PBM image IMG for use on frame F. */
|
/* Load PBM image IMG for use on frame F. */
|
||||||
|
|
||||||
|
@ -5499,7 +5518,8 @@ pbm_load (struct frame *f, struct image *img)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int expected_size = height * width;
|
int expected_size = height * width;
|
||||||
if (max_color_idx > 255)
|
bool two_byte = 255 < max_color_idx;
|
||||||
|
if (two_byte)
|
||||||
expected_size *= 2;
|
expected_size *= 2;
|
||||||
if (type == PBM_COLOR)
|
if (type == PBM_COLOR)
|
||||||
expected_size *= 3;
|
expected_size *= 3;
|
||||||
|
@ -5522,24 +5542,14 @@ pbm_load (struct frame *f, struct image *img)
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
|
|
||||||
if (type == PBM_GRAY && raw_p)
|
if (type == PBM_GRAY && raw_p)
|
||||||
{
|
r = g = b = pbm_scan_index (&p, two_byte);
|
||||||
r = g = b = *p++;
|
|
||||||
if (max_color_idx > 255)
|
|
||||||
r = g = b = r * 256 + *p++;
|
|
||||||
}
|
|
||||||
else if (type == PBM_GRAY)
|
else if (type == PBM_GRAY)
|
||||||
r = g = b = pbm_scan_number (&p, end);
|
r = g = b = pbm_scan_number (&p, end);
|
||||||
else if (raw_p)
|
else if (raw_p)
|
||||||
{
|
{
|
||||||
r = *p++;
|
r = pbm_scan_index (&p, two_byte);
|
||||||
if (max_color_idx > 255)
|
g = pbm_scan_index (&p, two_byte);
|
||||||
r = r * 256 + *p++;
|
b = pbm_scan_index (&p, two_byte);
|
||||||
g = *p++;
|
|
||||||
if (max_color_idx > 255)
|
|
||||||
g = g * 256 + *p++;
|
|
||||||
b = *p++;
|
|
||||||
if (max_color_idx > 255)
|
|
||||||
b = b * 256 + *p++;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue