faster saveimage 8bit on OS X
Posted: Tue Aug 09, 2011 12:00 am
On my MacBook Air with SSD drive, 32bit and 4bit save within a second. But 8bit takes a few seconds. I haven't done any testing on XP or Linux to see if this is also true.
http://www.purebasic.com
https://www.purebasic.fr/english/
PNG format. I also began to wonder if it was due to the fact that converting a 32bit png to a 8bit png might be slower then 4bits because there is 256 colors instead of 16 to convert to? Could this be possible?wilbert wrote:What file format are you using ?
I use it in my Sprite Monkey app. Because if you are going to make a retro style game and use less colors, it might as well be in a 8bit or 4bit image format. Much smaller file size.wilbert wrote:I'm not sure but I imagine it can be a reason.
It probably has to do with finding the best color palette when decreasing the color depth.
Any reason why you are using 8 bit ?
Yeah, I thought about that or just creating my own procedure using plot and point. Which I already use for removing the alpha from 32bit to convert to 8 and 4bit. That way I could have a true RGB(255, 0, 255) background for those formats and not have to worry about the alpha channel blending into the RGB(255, 0, 255) background.wilbert wrote:I don't know how PureBasic handles things.
Maybe you could use api calls to speed things up.
Code: Select all
#kFSCatInfoNone = 0
#kOnSystemDisk = $8000
#kDesktopFolderType = 'desk'
#GraphicsExporterComponentType = 'grex'
#kQTFileTypePNG = 'PNGf'
#k4IndexedPixelFormat = 4
#k8IndexedPixelFormat = 8
ImportC ""
FSFindFolder(vRefNum, folderType, createFolder, *foundRef)
FSCreateFileUnicode(*parentRef, nameLength, name.p-unicode, whichInfo, *catalogInfo, *newRef, newSpec)
EndImport
ImportC "/System/Library/Frameworks/QuickTime.framework/QuickTime"
OpenADefaultComponent(componentType, componentSubType, *ci)
GraphicsExportSetInputCGImage(ci, imageRef)
GraphicsExportSetDepth(ci, depth)
GraphicsExportSetOutputFile(ci, *theFile)
GraphicsExportDoExport(ci, *actualSizeWritten)
CloseComponent(ci)
EndImport
CreateImage(0, 200, 200)
ImgRef = ImageID(0)
OpenADefaultComponent(#GraphicsExporterComponentType, #kQTFileTypePNG, @ci); export to png
GraphicsExportSetInputCGImage(ci, ImgRef); set input image
GraphicsExportSetDepth(ci, #k8IndexedPixelFormat); 8 bit
FSFindFolder(#kOnSystemDisk, #kDesktopFolderType, 0, @parentDir); find desktop folder
FSCreateFileUnicode(@parentDir, 8, "test.png", #kFSCatInfoNone, #Null, #Null, @fileSpec); create 'test.png' file on desktop
GraphicsExportSetOutputFile(ci, @fileSpec); set the file to export the image to
GraphicsExportDoExport(ci, #Null); export the image
CloseComponent(ci)
Code: Select all
#kFSCatInfoNone = 0
#kOnSystemDisk = $8000
#kDesktopFolderType = 'desk'
#kTextEncodingUnknown = $ffff
#GraphicsExporterComponentType = 'grex'
#kQTFileTypePNG = 'PNGf'
#kQTFileTypeTIFF = 'TIFF'
#kQTFileTypeBMP = 'BMPf'
#kQTFileTypeJPEG = 'JPEG'
#kQTFileTypeTargaImage = 'TPIC'
#k4IndexedPixelFormat = 4
#k8IndexedPixelFormat = 8
ImportC ""
FSFindFolder(vRefNum, folderType, createFolder, *foundRef)
FSMakeFSRefUnicode(*parentRef, nameLength, name.p-unicode, textEncodingHint, *newRef)
FSDeleteObject(*ref)
FSCreateFileUnicode(*parentRef, nameLength, name.p-unicode, whichInfo, *catalogInfo, *newRef, newSpec)
EndImport
ImportC "/System/Library/Frameworks/QuickTime.framework/QuickTime"
OpenADefaultComponent(componentType, componentSubType, *ci)
GraphicsExportSetInputCGImage(ci, imageRef)
GraphicsExportSetDepth(ci, depth)
GraphicsExportSetOutputFile(ci, *theFile)
GraphicsExportSetOutputHandle(ci, handle)
GraphicsExportDoExport(ci, *actualSizeWritten)
CloseComponent(ci)
EndImport
Procedure QTSaveImage(ImageID, FileName.s)
Global parentDir, fileSpec; don't know why but function crashes when there are not global
OpenADefaultComponent(#GraphicsExporterComponentType, #kQTFileTypePNG, @ci); export to png
GraphicsExportSetInputCGImage(ci, ImageID); set input image
GraphicsExportSetDepth(ci, #k8IndexedPixelFormat); 8 bit
FSFindFolder(#kOnSystemDisk, #kDesktopFolderType, 0, @parentDir); find desktop folder
FSMakeFSRefUnicode(@parentDir, Len(Filename), Filename, #kTextEncodingUnknown, @fileSpec); find existing file
If fileSpec : FSDeleteObject(@fileSpec) : EndIf; delete file if it exists
FSFindFolder(#kOnSystemDisk, #kDesktopFolderType, 0, @parentDir); find desktop folder
FSCreateFileUnicode(@parentDir, Len(FileName), Filename, #kFSCatInfoNone, #Null, #Null, @fileSpec); create new 'test.png' file on desktop
GraphicsExportSetOutputFile(ci, @fileSpec); set the file to export the image to
GraphicsExportDoExport(ci, #Null); export the image
CloseComponent(ci)
EndProcedure
If OpenWindow(0, 0, 0, 200, 200, "QT 2DDrawing Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
y = 0
For x = 0 To 95 Step 10
Box(x, y, 200-2*x, 200-2*y, RGB(Random(255), Random(255), Random(255)))
y + 10
Next x
StopDrawing()
ImageGadget(0, 0, 0, 200, 200, ImageID(0))
EndIf
QTSaveImage(ImageID(0), "test.png"); save test.png to desktop
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf