ソースを参照

* 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
remotes/tiles
jylam 16年前
コミット
4354bf70a4
1個のファイルの変更40行の追加2行の削除
  1. +40
    -2
      pipi/codec/coreimage.m

+ 40
- 2
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; y<h; y++)
{
for(x=0; x<w*pitch; x+=4)
{
if(!([myImage bitmapFormat] & NSAlphaFirstBitmapFormat))
{
tmp[k+2] = orig[o];
tmp[k+1] = orig[o+1];
tmp[k+0] = orig[o+2];
tmp[k+3] = orig[o+3];
} else
{
tmp[k+0] = orig[o];
tmp[k+1] = orig[o+1];
tmp[k+2] = orig[o+2];
tmp[k+3] = orig[o+3];
}
o+=4;
k+=4;
}
o+=a;
}
img->p[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];



読み込み中…
キャンセル
保存