mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-22 15:00:31 +01:00
[test] Fix-up rgb byte packing
Another embarrassing, but thankfully, trivial bug.
This commit is contained in:
parent
2554d17598
commit
cd2e18ddc6
2 changed files with 11 additions and 5 deletions
|
|
@ -990,6 +990,8 @@ cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file)
|
|||
for (x = 0; x < width; x++) {
|
||||
if (! freadn (buf, 3, file))
|
||||
goto FAIL;
|
||||
*(uint32_t *) buf =
|
||||
(buf[0] << 16) | (buf[1] << 8) | (buf[2] << 0);
|
||||
buf += 4;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -184,26 +184,30 @@ write_ppm (cairo_surface_t *surface, int fd)
|
|||
|
||||
len = sprintf (buf, "%s %d %d 255\n", format_str, width, height);
|
||||
for (j = 0; j < height; j++) {
|
||||
const unsigned char *row = data + stride * j;
|
||||
const unsigned int *row = (unsigned int *) (data + stride * j);
|
||||
|
||||
switch ((int) format) {
|
||||
case CAIRO_FORMAT_ARGB32:
|
||||
len = _write (fd,
|
||||
buf, sizeof (buf), len,
|
||||
row, 4 * width);
|
||||
(unsigned char *) row, 4 * width);
|
||||
break;
|
||||
case CAIRO_FORMAT_RGB24:
|
||||
for (i = 0; i < width; i++) {
|
||||
unsigned char rgb[3];
|
||||
unsigned int p = *row++;
|
||||
rgb[0] = (p & 0xff0000) >> 16;
|
||||
rgb[1] = (p & 0x00ff00) >> 8;
|
||||
rgb[2] = (p & 0x0000ff) >> 0;
|
||||
len = _write (fd,
|
||||
buf, sizeof (buf), len,
|
||||
row, 3);
|
||||
row += 4;
|
||||
rgb, 3);
|
||||
}
|
||||
break;
|
||||
case CAIRO_FORMAT_A8:
|
||||
len = _write (fd,
|
||||
buf, sizeof (buf), len,
|
||||
row, width);
|
||||
(unsigned char *) row, width);
|
||||
break;
|
||||
}
|
||||
if (len < 0)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue