[test] Fix-up rgb byte packing

Another embarrassing, but thankfully, trivial bug.
This commit is contained in:
Chris Wilson 2008-11-07 18:35:39 +00:00
parent 2554d17598
commit cd2e18ddc6
2 changed files with 11 additions and 5 deletions

View file

@ -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;

View file

@ -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)