diff options
author | scuri <scuri> | 2010-06-04 17:36:53 +0000 |
---|---|---|
committer | scuri <scuri> | 2010-06-04 17:36:53 +0000 |
commit | 1bad658bce4895bab21b2aab65c82544871fa551 (patch) | |
tree | 53bc33a2e2bf442faa0c716ec59a29b0ed89124b /src/cairo/cdcairo.c | |
parent | dd7a1955dbf538734dc54225eac5282e3ab35ff8 (diff) |
*** empty log message ***
Diffstat (limited to 'src/cairo/cdcairo.c')
-rw-r--r-- | src/cairo/cdcairo.c | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/src/cairo/cdcairo.c b/src/cairo/cdcairo.c index 9589d74..67a778c 100644 --- a/src/cairo/cdcairo.c +++ b/src/cairo/cdcairo.c @@ -1210,12 +1210,23 @@ static void cdgetimagergb(cdCtxCanvas *ctxcanvas, unsigned char *r, unsigned cha cairo_surface_destroy(image_surface); cairo_destroy(cr); - cairo_restore (ctxcanvas->cr); + cairo_restore(ctxcanvas->cr); +} + +static void sFixImageY(cdCanvas* canvas, int *topdown, int *y, int h) +{ + if (canvas->invert_yaxis) + *topdown = 0; + else + *topdown = 1; + + if (!(*topdown)) + *y -= (h - 1); /* move Y to top-left corner, since it was at the bottom of the image */ } static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax) { - int i, j, rw, rh, pos, offset; + int i, j, rw, rh, pos, offset, topdown; unsigned long* data; cairo_surface_t* image_surface; @@ -1229,11 +1240,16 @@ static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi data = (unsigned long*)cairo_image_surface_get_data(image_surface); offset = cairo_image_surface_get_stride(image_surface)/4 - rw; - for (i=ymax; i>=ymin; i--) + sFixImageY(ctxcanvas->canvas, &topdown, &y, h); + + for (i=ymin; i<=ymax; i++) { for (j=xmin; j<=xmax; j++) { - pos = i*iw+j; + if (topdown) + pos = i*iw+j; + else + pos = (ymax+ymin - i)*iw+j; *data++ = sEncodeRGBA(r[pos], g[pos], b[pos], 255); } @@ -1243,8 +1259,6 @@ static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi cairo_save (ctxcanvas->cr); - y -= (h - 1); /* Cairo image origin is at top-left */ - cairo_rectangle(ctxcanvas->cr, x, y, w, h); cairo_clip(ctxcanvas->cr); @@ -1265,7 +1279,7 @@ static void cdputimagerectrgb(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *r, const unsigned char *g, const unsigned char *b, const unsigned char *a, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax) { - int i, j, rw, rh, pos, offset; + int i, j, rw, rh, pos, offset, topdown; unsigned long* data; cairo_surface_t* image_surface; @@ -1279,11 +1293,16 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns data = (unsigned long*)cairo_image_surface_get_data(image_surface); offset = cairo_image_surface_get_stride(image_surface)/4 - rw; - for (i=ymax; i>=ymin; i--) + sFixImageY(ctxcanvas->canvas, &topdown, &y, h); + + for (i=ymin; i<=ymax; i++) { for (j=xmin; j<=xmax; j++) { - pos = i*iw+j; + if (topdown) + pos = i*iw+j; + else + pos = (ymax+ymin - i)*iw+j; *data++ = sEncodeRGBA(r[pos], g[pos], b[pos], a[pos]); } @@ -1293,8 +1312,6 @@ static void cdputimagerectrgba(cdCtxCanvas *ctxcanvas, int iw, int ih, const uns cairo_save (ctxcanvas->cr); - y -= (h - 1); /* Cairo image origin is at top-left */ - cairo_rectangle(ctxcanvas->cr, x, y, w, h); cairo_clip(ctxcanvas->cr); @@ -1329,7 +1346,7 @@ static int sCalcPalSize(int size, const unsigned char *index) static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsigned char *index, const long int *colors, int x, int y, int w, int h, int xmin, int xmax, int ymin, int ymax) { - int i, j, rw, rh, pos, offset, pal_size; + int i, j, rw, rh, pos, offset, pal_size, topdown; unsigned long* data, cairo_colors[256], c; cairo_surface_t* image_surface; @@ -1350,11 +1367,16 @@ static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi cairo_colors[i] = sEncodeRGBA(cdRed(c), cdGreen(c), cdBlue(c), 255); } - for (i=ymax; i>=ymin; i--) + sFixImageY(ctxcanvas->canvas, &topdown, &y, h); + + for (i=ymin; i<=ymax; i++) { for (j=xmin; j<=xmax; j++) { - pos = i*iw+j; + if (topdown) + pos = i*iw+j; + else + pos = (ymax+ymin - i)*iw+j; *data++ = cairo_colors[index[pos]]; } @@ -1364,8 +1386,6 @@ static void cdputimagerectmap(cdCtxCanvas *ctxcanvas, int iw, int ih, const unsi cairo_save (ctxcanvas->cr); - y -= (h - 1); /* Cairo image origin is at top-left */ - cairo_rectangle(ctxcanvas->cr, x, y, w, h); cairo_clip(ctxcanvas->cr); |