From b95d2066a56f656df0a1be5fe32115a186d4e46a Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 11 Dec 2003 07:03:41 +0000 Subject: [PATCH] Fix to use shifts and masks for endianness-correct PS image generation. Rename bgr to rgb now that the byte order issues are clear. --- ChangeLog | 7 +++++++ src/cairo-ps-surface.c | 27 +++++++++++++-------------- src/cairo_ps_surface.c | 27 +++++++++++++-------------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef7782f83..c1e337a3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-12-11 Carl Worth + + * src/cairo_ps_surface.c (_cairo_ps_surface_copy_page): Fix to use + shifts and masks for endianness-correct PS image + generation. Rename bgr to rgb now that the byte order issues are + clear. + 2003-12-08 Carl Worth * src/cairo_path_bounds.c (_cairo_path_bounder_move_to): diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index c66b70987..c5313de79 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -286,19 +286,19 @@ _cairo_ps_surface_copy_page (void *abstract_surface) int i, x, y; cairo_surface_t *white_surface; - char *bgr, *compressed; - long bgr_size, compressed_size; + char *rgb, *compressed; + long rgb_size, compressed_size; cairo_color_t white; - bgr_size = 3 * width * height; - bgr = malloc (bgr_size); - if (bgr == NULL) { + rgb_size = 3 * width * height; + rgb = malloc (rgb_size); + if (rgb == NULL) { status = CAIRO_STATUS_NO_MEMORY; goto BAIL0; } - compressed_size = (int) (1.0 + 1.1 * bgr_size); + compressed_size = (int) (1.0 + 1.1 * rgb_size); compressed = malloc (compressed_size); if (compressed == NULL) { status = CAIRO_STATUS_NO_MEMORY; @@ -330,16 +330,15 @@ _cairo_ps_surface_copy_page (void *abstract_surface) i = 0; for (y = 0; y < height; y++) { - char *line = surface->image->data + y * surface->image->stride; - for (x = 0; x < width; x++) { - unsigned char *pixel = (unsigned char *) line + x * 4; - bgr[i++] = *(pixel+2); - bgr[i++] = *(pixel+1); - bgr[i++] = *(pixel); + IcBits *pixel = (IcBits *) (surface->image->data + y * surface->image->stride); + for (x = 0; x < width; x++, pixel++) { + rgb[i++] = (*pixel & 0x00ff0000) >> 16; + rgb[i++] = (*pixel & 0x0000ff00) >> 8; + rgb[i++] = (*pixel & 0x000000ff) >> 0; } } - compress (compressed, &compressed_size, bgr, bgr_size); + compress (compressed, &compressed_size, rgb, rgb_size); /* Page header */ fprintf (file, "%%%%Page: %d\n", ++surface->pages); @@ -375,7 +374,7 @@ _cairo_ps_surface_copy_page (void *abstract_surface) BAIL2: free (compressed); BAIL1: - free (bgr); + free (rgb); BAIL0: return status; } diff --git a/src/cairo_ps_surface.c b/src/cairo_ps_surface.c index c66b70987..c5313de79 100644 --- a/src/cairo_ps_surface.c +++ b/src/cairo_ps_surface.c @@ -286,19 +286,19 @@ _cairo_ps_surface_copy_page (void *abstract_surface) int i, x, y; cairo_surface_t *white_surface; - char *bgr, *compressed; - long bgr_size, compressed_size; + char *rgb, *compressed; + long rgb_size, compressed_size; cairo_color_t white; - bgr_size = 3 * width * height; - bgr = malloc (bgr_size); - if (bgr == NULL) { + rgb_size = 3 * width * height; + rgb = malloc (rgb_size); + if (rgb == NULL) { status = CAIRO_STATUS_NO_MEMORY; goto BAIL0; } - compressed_size = (int) (1.0 + 1.1 * bgr_size); + compressed_size = (int) (1.0 + 1.1 * rgb_size); compressed = malloc (compressed_size); if (compressed == NULL) { status = CAIRO_STATUS_NO_MEMORY; @@ -330,16 +330,15 @@ _cairo_ps_surface_copy_page (void *abstract_surface) i = 0; for (y = 0; y < height; y++) { - char *line = surface->image->data + y * surface->image->stride; - for (x = 0; x < width; x++) { - unsigned char *pixel = (unsigned char *) line + x * 4; - bgr[i++] = *(pixel+2); - bgr[i++] = *(pixel+1); - bgr[i++] = *(pixel); + IcBits *pixel = (IcBits *) (surface->image->data + y * surface->image->stride); + for (x = 0; x < width; x++, pixel++) { + rgb[i++] = (*pixel & 0x00ff0000) >> 16; + rgb[i++] = (*pixel & 0x0000ff00) >> 8; + rgb[i++] = (*pixel & 0x000000ff) >> 0; } } - compress (compressed, &compressed_size, bgr, bgr_size); + compress (compressed, &compressed_size, rgb, rgb_size); /* Page header */ fprintf (file, "%%%%Page: %d\n", ++surface->pages); @@ -375,7 +374,7 @@ _cairo_ps_surface_copy_page (void *abstract_surface) BAIL2: free (compressed); BAIL1: - free (bgr); + free (rgb); BAIL0: return status; }