diff --git a/pipi/codec/coreimage.m b/pipi/codec/coreimage.m index b969e82..4e4a8b3 100644 --- a/pipi/codec/coreimage.m +++ b/pipi/codec/coreimage.m @@ -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;