aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2017-04-20 22:06:14 +0200
committerGerd Hoffmann <kraxel@redhat.com>2017-04-20 22:06:14 +0200
commitdf16832c0c43015500b4f71aebabbb14e127b447 (patch)
treee6d6c22fe01ae07c0060c8795b7cea8bc7084da8
parent3377d6e3a37358bf47c23bd6a9213db354535141 (diff)
downloadfbida-df16832c0c43015500b4f71aebabbb14e127b447.tar.gz
fix flip & rotate
-rw-r--r--op.c42
-rw-r--r--readers.c13
-rw-r--r--readers.h2
3 files changed, 35 insertions, 22 deletions
diff --git a/op.c b/op.c
index e9ce52f..6273541 100644
--- a/op.c
+++ b/op.c
@@ -19,7 +19,7 @@ op_flip_vert(struct ida_image *src, struct ida_rect *rect,
char *scanline;
scanline = ida_image_scanline(src, src->i.height - line - 1);
- memcpy(dst,scanline,src->i.width*3);
+ memcpy(dst, scanline, ida_image_stride(src));
}
static void
@@ -27,15 +27,15 @@ op_flip_horz(struct ida_image *src, struct ida_rect *rect,
unsigned char *dst, int line, void *data)
{
char *scanline;
- unsigned int i;
+ unsigned int i, bpp;
- scanline = ida_image_scanline(src, line+1);
+ bpp = ida_image_bpp(src);
+ scanline = ida_image_scanline(src, line);
+ scanline += src->i.width * bpp;
for (i = 0; i < src->i.width; i++) {
- scanline -= 3;
- dst[0] = scanline[0];
- dst[1] = scanline[1];
- dst[2] = scanline[2];
- dst += 3;
+ scanline -= bpp;
+ memcpy(dst, scanline, bpp);
+ dst += bpp;
}
}
@@ -55,15 +55,14 @@ op_rotate_cw(struct ida_image *src, struct ida_rect *rect,
unsigned char *dst, int line, void *data)
{
char *pix;
- unsigned int i;
+ unsigned int i, bpp;
- pix = ida_image_scanline(src, src->i.height) + line * 3;
+ bpp = ida_image_bpp(src);
+ pix = ida_image_scanline(src, src->i.height) + line * bpp;
for (i = 0; i < src->i.height; i++) {
- pix -= src->i.width * 3;
- dst[0] = pix[0];
- dst[1] = pix[1];
- dst[2] = pix[2];
- dst += 3;
+ pix -= ida_image_stride(src);
+ memcpy(dst, pix, bpp);
+ dst += bpp;
}
}
@@ -72,15 +71,14 @@ op_rotate_ccw(struct ida_image *src, struct ida_rect *rect,
unsigned char *dst, int line, void *data)
{
char *pix;
- unsigned int i;
+ unsigned int i, bpp;
- pix = ida_image_scanline(src, 0) + (src->i.width-line-1) * 3;
+ bpp = ida_image_bpp(src);
+ pix = ida_image_scanline(src, 0) + (src->i.width-line-1) * bpp;
for (i = 0; i < src->i.height; i++) {
- dst[0] = pix[0];
- dst[1] = pix[1];
- dst[2] = pix[2];
- pix += src->i.width * 3;
- dst += 3;
+ memcpy(dst, pix, bpp);
+ pix += ida_image_stride(src);
+ dst += bpp;
}
}
diff --git a/readers.c b/readers.c
index b7da842..4fd09fc 100644
--- a/readers.c
+++ b/readers.c
@@ -144,6 +144,19 @@ uint8_t *ida_image_scanline(struct ida_image *img, int y)
return scanline;
}
+uint32_t ida_image_stride(struct ida_image *img)
+{
+ return pixman_image_get_stride(img->p);
+}
+
+uint32_t ida_image_bpp(struct ida_image *img)
+{
+ uint32_t bits = PIXMAN_FORMAT_BPP(pixman_image_get_format(img->p));
+ uint32_t bytes = bits / 8;
+ assert(bytes * 8 == bits);
+ return bytes;
+}
+
void ida_image_free(struct ida_image *img)
{
assert(img->p != NULL);
diff --git a/readers.h b/readers.h
index 1ad0e94..171ac76 100644
--- a/readers.h
+++ b/readers.h
@@ -89,6 +89,8 @@ int load_free_extras(struct ida_image_info *info);
void ida_image_alloc(struct ida_image *img);
uint8_t *ida_image_scanline(struct ida_image *img, int y);
+uint32_t ida_image_stride(struct ida_image *img);
+uint32_t ida_image_bpp(struct ida_image *img);
void ida_image_free(struct ida_image *img);
/* ----------------------------------------------------------------------- */