--- ghostscript-7.07/src/gdevescv.c.a-urasim 2006-04-08 19:37:19.000000000 +0900 +++ ghostscript-7.07/src/gdevescv.c 2006-04-08 20:27:11.000000000 +0900 @@ -85,6 +85,7 @@ #define ESCV_FORCEDRAWPATH 0 /* 0: correct LP-9200C path trouble. */ +#define RGBtoG8(r,g,b) ((byte)((int)((r)*0.29891+(g)*0.58661+(b)*0.11448+0.5) & 0xff)) /* ---------------- Device definition ---------------- */ @@ -235,7 +236,7 @@ 0, /* bool Duplex; */\ ESCPAGE_TUMBLE_DEFAULT, /* bool Tumble; */\ 0, /* int ncomp; */\ - 0, /* int MaskReverse; */\ + -1, /* int MaskReverse; */\ 0, /* int MaskState; */\ TRUE, /* bool c4map; * 4bit ColorMap * */\ TRUE, /* bool c8map; * 8bit ColorMap * */\ @@ -2248,8 +2249,7 @@ gx_device_vector *const vdev = (gx_device_vector *) dev; int depth = dev->color_info.depth; - int num_components = (depth < 24 ? 1 : 3); - uint width_bytes = w * num_components; + uint width_bytes = w * ((depth < 24 || pdev->colormode == 0) ? 1 : 3); if (pdev->MaskState != 0) { @@ -2274,7 +2274,17 @@ byte *buf = gs_alloc_bytes(vdev->memory, num_bytes, "escv_copy_color(buf)"); for (i = 0; i < h; ++i) { - memcpy(buf + i * width_bytes, data + ((data_x * depth) >> 3) + i * raster, width_bytes); + if(depth == 24 && pdev->colormode == 0){ + int j; + byte *d = buf + i * width_bytes; + byte *p = data + ((data_x * depth) >>3) + i * raster; + for(j = 0; j < w; j++){ + *d++ = RGBtoG8(*p, *(p+1), *(p+2)); + p += 3; + } + } else { + memcpy(buf + i * width_bytes, data + ((data_x * depth) >> 3) + i * raster, width_bytes); + } } escv_write_data(dev, depth, buf, num_bytes, w, h); @@ -2616,7 +2626,12 @@ if (height == 260) height = 1; #endif - width_bytes = (pie->width * pie->bits_per_pixel / pdev->ncomp + 7) / 8 * pdev->ncomp; + if ( pie->bits_per_pixel == 24 && pdev->colormode == 0){ + width_bytes = (pie->width * 8 + 7) / 8; + } + else { + width_bytes = (pie->width * pie->bits_per_pixel / pdev->ncomp + 7) / 8 * pdev->ncomp; + } tbyte = width_bytes * height; buf = gs_alloc_bytes(vdev->memory, tbyte, "escv_image_data(buf)"); @@ -2680,54 +2695,57 @@ byte c; p = planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3) + y * planes[plane].raster; - if (pdev -> reverse_y) { - - d = buf + (height - y) * width_bytes; - - if (!pdev -> reverse_x) { - (void)memcpy(buf + (height - y - 1) * width_bytes, - planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3) - + y * planes[plane].raster, width_bytes); - - } - - } else { - - d = buf + (y + 1) * width_bytes; - - if (!pdev -> reverse_x) { - - (void)memcpy(buf + y * width_bytes, - planes[plane].data + ((planes[plane].data_x * pie->bits_per_pixel) >> 3) - + y * planes[plane].raster, width_bytes); - - } - } - if (pdev -> reverse_x) { - if (pie->bits_per_pixel == 1) { - for (w = 0; w < width_bytes; w++) { - c = 0; - for (bit = 0; bit < 8; bit++) { - if (*p & 1 << (7 - bit)) { - c |= 1 << bit; - } - } - p++; - *--d = c; - } - } else if (pie->bits_per_pixel == 8){ - for (w = 0; w < width_bytes; w++) { - *--d = *p++; - } - } else { - for (w = 0; w < width_bytes / 3; w++) { - *--d = *(p + 2); - *--d = *(p + 1); - *--d = *p; - p += 3; - } - } - } + if (!pdev -> reverse_x) { + if (!pdev -> reverse_y) { + d = buf + y * width_bytes; + } else { + d = buf + (height - y - 1) * width_bytes; + } + + if (pie->bits_per_pixel == 24 && pdev->colormode == 0) { + for(w = 0; w < width_bytes; w++){ + *d++ = RGBtoG8(*p, *(p+1), *(p+2)); + p += 3; + } + } else { + (void)memcpy(d, p, width_bytes); + } + } else { + if (!pdev -> reverse_y) { + d = buf + (y + 1) * width_bytes; + } else { + d = buf + (height - y) * width_bytes; + } + + if (pie->bits_per_pixel == 1) { + for (w = 0; w < width_bytes; w++) { + c = 0; + for (bit = 0; bit < 8; bit++) { + if (*p & 1 << (7 - bit)) { + c |= 1 << bit; + } + } + p++; + *--d = c; + } + } else if (pie->bits_per_pixel == 8) { + for (w = 0; w < width_bytes; w++) { + *--d = *p++; + } + } else if (pie->bits_per_pixel == 24 && pdev->colormode == 0) { + for(w = 0; w < width_bytes; w++){ + *--d = RGBtoG8(*p, *(p+1), *(p+2)); + p += 3; + } + } else { + for (w = 0; w < width_bytes / 3; w++) { + *--d = *(p + 2); + *--d = *(p + 1); + *--d = *p; + p += 3; + } + } + } } } @@ -2973,6 +2991,11 @@ }else{ (void)sprintf(obuf, ESC_GS "%d;%du{I", bsize, ras); } + if (pdev->MaskReverse == 0) { + for(size = 0; size < bsize; size++) { + buf[size] ^= 0xff; + } + } }else{ (void)sprintf(obuf, ESC_GS "%d;%dcu{I", bsize, ras); }