From 4354bf70a42118d03ee0ec1dbe229c1b6ca751c8 Mon Sep 17 00:00:00 2001 From: jylam Date: Sun, 19 Oct 2008 12:32:42 +0000 Subject: [PATCH] * Convert CoreImage buffer to RGBA right after loading * Crop padding while needed, making pitch consistent with (width*bytesperpixel) git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3032 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/codec/coreimage.m | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/pipi/codec/coreimage.m b/pipi/codec/coreimage.m index 4e4a8b3..1a70f04 100644 --- a/pipi/codec/coreimage.m +++ b/pipi/codec/coreimage.m @@ -46,7 +46,7 @@ pipi_image_t *pipi_load_coreimage(const char *name) pipi_image_t *img; img = pipi_new(w, h); - img->p[PIPI_PIXELS_RGBA_C].pixels = [myImage bitmapData]; + img->p[PIPI_PIXELS_RGBA_C].w = w; img->p[PIPI_PIXELS_RGBA_C].h = h; img->p[PIPI_PIXELS_RGBA_C].pitch = ([myImage bytesPerRow]/8) * img->w; @@ -54,6 +54,45 @@ pipi_image_t *pipi_load_coreimage(const char *name) img->p[PIPI_PIXELS_RGBA_C].bytes = ([myImage bitsPerPixel]/8) * img->w * img->h; img->last_modified = PIPI_PIXELS_RGBA_C; + + /* CoreImage feeds us with BGRA while we need RGBA, so convert it. + * We also need to get a pitch==(w*bpp) in order to pipi to opper properly. + */ + + int pitch = (img->p[PIPI_PIXELS_RGBA_C].bpp/8); + unsigned char *tmp = (unsigned char*)malloc(h*w*pitch); + unsigned char *orig = (unsigned char*)[myImage bitmapData]; + int x, y, k=0, o=0, a=[myImage bytesPerRow] - (w*([myImage bitsPerPixel]/8)); + + for(y=0; yp[PIPI_PIXELS_RGBA_C].pixels = tmp; + img->p[PIPI_PIXELS_RGBA_C].pitch = w*([myImage bitsPerPixel]/8); + + + + img->codec_priv = (struct pipi_codec_coreimage *) malloc(sizeof(struct pipi_codec_coreimage *)); struct pipi_codec_coreimage *infos = (struct pipi_codec_coreimage *) img->codec_priv; infos->format = [myImage bitmapFormat]; @@ -108,7 +147,6 @@ int pipi_save_coreimage(pipi_image_t *img, const char *name) else if(!strncasecmp(ext, ".j2k", 3)) type = NSJPEG2000FileType; } - [[bitmap representationUsingType:type properties:nil] writeToFile:n atomically:YES]; [autoreleasepool release];