diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2017-04-20 22:06:14 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2017-04-20 22:06:14 +0200 |
commit | df16832c0c43015500b4f71aebabbb14e127b447 (patch) | |
tree | e6d6c22fe01ae07c0060c8795b7cea8bc7084da8 | |
parent | 3377d6e3a37358bf47c23bd6a9213db354535141 (diff) | |
download | fbida-df16832c0c43015500b4f71aebabbb14e127b447.tar.gz |
fix flip & rotate
-rw-r--r-- | op.c | 42 | ||||
-rw-r--r-- | readers.c | 13 | ||||
-rw-r--r-- | readers.h | 2 |
3 files changed, 35 insertions, 22 deletions
@@ -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; } } @@ -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); @@ -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); /* ----------------------------------------------------------------------- */ |