Hi,

Thanks to Eric's help earlier, I managed to get wx running and run
some simple programs in it. I have run into the following
(unconnected) problems with the API:

There doesn't seem to be a binding to wxImage's "SetOption" call. I
need to this to save a JPEG at anything other than the default
quality. I'm loading in a JPEG, cropping, and saving out: if you
recompress that at low quality you really suffer from jpg artifacts.

There doesn't seem to be a binding to the "wxImage-from-WXStream"
constructor. In particular, it would be nice to have a version using a
wxMemoryInputStream so that you can load a wxImage from a Ptr, such as
if you get an image via a network protocol or embedded in a larger
file.

I have random segfaults when calling imageGetPixels. Seems to be with
a probability of something like 25%. Here is the code I've written
(which generates an openGL texture from a WX bitmap):

textureFromBitmap bmp = do
     image <- imageCreateFromBitmap bmp
     pixels <- imageGetData image
     putStrLn $ "pixels : " ++ show pixels
     bytes <- peekArray 8 (castPtr pixels)
     putStrLn $ "bytes : " ++ show (bytes :: [Word8])
     WX.Size w h <- imageGetSize image
     putStrLn $ "Image size : " ++ show (w,h)
     pixs <- imageGetPixels image
     putStrLn $ "number of pixs = " ++ show (length pixs)
     putStrLn $ "first pixel " ++ show (head pixs)

     [tex] <- genObjectNames 1
     textureBinding Texture2D $= Just tex
     textureWrapMode Texture2D T $= (Repeated,Repeat)
     textureWrapMode Texture2D S $= (Repeated,Repeat)
     textureFilter Texture2D $= ((Nearest,  Nothing), Linear')
     let wxToColor3 :: WX.Color -> Color3 GLubyte
         wxToColor3 c = Color3 (fromIntegral $ WX.colorRed c)
                        (fromIntegral $ WX.colorGreen c)
                        (fromIntegral $ WX.colorBlue c)
         padded | w `mod` 2 == 0 = pixs
                | otherwise = concatMap (\x -> x ++ [WX.colorRGB 0 0 0]) .
                              chunksOf w $ pixs
         chunksOf n l = takeWhile (not.null) . map (take n) . iterate 
(drop n) $ l
     withArray (map wxToColor3 padded) $
       \a -> texImage2D Nothing NoProxy 0 RGBA' (TextureSize2D 
(fromIntegral w) (fromIntegral h)) 0
               (PixelData RGB UnsignedByte a)
     return tex

It doesn't appear to be relevant where the bitmap comes from, I've
seen the segfault with bitmaps coming from "bitmapCreateFromFile" as
well as from "bitmapCreateEmpty".

About 1 time in 4, this will segfault with the last thing printed
being the "Image size" putStrLn, leading me to think that
imageGetPixels is segfaulting. gdb doesn't tell me anything useful
- presumably because my wx libraries are not compiled with debug info?
Is there a wx configure option for that? I'll have a look and see what
I can see.

Thanks for providing such a useful binding,

Jules Bean

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
wxhaskell-users mailing list
wxhaskell-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wxhaskell-users

Reply via email to