bah.freeimage and SavePixmapPng
BlitzMax Forums/Brucey's Modules/bah.freeimage and SavePixmapPng
| ||
Brucey once again wanted to thank you for all the excellent work you've been doing! Without which my project would be seriously lacking. I seem to have discovered a bug with bah.freeimage and the SavePixmapPNG command. The following doesn't seem to work - SuperStrict Framework brl.pixmap Import BRL.PNGLoader Import bah.freeimage Local pix:TPixmap = CreatePixmap(300,300,PF_RGBA8888) ClearPixels(pix,GenRgb(0,0,255)) SavePixmapPNG(pix,"pixmaptest.png",0) Function GenRgb:Int(red:Int, green:Int, blue:Int, alpha:Int = 255) Local RGB:Int = (Alpha Shl 24) | (Red Shl 16) | (Green Shl 8) | Blue Return RGB End Function It's crashing at this line - Function SavePixmapPNG( pixmap:TPixmap,url:Object,compression=5 ) compression=Min( Max( compression,0 ),9 ) png_stream:TStream=WriteStream( url ) If Not png_stream Return Try Local png_ptr=png_create_write_struct( "1.2.12",Null,Null,Null )<--***CRASH*** Unfortunately my limited c++ knowledge is keeping me from being able to debug the code. :/ |
| ||
If I remember correctly, bah.freeimage clashes with the default image handlers, so it should be used by itself only. You can save images with bah.freeimage:SuperStrict Framework brl.pixmap Import bah.freeimage Local pix:TPixmap = CreatePixmap(300,300,PF_RGBA8888) ClearPixels(pix,GenRgb(0,0,255)) Local img:TFreeImage = TFreeImage.CreateFromPixmap(pix) img.save("pixmaptest.png",FIF_PNG) Function GenRgb:Int(red:Int, green:Int, blue:Int, alpha:Int = 255) Local RGB:Int = (Alpha Shl 24) | (Red Shl 16) | (Green Shl 8) | Blue Return RGB End Function |
| ||
Like what rs232 said :-) FreeImage has a plethora of image tools, including saving. If you are using the module, you may as well use them too! |
| ||
This is great! Thanks for the help! Except freeImage seems to be reversing the R and B components. Even overwriting the format field doesn't seem to help. SuperStrict Framework brl.pixmap Import bah.freeimage Local pix:TPixmap = CreatePixmap(300,300,PF_RGBA8888) ClearPixels(pix,GenRgb(0,0,255)) pix.format = PF_BGRA8888 Local img:TFreeImage = TFreeImage.CreateFromPixmap(pix) 'img.ConvertToType(FIT_RGBAF) img.save("pixmaptest.png",FIF_PNG) Function GenRgb:Int(red:Int, green:Int, blue:Int, alpha:Int = 255) Local RGB:Int = (Alpha Shl 24) | (Red Shl 16) | (Green Shl 8) | Blue Return RGB End Function I wrote a function to swap them to get by - SuperStrict Framework brl.pixmap Import bah.freeimage Local pix:TPixmap = CreatePixmap(300,300,PF_RGBA8888) ConvertPixmap(pix,PF_BGRA8888) ClearPixels(pix,GenRgb(0,0,255)) pix = SwapPixmapRB(pix) Local img:TFreeImage = TFreeImage.CreateFromPixmap(pix) 'img.ConvertToType(FIT_RGBAF) img.save("pixmaptest.png",FIF_PNG) Function GenRgb:Int(red:Int, green:Int, blue:Int, alpha:Int = 255) Local RGB:Int = (Alpha Shl 24) | (Red Shl 16) | (Green Shl 8) | Blue Return RGB End Function Function SwapPixmapRB:TPixmap(Pixmap:TPixmap) Local px:TPixmap = CopyPixmap(Pixmap) For Local x:Int = 0 Until px.width For Local y:Int = 0 Until px.height Local pxl:Int = ReadPixel(Pixmap,x,y) WritePixel(px,x,y,GenRGB(ARGB_B(pxl),ARGB_G(pxl),ARGB_R(pxl))) Next Next Return px End Function Function ARGB_R:Int(r:Int) Return (r Shr 16) & $FF End Function Function ARGB_G:Int(g:Int) Return (g Shr 8) & $FF End Function Function ARGB_B:Int(b:Int) Return b & $FF End Function |
| ||
Regarding the R and B being swapped round, I had a similar problem but it only seems to affect windows, Mac seemd ok. I did something like:?Win32 anim = anim.Convert(PF_BGRA8888) ? Local freeimage:TFreeImage = TFreeImage.CreateFromPixmap(anim) freeimage.save(tempfilename, FIF_PNG) Which seemed to sort it. |