Browse Source

* CoreImage codec now recognizes file extention and saves the image according to it

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@3021 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
jylam 16 years ago
parent
commit
0a3fb452ad
1 changed files with 20 additions and 1 deletions
  1. +20
    -1
      pipi/codec/coreimage.m

+ 20
- 1
pipi/codec/coreimage.m View File

@@ -90,7 +90,26 @@ int pipi_save_coreimage(pipi_image_t *img, const char *name)
if(bitmap == nil) return -1;
memcpy([bitmap bitmapData], p->pixels, p->w*p->h*4);

[[bitmap representationUsingType:NSPNGFileType properties:nil] writeToFile:n atomically:YES];
NSBitmapImageFileType type = NSPNGFileType;
if(strlen(name) > 4)
{
char *ext = (char*)&name[strlen(name) - 4];
if( !strncasecmp(ext, ".png", 3)) type = NSPNGFileType;
else if(!strncasecmp(ext, "jpeg", 4)) type = NSJPEGFileType;
else if(!strncasecmp(ext, ".jpg", 3)) type = NSJPEGFileType;
else if(!strncasecmp(ext, ".bmp", 3)) type = NSBMPFileType;
else if(!strncasecmp(ext, ".tif", 3)) type = NSTIFFFileType;
else if(!strncasecmp(ext, ".tiff", 3)) type = NSTIFFFileType;
else if(!strncasecmp(ext, ".gif", 3)) type = NSGIFFileType;
else if(!strncasecmp(ext, ".bmp", 3)) type = NSBMPFileType;
else if(!strncasecmp(ext, ".jp2", 3)) type = NSJPEG2000FileType;
else if(!strncasecmp(ext, ".j2k", 3)) type = NSJPEG2000FileType;
}
[[bitmap representationUsingType:type properties:nil] writeToFile:n atomically:YES];
[autoreleasepool release];

return 1;


Loading…
Cancel
Save