{-# OPTIONS -fffi -fglasgow-exts #-} {- Haskell Binding for Imlib 2 Cale Gibbard Mar 20 2004 -} {- New exported calls: image_with_data color_to_bits create_image_using_list -} -- TODO: Convenience wrappers for reading in proper Haskell arrays/lists in the case -- image_get_data, image_get_data_for_reading_only, image_put_back_data and image_with_data {- -- Not imported -- This list contains anything which interfaces with X (i.e. uses Display/Visual/Drawable/Colormap/Pixmap) -- as I'm not sure about what standard lowlevel X bindings there are as of yet, and what would be convenient. -- If I do ecore eventually, they'll probably get written. -- Apart from that, the only thing that is in this list is imlib_apply_filter (which is rather unfortunate, -- since it's a cool feature). It uses va_args, so perhaps some Template Haskell is in order. int imlib_get_visual_depth(Display *display, Visual *visual); Visual *imlib_get_best_visual(Display *display, int screen, int *depth_return); void imlib_context_set_display(Display *display); void imlib_context_set_visual(Visual *visual); void imlib_context_set_colormap(Colormap colormap); void imlib_context_set_drawable(Drawable drawable); void imlib_context_set_mask(Pixmap mask); Display *imlib_context_get_display(void); Visual *imlib_context_get_visual(void); Colormap imlib_context_get_colormap(void); Drawable imlib_context_get_drawable(void); Pixmap imlib_context_get_mask(void); void imlib_render_pixmaps_for_whole_image(Pixmap *pixmap_return, Pixmap *mask_return); void imlib_render_pixmaps_for_whole_image_at_size(Pixmap *pixmap_return, Pixmap *mask_return, int width, int height); void imlib_free_pixmap_and_mask(Pixmap pixmap); void imlib_render_image_on_drawable(int x, int y); void imlib_render_image_on_drawable_at_size(int x, int y, int width, int height); void imlib_render_image_part_on_drawable_at_size(int source_x, int source_y, int source_width, int source_height, int x, int y, int width, int height); Imlib_Image imlib_create_image_from_drawable(Pixmap mask, int x, int y, int width, int height, char need_to_grab_x); Imlib_Image imlib_create_scaled_image_from_drawable(Pixmap mask, int source_x, int source_y, int source_width, int source_height, int destination_width, int destination_height, char need_to_grab_x, char get_mask_from_shape); char imlib_copy_drawable_to_image(Pixmap mask, int x, int y, int width, int height, int destination_x, int destination_y, char need_to_grab_x); void imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x, int y); void imlib_render_image_on_drawable_skewed(int source_x, int source_y, int source_width, int source_height, int destination_x, int destination_y, int h_angle_x, int h_angle_y, int v_angle_x, int v_angle_y); void imlib_render_image_on_drawable_at_angle(int source_x, int source_y, int source_width, int source_height, int destination_x, int destination_y, int angle_x, int angle_y); void imlib_apply_filter( char *script, ... ); -} module Imlib ( Imlib_Progress_Function, Imlib_Data_Destructor_Function, Imlib_TTF_Encoding (..), Imlib_Load_Error (..), Imlib_Text_Direction (..), Imlib_Operation (..), Imlib_Color (..), Imlib_Border (..), Imlib_Polygon, Imlib_Filter, Imlib_Color_Range, Imlib_Font, Imlib_Updates, Imlib_Color_Modifier, Imlib_Image, Imlib_Context, context_set_dither_mask, context_set_anti_alias, context_set_dither, context_set_blend, context_set_color_modifier, context_set_operation, context_set_font, context_set_direction, context_set_angle, context_set_color, context_set_color_cmya, context_set_color_hsva, context_set_color_hlsa, context_set_color_range, context_set_progress_function, context_set_progress_granularity, context_set_filter, context_set_image, context_get_dither_mask, context_get_anti_alias, context_get_dither, context_get_blend, context_get_color_modifier, context_get_operation, context_get_font, context_get_angle, context_get_direction, context_get_color, context_get_color_cmya, context_get_color_hsva, context_get_color_hlsa, context_get_imlib_color, context_get_color_range, context_get_progress_function, context_get_progress_granularity, context_get_image, context_get_filter, get_cache_size, set_cache_size, get_color_usage, set_color_usage, flush_loaders, load_image, load_image_immediately, load_image_without_cache, load_image_immediately_without_cache, load_image_with_error_return, free_image, free_image_and_decache, image_get_width, image_get_height, image_get_filename, image_get_data, image_get_data_for_reading_only, image_put_back_data, image_with_data, image_has_alpha, image_set_changes_on_disk, image_get_border, image_set_border, image_set_format, image_set_irrelevant_format, image_set_irrelevant_border, image_set_irrelevant_alpha, image_format, image_set_has_alpha, blend_image_onto_image, create_image, create_image_using_data, create_image_using_copied_data, clone_image, create_cropped_image, create_cropped_scaled_image, updates_clone, update_append_rect, updates_merge, updates_merge_for_rendering, updates_free, updates_get_next, updates_get_coordinates, updates_set_coordinates, updates_init, updates_append_updates, image_flip_horizontal, image_flip_vertical, image_flip_diagonal, image_orientate, image_blur, image_sharpen, image_tile_horizontal, image_tile_vertical, image_tile, load_font, free_font, text_draw, text_draw_with_return_metrics, get_text_size, get_text_advance, get_text_inset, add_path_to_font_path, remove_path_from_font_path, list_font_path, text_get_index_and_location, text_get_location_at_index, list_fonts, get_font_cache_size, set_font_cache_size, flush_font_cache, get_font_ascent, get_font_descent, get_maximum_font_ascent, get_maximum_font_descent, create_color_modifier, free_color_modifier, modify_color_modifier_gamma, modify_color_modifier_brightness, modify_color_modifier_contrast, set_color_modifier_tables, get_color_modifier_tables, reset_color_modifier, apply_color_modifier, apply_color_modifier_to_rectangle, image_draw_line, image_draw_rectangle, image_fill_rectangle, image_copy_alpha_to_image, image_copy_alpha_rectangle_to_image, image_scroll_rect, image_copy_rect, create_color_range, free_color_range, add_color_to_color_range, image_fill_color_range_rectangle, image_fill_hsva_color_range_rectangle, image_query_pixel, image_query_pixel_cmya, image_query_pixel_hsva, image_query_pixel_hlsa, image_attach_data_value, image_get_attached_data, image_get_attached_value, image_remove_attached_data_value, image_remove_and_free_attached_data_value, save_image, save_image_with_error_return, create_rotated_image, blend_image_onto_image_at_angle, blend_image_onto_image_skewed, context_set_cliprect, clip_line, polygon_new, polygon_free, polygon_add_point, image_draw_polygon, image_fill_polygon, polygon_get_bounds, polygon_contains_point, image_draw_ellipse, image_fill_ellipse, image_filter, create_filter, free_filter, filter_set, filter_set_alpha, filter_set_red, filter_set_green, filter_set_blue, filter_constants, filter_divisors ) where import Foreign import Foreign.C import Data.Bits import Array {- Types from the Imlib 2 header typedef void *Imlib_Context; typedef void *Imlib_Image; typedef void *Imlib_Color_Modifier; typedef void *Imlib_Updates; typedef void *Imlib_Font; typedef void *Imlib_Color_Range; typedef void *Imlib_Filter; typedef struct _imlib_border Imlib_Border; typedef struct _imlib_color Imlib_Color; typedef void *ImlibPolygon; -} ----- Utility Calls replicateM n x = sequence $ replicate n x nmalloc :: Storable a => Int -> IO [Ptr a] nmalloc n = replicateM n malloc nmallocArray :: Storable a => Int -> Int -> IO [Ptr a] nmallocArray n m = replicateM n (mallocArray m) ----- data Imlib_Context data Imlib_Image data Imlib_Color_Modifier data Imlib_Updates data Imlib_Font data Imlib_Color_Range data Imlib_Filter data Imlib_Polygon data Imlib_Border = Imlib_Border Int Int Int Int deriving (Show, Eq) -- left, right, top, bottom instance Storable Imlib_Border where sizeOf _ = 16 alignment _ = 4 peek p = do [a,b,c,d] <- peekArray 4 (castPtr p) return (Imlib_Border a b c d) where poke p (Imlib_Border a b c d) = do pokeArray (castPtr p) [a,b,c,d] data Imlib_Color = Imlib_Color Word32 Word32 Word32 Word32 deriving (Show, Eq) -- alpha, red, green, blue instance Storable Imlib_Color where sizeOf _ = 16 alignment _ = 4 peek p = do [a,b,c,d] <- peekArray 4 (castPtr p) return (Imlib_Color a b c d) where poke p (Imlib_Color a b c d) = do pokeArray (castPtr p) [a,b,c,d] data Imlib_Operation = Imlib_Op_Copy -- 0 | Imlib_Op_Add -- 1 | Imlib_Op_Subtract -- 2 | Imlib_Op_Reshade -- 3 deriving (Enum, Show, Eq) data Imlib_Text_Direction = Imlib_Text_To_Right -- 0 | Imlib_Text_To_Left -- 1 | Imlib_Text_To_Down -- 2 | Imlib_Text_To_Up -- 3 | Imlib_Text_To_Angle -- 4 deriving (Enum, Show, Eq) data Imlib_Load_Error = Imlib_Load_Error_None -- 0 | Imlib_Load_Error_File_Does_Not_Exist -- 1 | Imlib_Load_Error_File_Is_Directory -- 2 | Imlib_Load_Error_Permission_Denied_To_Read -- 3 | Imlib_Load_Error_No_Loader_For_File_Format -- 4 | Imlib_Load_Error_Path_Too_Long -- 5 | Imlib_Load_Error_Path_Component_Non_Existant -- 6 | Imlib_Load_Error_Path_Component_Not_Directory -- 7 | Imlib_Load_Error_Path_Points_Outside_Address_Space -- 8 | Imlib_Load_Error_Too_Many_Symbolic_Links -- 9 | Imlib_Load_Error_Out_Of_Memory -- 10 | Imlib_Load_Error_Out_Of_File_Descriptors -- 11 | Imlib_Load_Error_Permission_Denied_To_Write -- 12 | Imlib_Load_Error_Out_Of_Disk_Space -- 13 | Imlib_Load_Error_Unknown -- 14 deriving (Show, Enum, Eq) data Imlib_TTF_Encoding = Imlib_TTF_Encoding_ISO_8859_1 -- 0 | Imlib_TTF_Encoding_ISO_8859_2 -- 1 | Imlib_TTF_Encoding_ISO_8859_3 -- 2 | Imlib_TTF_Encoding_ISO_8859_4 -- 3 | Imlib_TTF_Encoding_ISO_8859_5 -- 4 deriving (Enum, Show, Eq) type Imlib_Progress_Function = Ptr Imlib_Image -- image -> Word8 -- percent -> Int -- update x -> Int -- update y -> Int -- update w -> Int -- update h -> IO Int -- return value (not sure what this means) foreign import ccall "wrapper" mkProgressFunction :: Imlib_Progress_Function -> IO (FunPtr Imlib_Progress_Function) color_to_bits :: Imlib_Color -> Word32 color_to_bits (Imlib_Color a r g b) = fromIntegral (b + (g `shift` 8) + (r `shift` 16) + (a `shift` 24)) color_from_bits :: Word32 -> Imlib_Color color_from_bits n = Imlib_Color a r g b where b = fromIntegral $ n `mod` 256 g = fromIntegral $ (n `shift` (-8)) `mod` 256 r = fromIntegral $ (n `shift` (-16)) `mod` 256 a = fromIntegral $ (n `shift` (-24)) `mod` 256 --typedef void (*Imlib_Data_Destructor_Function) (Imlib_Image im, void *data); type Imlib_Data_Destructor_Function = Ptr Imlib_Image -> Ptr () -> IO () foreign import ccall "wrapper" mkDestructorFunction :: Imlib_Data_Destructor_Function -> IO (FunPtr Imlib_Data_Destructor_Function) --void imlib_context_set_dither_mask(char dither_mask); foreign import ccall "static Imlib2.h" imlib_context_set_dither_mask :: Bool -> IO () context_set_dither_mask = imlib_context_set_dither_mask --void imlib_context_set_anti_alias(char anti_alias); foreign import ccall "static Imlib2.h" imlib_context_set_anti_alias :: Bool -> IO () context_set_anti_alias = imlib_context_set_anti_alias --void imlib_context_set_dither(char dither); foreign import ccall "static Imlib2.h" imlib_context_set_dither :: Bool -> IO () context_set_dither = imlib_context_set_dither --void imlib_context_set_blend(char blend); foreign import ccall "static Imlib2.h" imlib_context_set_blend :: Bool -> IO () context_set_blend = imlib_context_set_blend --void imlib_context_set_color_modifier(Imlib_Color_Modifier color_modifier); foreign import ccall "static Imlib2.h" imlib_context_set_color_modifier :: Ptr Imlib_Color_Modifier -> IO () context_set_color_modifier = imlib_context_set_color_modifier --void imlib_context_set_operation(Imlib_Operation operation); foreign import ccall "static Imlib2.h" imlib_context_set_operation :: Int -> IO () context_set_operation :: Imlib_Operation -> IO () context_set_operation op = imlib_context_set_operation (fromEnum op) --void imlib_context_set_font(Imlib_Font font); foreign import ccall "static Imlib2.h" imlib_context_set_font :: Ptr Imlib_Font -> IO () context_set_font = imlib_context_set_font --void imlib_context_set_direction(Imlib_Text_Direction direction); foreign import ccall "static Imlib2.h" imlib_context_set_direction :: Int -> IO () context_set_direction :: Imlib_Text_Direction -> IO () context_set_direction dir = imlib_context_set_direction (fromEnum dir) --void imlib_context_set_angle(double angle); foreign import ccall "static Imlib2.h" imlib_context_set_angle :: Double -> IO () context_set_angle = imlib_context_set_angle --void imlib_context_set_color(int red, int green, int blue, int alpha); foreign import ccall "static Imlib2.h" imlib_context_set_color :: Int -> Int -> Int -> Int -> IO () context_set_color = imlib_context_set_color --void imlib_context_set_color_cmya(int cyan, magenta, int yellow, int alpha); foreign import ccall "static Imlib2.h" imlib_context_set_color_cmya :: Int -> Int -> Int -> Int -> IO () context_set_color_cmya = imlib_context_set_color_cmya --void imlib_context_set_color_hsva(float hue, float saturation, float value, int alpha); foreign import ccall "static Imlib2.h" imlib_context_set_color_hsva :: Int -> Int -> Int -> Int -> IO () context_set_color_hsva = imlib_context_set_color_hsva --void imlib_context_set_color_hlsa(float hue, float lightness, float saturation, int alpha); foreign import ccall "static Imlib2.h" imlib_context_set_color_hlsa :: Int -> Int -> Int -> Int -> IO () context_set_color_hlsa = imlib_context_set_color_hlsa --void imlib_context_set_color_range(Imlib_Color_Range color_range); foreign import ccall "static Imlib2.h" imlib_context_set_color_range :: Ptr Imlib_Color_Range -> IO () context_set_color_range = imlib_context_set_color_range --void imlib_context_set_progress_function(Imlib_Progress_Function progress_function); foreign import ccall "static Imlib2.h" imlib_context_set_progress_function :: FunPtr(Imlib_Progress_Function) -> IO () context_set_progress_function f = do fn <- mkProgressFunction f imlib_context_set_progress_function fn --void imlib_context_set_progress_granularity(char progress_granularity); foreign import ccall "static Imlib2.h" imlib_context_set_progress_granularity :: Word8 -> IO () context_set_progress_granularity = imlib_context_set_progress_granularity --void imlib_context_set_filter(Imlib_Filter filter); foreign import ccall "static Imlib2.h" imlib_context_set_filter :: (Ptr Imlib_Filter) -> IO () context_set_filter = imlib_context_set_filter -- void imlib_context_set_image(Imlib_Image image); foreign import ccall "static Imlib2.h" imlib_context_set_image :: Ptr Imlib_Image -> IO () context_set_image = imlib_context_set_image -- char imlib_context_get_dither_mask(void); foreign import ccall "static Imlib2.h" imlib_context_get_dither_mask :: IO Bool context_get_dither_mask = imlib_context_get_dither_mask -- char imlib_context_get_anti_alias(void); foreign import ccall "static Imlib2.h" imlib_context_get_anti_alias :: IO Bool context_get_anti_alias = imlib_context_get_anti_alias -- char imlib_context_get_dither(void); foreign import ccall "static Imlib2.h" imlib_context_get_dither :: IO Bool context_get_dither = imlib_context_get_dither -- char imlib_context_get_blend(void); foreign import ccall "static Imlib2.h" imlib_context_get_blend :: IO Bool context_get_blend = imlib_context_get_blend -- Imlib_Color_Modifier imlib_context_get_color_modifier(void); foreign import ccall "static Imlib2.h" imlib_context_get_color_modifier :: IO (Ptr Imlib_Color_Modifier) context_get_color_modifier = imlib_context_get_color_modifier -- Imlib_Operation imlib_context_get_operation(void); foreign import ccall "static Imlib2.h" imlib_context_get_operation :: IO Int context_get_operation :: IO Imlib_Operation context_get_operation = do i <- imlib_context_get_operation return (toEnum i) -- Imlib_Font imlib_context_get_font(void); foreign import ccall "static Imlib2.h" imlib_context_get_font :: IO (Ptr Imlib_Font) context_get_font = imlib_context_get_font -- double imlib_context_get_angle(void); foreign import ccall "static Imlib2.h" imlib_context_get_angle :: IO Double context_get_angle = imlib_context_get_angle -- Imlib_Text_Direction imlib_context_get_direction(void); foreign import ccall "static Imlib2.h" imlib_context_get_direction :: IO Int context_get_direction :: IO Imlib_Text_Direction context_get_direction = do d <- imlib_context_get_direction return (toEnum d) -- void imlib_context_get_color(int *red, int *green, int *blue, int *alpha); foreign import ccall "static Imlib2.h" imlib_context_get_color :: Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () context_get_color :: IO (Int, Int, Int, Int) context_get_color = do [r,g,b,a] <- nmalloc 4 imlib_context_get_color r g b a [rr,gg,bb,aa] <- mapM peek [r,g,b,a] mapM_ free [r,g,b,a] return (rr,gg,bb,aa) -- void imlib_context_get_color_cmya(int *cyan, int *magenta, int *yellow, int *alpha); foreign import ccall "static Imlib2.h" imlib_context_get_color_cmya :: Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () context_get_color_cmya :: IO (Int, Int, Int, Int) context_get_color_cmya = do [c,m,y,a] <- nmalloc 4 imlib_context_get_color_cmya c m y a [cc,mm,yy,aa] <- mapM peek [c,m,y,a] mapM_ free [c,m,y,a] return (cc,mm,yy,aa) -- void imlib_context_get_color_hsva(float *hue, float *saturation, float *value, int *alpha); foreign import ccall "static Imlib2.h" imlib_context_get_color_hsva :: Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () context_get_color_hsva :: IO (Int, Int, Int, Int) context_get_color_hsva = do [h,s,v,a] <- nmalloc 4 imlib_context_get_color_hsva h s v a [hh,ss,vv,aa] <- mapM peek [h,s,v,a] mapM_ free [h,s,v,a] return (hh,ss,vv,aa) -- void imlib_context_get_color_hlsa(float *hue, float * lightness, float *saturation, int *alpha); foreign import ccall "static Imlib2.h" imlib_context_get_color_hlsa :: Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () context_get_color_hlsa :: IO (Int, Int, Int, Int) context_get_color_hlsa = do [h,l,s,a] <- nmalloc 4 imlib_context_get_color_hlsa h l s a [hh,ll,ss,aa] <- mapM peek [h,l,s,a] mapM_ free [h,l,s,a] return (hh,ll,ss,aa) -- Imlib_Color *imlib_context_get_imlib_color(void); foreign import ccall "static Imlib2.h" imlib_context_get_imlib_color :: IO (Ptr Imlib_Color) context_get_imlib_color :: IO Imlib_Color context_get_imlib_color = do c <- imlib_context_get_imlib_color cc <- peek c free c return cc -- Imlib_Color_Range imlib_context_get_color_range(void); foreign import ccall "static Imlib2.h" imlib_context_get_color_range :: IO (Ptr Imlib_Color_Range) context_get_color_range = imlib_context_get_color_range -- Imlib_Progress_Function imlib_context_get_progress_function(void); foreign import ccall "static Imlib2.h" imlib_context_get_progress_function :: IO (FunPtr Imlib_Progress_Function) context_get_progress_function = imlib_context_get_progress_function -- char imlib_context_get_progress_granularity(void); foreign import ccall "static Imlib2.h" imlib_context_get_progress_granularity :: IO Word8 context_get_progress_granularity = imlib_context_get_progress_granularity -- Imlib_Image imlib_context_get_image(void); foreign import ccall "static Imlib2.h" imlib_context_get_image :: IO (Ptr Imlib_Image) context_get_image = imlib_context_get_image -- Imlib_Filter imlib_context_get_filter(void); foreign import ccall "static Imlib2.h" imlib_context_get_filter :: IO (Ptr Imlib_Filter) context_get_filter = imlib_context_get_filter -- int imlib_get_cache_size(void); foreign import ccall "static Imlib2.h" imlib_get_cache_size :: IO Int get_cache_size = imlib_get_cache_size -- void imlib_set_cache_size(int bytes); foreign import ccall "static Imlib2.h" imlib_set_cache_size :: Int -> IO () set_cache_size = imlib_set_cache_size -- int imlib_get_color_usage(void); foreign import ccall "static Imlib2.h" imlib_get_color_usage :: IO Int get_color_usage = imlib_get_color_usage -- void imlib_set_color_usage(int max); foreign import ccall "static Imlib2.h" imlib_set_color_usage :: Int -> IO () set_color_usage = imlib_set_color_usage -- void imlib_flush_loaders(void); foreign import ccall "static Imlib2.h" imlib_flush_loaders :: IO () flush_loaders = imlib_flush_loaders -- Imlib_Image imlib_load_image(const char *file); foreign import ccall "static Imlib2.h" imlib_load_image :: CString -> IO (Ptr Imlib_Image) load_image str = withCString str imlib_load_image --Imlib_Image imlib_load_image_immediately(const char *file); foreign import ccall "static Imlib2.h" imlib_load_image_immediately :: CString -> IO (Ptr Imlib_Image) load_image_immediately str = withCString str imlib_load_image_immediately --Imlib_Image imlib_load_image_without_cache(const char *file); foreign import ccall "static Imlib2.h" imlib_load_image_without_cache :: CString -> IO (Ptr Imlib_Image) load_image_without_cache str = withCString str imlib_load_image_without_cache --Imlib_Image imlib_load_image_immediately_without_cache(const char *file); foreign import ccall "static Imlib2.h" imlib_load_image_immediately_without_cache :: CString -> IO (Ptr Imlib_Image) load_image_immediately_without_cache str = withCString str imlib_load_image_immediately_without_cache --Imlib_Image imlib_load_image_with_error_return(const char *file, Imlib_Load_Error *error_return); foreign import ccall "static Imlib2.h" imlib_load_image_with_error_return :: CString -> Ptr Int -> IO (Ptr Imlib_Image) load_image_with_error_return :: String -> IO (Ptr Imlib_Image, Imlib_Load_Error) load_image_with_error_return str = do pe <- malloc im <- withCString str (\s -> imlib_load_image_with_error_return s pe) e <- peek pe free pe return (im, toEnum e) --void imlib_free_image(void); foreign import ccall "static Imlib2.h" imlib_free_image :: IO () free_image = imlib_free_image --void imlib_free_image_and_decache(void); foreign import ccall "static Imlib2.h" imlib_free_image_and_decache :: IO () free_image_and_decache = imlib_free_image_and_decache --int imlib_image_get_width(void); foreign import ccall "static Imlib2.h" imlib_image_get_width :: IO Int image_get_width = imlib_image_get_width --int imlib_image_get_height(void); foreign import ccall "static Imlib2.h" imlib_image_get_height :: IO Int image_get_height = imlib_image_get_height --const char *imlib_image_get_filename(void); foreign import ccall "static Imlib2.h" imlib_image_get_filename :: IO CString image_get_filename = do b <- imlib_image_get_filename peekCString b --DATA32 *imlib_image_get_data(void); foreign import ccall "static Imlib2.h" imlib_image_get_data :: IO (Ptr Word32) image_get_data = imlib_image_get_data --DATA32 *imlib_image_get_data_for_reading_only(void); foreign import ccall "static Imlib2.h" imlib_image_get_data_for_reading_only :: IO (Ptr Word32) image_get_data_for_reading_only = imlib_image_get_data_for_reading_only --void imlib_image_put_back_data(DATA32 *data); foreign import ccall "static Imlib2.h" imlib_image_put_back_data :: Ptr Word32 -> IO () image_put_back_data = imlib_image_put_back_data -- Convenience "control structure" for working with getting and putting image data back, since you must always return the data that you get. image_with_data :: (Ptr Word32 -> IO a) -> IO a image_with_data f = do p <- image_get_data r <- f p image_put_back_data p return r with_image_bits :: (Int -> Int -> [Word32] -> [Word32]) -> IO () with_image_bits f = do w <- image_get_width h <- image_get_height p <- image_get_data arr <- peekArray (w*h) p -- turn the [Word32] into a [Imlib_Color] and pass it to the function along with the -- width and height, then poke the array with the new image returned. pokeArray p $ f w h arr image_put_back_data p -- Takes a function which gets the image width and height and image data and transforms it, -- and returns an action performing that transformation. with_image :: (Int -> Int -> [Imlib_Color] -> [Imlib_Color]) -> IO () with_image f = do w <- image_get_width h <- image_get_height p <- image_get_data arr <- peekArray (w*h) p -- turn the [Word32] into a [Imlib_Color] and pass it to the function along with the -- width and height, then poke the array with the new image returned. pokeArray p $ map color_to_bits $ f w h $ map color_from_bits arr image_put_back_data p --char imlib_image_has_alpha(void); foreign import ccall "static Imlib2.h" imlib_image_has_alpha :: IO Bool image_has_alpha = imlib_image_has_alpha --void imlib_image_set_changes_on_disk(void); foreign import ccall "static Imlib2.h" imlib_image_set_changes_on_disk :: IO () image_set_changes_on_disk = imlib_image_set_changes_on_disk --void imlib_image_get_border(Imlib_Border *border); foreign import ccall "static Imlib2.h" imlib_image_get_border :: Ptr Imlib_Border -> IO () image_get_border :: IO Imlib_Border image_get_border = do b <- malloc imlib_image_get_border b bb <- peek b free b return bb --void imlib_image_set_border(Imlib_Border *border); foreign import ccall "static Imlib2.h" imlib_image_set_border :: Ptr Imlib_Border -> IO () image_set_border :: Imlib_Border -> IO () image_set_border b = do p <- malloc poke p b imlib_image_set_border p free p --void imlib_image_set_format(const char *format); foreign import ccall "static Imlib2.h" imlib_image_set_format :: CString -> IO () image_set_format str = withCString str imlib_image_set_format --void imlib_image_set_irrelevant_format(char irrelevant); foreign import ccall "static Imlib2.h" imlib_image_set_irrelevant_format :: Bool -> IO () image_set_irrelevant_format = imlib_image_set_irrelevant_format --void imlib_image_set_irrelevant_border(char irrelevant); foreign import ccall "static Imlib2.h" imlib_image_set_irrelevant_border :: Bool -> IO () image_set_irrelevant_border = imlib_image_set_irrelevant_border --void imlib_image_set_irrelevant_alpha(char irrelevant); foreign import ccall "static Imlib2.h" imlib_image_set_irrelevant_alpha :: Bool -> IO () image_set_irrelevant_alpha = imlib_image_set_irrelevant_alpha --char *imlib_image_format(void); foreign import ccall "static Imlib2.h" imlib_image_format :: IO CString image_format :: IO String image_format = imlib_image_format >>= peekCString --void imlib_image_set_has_alpha(char has_alpha); foreign import ccall "static Imlib2.h" imlib_image_set_has_alpha :: Bool -> IO () image_set_has_alpha = imlib_image_set_has_alpha --void imlib_blend_image_onto_image(Imlib_Image source_image, char merge_alpha, int source_x, int source_y, int source_width, int source_height, int destination_x, int destination_y, int destination_width, int destination_height); foreign import ccall "static Imlib2.h" imlib_blend_image_onto_image :: Ptr Imlib_Image -> Bool -- merge alpha -> Int -- source x -> Int -- source y -> Int -- source width -> Int -- source height -> Int -- dest x -> Int -- dest y -> Int -- dest width -> Int -- dest height -> IO () blend_image_onto_image merge_alpha (sx, sy, sw, sh) (dx, dy, dw, dh) = imlib_blend_image_onto_image merge_alpha sx sy sw sh dx dy dw dh --Imlib_Image imlib_create_image(int width, int height); foreign import ccall "static Imlib2.h" imlib_create_image :: Int -> Int -> IO (Ptr Imlib_Image) create_image = imlib_create_image --Imlib_Image imlib_create_image_using_data(int width, int height, DATA32 *data); foreign import ccall "static Imlib2.h" imlib_create_image_using_data :: Int -> Int -> Ptr Word32 -> IO (Ptr Imlib_Image) create_image_using_data = imlib_create_image_using_data --Imlib_Image imlib_create_image_using_copied_data(int width, int height, DATA32 *data); foreign import ccall "static Imlib2.h" imlib_create_image_using_copied_data :: Int -> Int -> Ptr(Word32) -> IO (Ptr Imlib_Image) create_image_using_copied_data = imlib_create_image_using_copied_data create_image_using_list :: Int -> Int -> [Imlib_Color] -> IO (Ptr Imlib_Image) create_image_using_list w h xs = withArray (map color_to_bits xs) (create_image_using_copied_data w h) --Imlib_Image imlib_clone_image(void); foreign import ccall "static Imlib2.h" imlib_clone_image :: IO (Ptr Imlib_Image) clone_image = imlib_clone_image --Imlib_Image imlib_create_cropped_image(int x, int y, int width, int height); foreign import ccall "static Imlib2.h" imlib_create_cropped_image :: Int -> Int -> Int -> Int -> IO (Ptr Imlib_Image) create_cropped_image = imlib_create_cropped_image --Imlib_Image imlib_create_cropped_scaled_image(int source_x, int source_y, int source_width, int source_height, int destination_width, int destination_height); foreign import ccall "static Imlib2.h" imlib_create_cropped_scaled_image :: Int -> Int -> Int -> Int -> Int -> Int -> IO (Ptr Imlib_Image) create_cropped_scaled_image = imlib_create_cropped_scaled_image --Imlib_Updates imlib_updates_clone(Imlib_Updates updates); foreign import ccall "static Imlib2.h" imlib_updates_clone :: Ptr (Imlib_Updates) -> IO (Ptr Imlib_Updates) updates_clone = imlib_updates_clone --Imlib_Updates imlib_update_append_rect(Imlib_Updates updates, int x, int y, int w, int h); foreign import ccall "static Imlib2.h" imlib_update_append_rect :: Int -> Int -> Int -> Int -> IO (Ptr Imlib_Updates) update_append_rect = imlib_update_append_rect --Imlib_Updates imlib_updates_merge(Imlib_Updates updates, int w, int h); foreign import ccall "static Imlib2.h" imlib_updates_merge :: Int -> Int -> IO (Ptr Imlib_Updates) updates_merge = imlib_updates_merge --Imlib_Updates imlib_updates_merge_for_rendering(Imlib_Updates updates, int w, int h); foreign import ccall "static Imlib2.h" imlib_updates_merge_for_rendering :: Ptr Imlib_Updates -> Int -> Int -> IO (Ptr Imlib_Updates) updates_merge_for_rendering = imlib_updates_merge_for_rendering --void imlib_updates_free(Imlib_Updates updates); foreign import ccall "static Imlib2.h" imlib_updates_free :: Ptr Imlib_Updates -> IO () updates_free = imlib_updates_free --Imlib_Updates imlib_updates_get_next(Imlib_Updates updates); foreign import ccall "static Imlib2.h" imlib_updates_get_next :: Ptr Imlib_Updates -> IO (Ptr Imlib_Updates) updates_get_next = imlib_updates_get_next --void imlib_updates_get_coordinates(Imlib_Updates updates, int *x_return, int *y_return, int *width_return, int *height_return); foreign import ccall "static Imlib2.h" imlib_updates_get_coordinates :: Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () updates_get_coordinates :: IO (Int, Int, Int, Int) updates_get_coordinates = do [x,y,w,h] <- nmalloc 4 imlib_updates_get_coordinates x y w h [xx,yy,ww,hh] <- mapM peek [x,y,w,h] mapM_ free [x,y,w,h] return (xx,yy,ww,hh) --void imlib_updates_set_coordinates(Imlib_Updates updates, int x, int y, int width, int height); foreign import ccall "static Imlib2.h" imlib_updates_set_coordinates :: Ptr Imlib_Updates -> Int -> Int -> Int -> Int -> IO () updates_set_coordinates = imlib_updates_set_coordinates --Imlib_Updates imlib_updates_init(void); foreign import ccall "static Imlib2.h" imlib_updates_init :: IO (Ptr Imlib_Updates) updates_init = imlib_updates_init --Imlib_Updates imlib_updates_append_updates(Imlib_Updates updates, Imlib_Updates appended_updates); foreign import ccall "static Imlib2.h" imlib_updates_append_updates :: Ptr Imlib_Updates -> Ptr Imlib_Updates -> IO (Ptr Imlib_Updates) updates_append_updates = imlib_updates_append_updates --void imlib_image_flip_horizontal(void); foreign import ccall "static Imlib2.h" imlib_image_flip_horizontal :: IO () image_flip_horizontal = imlib_image_flip_horizontal --void imlib_image_flip_vertical(void); foreign import ccall "static Imlib2.h" imlib_image_flip_vertical :: IO () image_flip_vertical = imlib_image_flip_vertical --void imlib_image_flip_diagonal(void); foreign import ccall "static Imlib2.h" imlib_image_flip_diagonal :: IO () image_flip_diagonal = imlib_image_flip_diagonal --void imlib_image_orientate(int orientation); foreign import ccall "static Imlib2.h" imlib_image_orientate :: Int -> IO () image_orientate = imlib_image_orientate --void imlib_image_blur(int radius); foreign import ccall "static Imlib2.h" imlib_image_blur :: Int -> IO () image_blur = imlib_image_blur --void imlib_image_sharpen(int radius); foreign import ccall "static Imlib2.h" imlib_image_sharpen :: Int -> IO () image_sharpen = imlib_image_sharpen --void imlib_image_tile_horizontal(void); foreign import ccall "static Imlib2.h" imlib_image_tile_horizontal :: IO () image_tile_horizontal = imlib_image_tile_horizontal --void imlib_image_tile_vertical(void); foreign import ccall "static Imlib2.h" imlib_image_tile_vertical :: IO () image_tile_vertical = imlib_image_tile_vertical --void imlib_image_tile(void); foreign import ccall "static Imlib2.h" imlib_image_tile :: IO () image_tile = imlib_image_tile --Imlib_Font imlib_load_font(const char *font_name); foreign import ccall "static Imlib2.h" imlib_load_font :: CString -> IO (Ptr Imlib_Font) load_font str = withCString str imlib_load_font --void imlib_free_font(void); foreign import ccall "static Imlib2.h" imlib_free_font :: IO () free_font str = imlib_free_font --void imlib_text_draw(int x, int y, const char *text); foreign import ccall "static Imlib2.h" imlib_text_draw :: Int -> Int -> CString -> IO () text_draw x y str = withCString str (imlib_text_draw x y) --void imlib_text_draw_with_return_metrics(int x, int y, const char *text, int *width_return, int *height_return, int *horizontal_advance_return, int *vertical_advance_return); foreign import ccall "static Imlib2.h" imlib_text_draw_with_return_metrics :: Int -> Int -> CString -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () text_draw_with_return_metrics x y str = do [w,h,ah,av] <- nmalloc 4 withCString str (\s -> imlib_text_draw_with_return_metrics x y s w h ah av) [rw,rh,rah,rav] <- mapM peek [w,h,ah,av] mapM_ free [w,h,ah,av] return (rw,rh,rah,rav) --void imlib_get_text_size(const char *text, int *width_return, int *height_return); foreign import ccall "static Imlib2.h" imlib_get_text_size :: CString -> Ptr Int -> Ptr Int -> IO () get_text_size str = do [w,h] <- nmalloc 4 withCString str (\s -> imlib_get_text_size s w h) [rw,rh] <- mapM peek [w,h] mapM_ free [w,h] return (rw,rh) --void imlib_get_text_advance(const char *text, int *horizontal_advance_return, int *vertical_advance_return); foreign import ccall "static Imlib2.h" imlib_get_text_advance :: CString -> Ptr Int -> Ptr Int -> IO () get_text_advance str = do [h,v] <- nmalloc 4 withCString str (\s -> imlib_get_text_advance s h v) [rh,rv] <- mapM peek [h,v] mapM_ free [h,v] return (rh,rv) --int imlib_get_text_inset(const char *text); foreign import ccall "static Imlib2.h" imlib_get_text_inset :: CString -> IO Int get_text_inset str = withCString str imlib_get_text_inset --void imlib_add_path_to_font_path(const char *path); foreign import ccall "static Imlib2.h" imlib_add_path_to_font_path :: CString -> IO () add_path_to_font_path str = withCString str imlib_add_path_to_font_path --void imlib_remove_path_from_font_path(const char *path); foreign import ccall "static Imlib2.h" imlib_remove_path_from_font_path :: CString -> IO () remove_path_from_font_path str = withCString str imlib_remove_path_from_font_path --char **imlib_list_font_path(int *number_return); foreign import ccall "static Imlib2.h" imlib_list_font_path :: Ptr Int -> IO (Ptr CString) list_font_path = do pn <- malloc pxs <- imlib_list_font_path pn n <- peek pn free pn xs <- peekArray n pxs xs <- mapM peekCString xs return xs --int imlib_text_get_index_and_location(const char *text, int x, int y, int *char_x_return, int *char_y_return, int *char_width_return, int *char_height_return); foreign import ccall "static Imlib2.h" imlib_text_get_index_and_location :: CString -> Int -> Int -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO Int text_get_index_and_location str x y = do [xp,yp,wp,hp] <- nmalloc 4 n <- withCString str (\s -> imlib_text_get_index_and_location s x y xp yp wp hp) [xr,yr,wr,hr] <- mapM peek [xp,yp,wp,hp] mapM_ free [xp,yp,wp,hp] return (n,xr,yr,wr,hr) --void imlib_text_get_location_at_index(const char *text, int index, int *char_x_return, int *char_y_return, int *char_width_return, int *char_height_return); foreign import ccall "static Imlib2.h" imlib_text_get_location_at_index :: CString -> Int -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () text_get_location_at_index str k = do [xp,yp,wp,hp] <- nmalloc 4 withCString str (\s -> imlib_text_get_location_at_index s k xp yp wp hp) [xr,yr,wr,hr] <- mapM peek [xp,yp,wp,hp] mapM_ free [xp,yp,wp,hp] return (xr,yr,wr,hr) --char **imlib_list_fonts(int *number_return); --void imlib_free_font_list(char **font_list, int number); foreign import ccall "static Imlib2.h" imlib_list_fonts :: Ptr Int -> IO (Ptr CString) foreign import ccall "static Imlib2.h" imlib_free_font_list :: Ptr (CString) -> Int -> IO () list_fonts = do pn <- malloc pxs <- imlib_list_fonts pn n <- peek pn free pn xs <- peekArray n pxs xs <- mapM peekCString xs imlib_free_font_list pxs n return xs --int imlib_get_font_cache_size(void); foreign import ccall "static Imlib2.h" imlib_get_font_cache_size :: IO Int get_font_cache_size = imlib_get_font_cache_size --void imlib_set_font_cache_size(int bytes); foreign import ccall "static Imlib2.h" imlib_set_font_cache_size :: Int -> IO () set_font_cache_size = imlib_set_font_cache_size --void imlib_flush_font_cache(void); foreign import ccall "static Imlib2.h" imlib_flush_font_cache :: IO () flush_font_cache = imlib_flush_font_cache --int imlib_get_font_ascent(void); foreign import ccall "static Imlib2.h" imlib_get_font_ascent :: IO Int get_font_ascent = imlib_get_font_ascent --int imlib_get_font_descent(void); foreign import ccall "static Imlib2.h" imlib_get_font_descent :: IO Int get_font_descent = imlib_get_font_descent --int imlib_get_maximum_font_ascent(void); foreign import ccall "static Imlib2.h" imlib_get_maximum_font_ascent :: IO Int get_maximum_font_ascent = imlib_get_maximum_font_ascent --int imlib_get_maximum_font_descent(void); foreign import ccall "static Imlib2.h" imlib_get_maximum_font_descent :: IO Int get_maximum_font_descent = imlib_get_maximum_font_descent --Imlib_Color_Modifier imlib_create_color_modifier(void); foreign import ccall "static Imlib2.h" imlib_create_color_modifier :: IO (Ptr Imlib_Color_Modifier) create_color_modifier = imlib_create_color_modifier --void imlib_free_color_modifier(void); foreign import ccall "static Imlib2.h" imlib_free_color_modifier :: IO () free_color_modifier = imlib_free_color_modifier --void imlib_modify_color_modifier_gamma(double gamma_value); foreign import ccall "static Imlib2.h" imlib_modify_color_modifier_gamma :: Double -> IO () modify_color_modifier_gamma = imlib_modify_color_modifier_gamma --void imlib_modify_color_modifier_brightness(double brightness_value); foreign import ccall "static Imlib2.h" imlib_modify_color_modifier_brightness :: Double -> IO () modify_color_modifier_brightness = imlib_modify_color_modifier_brightness --void imlib_modify_color_modifier_contrast(double contrast_value); foreign import ccall "static Imlib2.h" imlib_modify_color_modifier_contrast :: Double -> IO () modify_color_modifier_contrast = imlib_modify_color_modifier_contrast --void imlib_set_color_modifier_tables(DATA8 *red_table, DATA8 *green_table, DATA8 *blue_table, DATA8 *alpha_table); foreign import ccall "static Imlib2.h" imlib_set_color_modifier_tables :: (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> IO () set_color_modifier_tables r g b a = do withArray rs (\ra -> withArray gs (\ga -> withArray bs (\ba -> withArray as (\aa -> imlib_set_color_modifier_tables ra ga ba aa)))) where padLeft n a xs | l > n = take n xs | l < n = (replicate (n-l) a) ++ xs | l == n = xs where l = length xs rs = padLeft 256 0 r gs = padLeft 256 0 g bs = padLeft 256 0 b as = padLeft 256 0 a --void imlib_get_color_modifier_tables(DATA8 *red_table, DATA8 *green_table, DATA8 *blue_table, DATA8 *alpha_table); foreign import ccall "static Imlib2.h" imlib_get_color_modifier_tables :: (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> (Ptr Word8) -> IO () get_color_modifier_tables = do [ra,ga,ba,aa] <- nmallocArray 4 256 imlib_get_color_modifier_tables ra ga ba aa [rs,gs,bs,as] <- mapM (peekArray 256) [ra,ga,ba,aa] mapM free [ra,ga,ba,aa] return (rs,gs,bs,as) --void imlib_reset_color_modifier(void); foreign import ccall "static Imlib2.h" imlib_reset_color_modifier :: IO () reset_color_modifier = imlib_reset_color_modifier --void imlib_apply_color_modifier(void); foreign import ccall "static Imlib2.h" imlib_apply_color_modifier :: IO () apply_color_modifier = imlib_apply_color_modifier --void imlib_apply_color_modifier_to_rectangle(int x, int y, int width, int height); foreign import ccall "static Imlib2.h" imlib_apply_color_modifier_to_rectangle :: Int -> Int -> Int -> Int -> IO () apply_color_modifier_to_rectangle = imlib_apply_color_modifier_to_rectangle --Imlib_Updates imlib_image_draw_line(int x1, int y1, int x2, int y2, char make_updates); foreign import ccall "static Imlib2.h" imlib_image_draw_line :: Int -> Int -> Int -> Int -> Bool -> IO (Ptr Imlib_Updates) image_draw_line = imlib_image_draw_line --void imlib_image_draw_rectangle(int x, int y, int width, int height); foreign import ccall "static Imlib2.h" imlib_image_draw_rectangle :: Int -> Int -> Int -> Int -> IO () image_draw_rectangle = imlib_image_draw_rectangle --void imlib_image_fill_rectangle(int x, int y, int width, int height); foreign import ccall "static Imlib2.h" imlib_image_fill_rectangle :: Int -> Int -> Int -> Int -> IO () image_fill_rectangle = imlib_image_fill_rectangle --void imlib_image_copy_alpha_to_image(Imlib_Image image_source, int x, int y); foreign import ccall "static Imlib2.h" imlib_image_copy_alpha_to_image :: Ptr Imlib_Image -> Int -> Int -> IO () image_copy_alpha_to_image = imlib_image_copy_alpha_to_image --void imlib_image_copy_alpha_rectangle_to_image(Imlib_Image image_source, int x, int y, int width, int height, int destination_x, int destination_y); foreign import ccall "static Imlib2.h" imlib_image_copy_alpha_rectangle_to_image :: Ptr Imlib_Image -> Int -> Int -> Int -> Int -> Int -> Int -> IO () image_copy_alpha_rectangle_to_image = imlib_image_copy_alpha_rectangle_to_image --void imlib_image_scroll_rect(int x, int y, int width, int height, int delta_x, int delta_y); foreign import ccall "static Imlib2.h" imlib_image_scroll_rect :: Int -> Int -> Int -> Int -> Int -> Int -> IO () image_scroll_rect = imlib_image_scroll_rect --void imlib_image_copy_rect(int x, int y, int width, int height, int new_x, int new_y); foreign import ccall "static Imlib2.h" imlib_image_copy_rect :: Int -> Int -> Int -> Int -> Int -> Int -> IO () image_copy_rect = imlib_image_copy_rect --Imlib_Color_Range imlib_create_color_range(void); foreign import ccall "static Imlib2.h" imlib_create_color_range :: IO (Ptr Imlib_Color_Range) create_color_range = imlib_create_color_range --void imlib_free_color_range(void); foreign import ccall "static Imlib2.h" imlib_free_color_range :: IO () free_color_range = imlib_free_color_range --void imlib_add_color_to_color_range(int distance_away); foreign import ccall "static Imlib2.h" imlib_add_color_to_color_range :: IO () add_color_to_color_range = imlib_add_color_to_color_range --void imlib_image_fill_color_range_rectangle(int x, int y, int width, int height, double angle); foreign import ccall "static Imlib2.h" imlib_image_fill_color_range_rectangle :: Int -> Int -> Int -> Int -> IO () image_fill_color_range_rectangle = imlib_image_fill_color_range_rectangle --void imlib_image_fill_hsva_color_range_rectangle(int x, int y, int width, int height, double angle); foreign import ccall "static Imlib2.h" imlib_image_fill_hsva_color_range_rectangle :: Int -> Int -> Int -> Int -> IO () image_fill_hsva_color_range_rectangle = imlib_image_fill_hsva_color_range_rectangle --void imlib_image_query_pixel(int x, int y, Imlib_Color *color_return); foreign import ccall "static Imlib2.h" imlib_image_query_pixel :: Int -> Int -> Ptr Imlib_Color -> IO () image_query_pixel x y = do c <- malloc imlib_image_query_pixel x y c r <- peek c free c return r --void imlib_image_query_pixel_cmya(int x, int y, int *cyan, int *magenta, int *yellow, int *alpha); foreign import ccall "static Imlib2.h" imlib_image_query_pixel_cmya :: Int -> Int -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () image_query_pixel_cmya :: Int -> Int -> IO (Int, Int, Int, Int) image_query_pixel_cmya cx cy = do [c,m,y,a] <- nmalloc 4 imlib_image_query_pixel_cmya cx cy c m y a [cc,mm,yy,aa] <- mapM peek [c,m,y,a] mapM_ free [c,m,y,a] return (cc,mm,yy,aa) --void imlib_image_query_pixel_hsva(int x, int y, float *hue, float *saturation, float *value, int *alpha); foreign import ccall "static Imlib2.h" imlib_image_query_pixel_hsva :: Int -> Int -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () image_query_pixel_hsva :: Int -> Int -> IO (Int, Int, Int, Int) image_query_pixel_hsva cx cy = do [h,s,v,a] <- nmalloc 4 imlib_image_query_pixel_cmya cx cy h s v a [hh,ss,vv,aa] <- mapM peek [h,s,v,a] mapM_ free [h,s,v,a] return (hh,ss,vv,aa) --void imlib_image_query_pixel_hlsa(int x, int y, float *hue, float *lightness, float *saturation, int *alpha); foreign import ccall "static Imlib2.h" imlib_image_query_pixel_hlsa :: Int -> Int -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () image_query_pixel_hlsa :: Int -> Int -> IO (Int, Int, Int, Int) image_query_pixel_hlsa cx cy = do [h,l,s,a] <- nmalloc 4 imlib_image_query_pixel_hlsa cx cy h l s a [hh,ll,ss,aa] <- mapM peek [h,l,s,a] mapM_ free [h,l,s,a] return (hh,ll,ss,aa) --void imlib_image_attach_data_value(const char *key, void *data, int value, Imlib_Data_Destructor_Function destructor_function); foreign import ccall "static Imlib2.h" imlib_image_attach_data_value :: CString -> Ptr () -> Int -> FunPtr Imlib_Data_Destructor_Function -> IO () image_attach_data_value key d v dest = do df <- mkDestructorFunction dest withCString key (\k -> imlib_image_attach_data_value k d v df) --void *imlib_image_get_attached_data(const char *key); foreign import ccall "static Imlib2.h" imlib_image_get_attached_data :: CString -> IO (Ptr ()) image_get_attached_data key = withCString key imlib_image_get_attached_data --int imlib_image_get_attached_value(const char *key); foreign import ccall "static Imlib2.h" imlib_image_get_attached_value :: CString -> IO Int image_get_attached_value key = withCString key imlib_image_get_attached_value --void imlib_image_remove_attached_data_value(const char *key); foreign import ccall "static Imlib2.h" imlib_image_remove_attached_data_value :: CString -> IO () image_remove_attached_data_value key = withCString key imlib_image_remove_attached_data_value --void imlib_image_remove_and_free_attached_data_value(const char *key); foreign import ccall "static Imlib2.h" imlib_image_remove_and_free_attached_data_value :: CString -> IO () image_remove_and_free_attached_data_value key = withCString key imlib_image_remove_and_free_attached_data_value --void imlib_save_image(const char *filename); foreign import ccall "static Imlib2.h" imlib_save_image :: CString -> IO () save_image str = withCString str imlib_save_image --void imlib_save_image_with_error_return(const char *filename, Imlib_Load_Error *error_return); foreign import ccall "static Imlib2.h" imlib_save_image_with_error_return :: CString -> Ptr Int -> IO () save_image_with_error_return :: String -> IO Imlib_Load_Error save_image_with_error_return str = do pe <- malloc im <- withCString str (\s -> imlib_save_image_with_error_return s pe) e <- peek pe free pe return (toEnum e) --Imlib_Image imlib_create_rotated_image(double angle); foreign import ccall "static Imlib2.h" imlib_create_rotated_image :: Double -> IO (Ptr Imlib_Image) create_rotated_image = imlib_create_rotated_image --void imlib_blend_image_onto_image_at_angle(Imlib_Image source_image, char merge_alpha, int source_x, int source_y, int source_width, int source_height, int destination_x, int destination_y, int angle_x, int angle_y); foreign import ccall "static Imlib2.h" imlib_blend_image_onto_image_at_angle :: Ptr(Imlib_Image) -> Bool -- merge alpha -> Int -- source x -> Int -- source y -> Int -- source width -> Int -- source height -> Int -- dest x -> Int -- dest y -> Int -- angle x -> Int -- angle y -> IO () blend_image_onto_image_at_angle = imlib_blend_image_onto_image_at_angle --void imlib_blend_image_onto_image_skewed(Imlib_Image source_image, char merge_alpha, int source_x, int source_y, int source_width, int source_height, int destination_x, int destination_y, int h_angle_x, int h_angle_y, int v_angle_x, int v_angle_y); foreign import ccall "static Imlib2.h" imlib_blend_image_onto_image_skewed :: Ptr(Imlib_Image) -> Bool -- merge alpha -> Int -- source x -> Int -- source y -> Int -- source width -> Int -- source height -> Int -- dest x -> Int -- dest y -> Int -- h angle x -> Int -- h angle y -> Int -- v angle x -> Int -- v angle y -> IO () blend_image_onto_image_skewed = imlib_blend_image_onto_image_skewed --void imlib_context_set_cliprect(int x, int y, int w, int h); foreign import ccall "static Imlib2.h" imlib_context_set_cliprect :: Int -> Int -> Int -> Int -> IO () context_set_cliprect = imlib_context_set_cliprect --int imlib_clip_line(int x0, int y0, int x1, int y1, int xmin, int xmax, int ymin, int ymax, int *clip_x0, int *clip_y0, int *clip_x1, int *clip_y1); foreign import ccall "static Imlib2.h" imlib_clip_line :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO Int clip_line x0 y0 x1 y1 xmin xmax ymin ymax = do [cx0,cy0,cx1,cy1] <- nmalloc 4 n <- imlib_clip_line x0 y0 x1 y1 xmin xmax ymin ymax cx0 cy0 cx1 cy1 [rcx0,rcy0,rcx1,rcy1] <- mapM peek [cx0,cy0,cx1,cy1] mapM_ free [cx0,cy0,cx1,cy1] return (n,rcx0,rcy0,rcx1,rcy1) --void imlib_polygon_new(void); foreign import ccall "static Imlib2.h" imlib_polygon_new :: IO () polygon_new = imlib_polygon_new --void imlib_polygon_free(ImlibPolygon poly); foreign import ccall "static Imlib2.h" imlib_polygon_free :: Ptr Imlib_Polygon -> IO () polygon_free = imlib_polygon_free --void imlib_polygon_add_point(ImlibPolygon poly, int x, int y); foreign import ccall "static Imlib2.h" imlib_polygon_add_point :: Ptr Imlib_Polygon -> Int -> Int -> IO () polygon_add_point = imlib_polygon_add_point --void imlib_image_draw_polygon(ImlibPolygon poly, unsigned char closed); foreign import ccall "static Imlib2.h" imlib_image_draw_polygon :: Ptr Imlib_Polygon -> Bool -> IO () image_draw_polygon = imlib_image_draw_polygon --void imlib_image_fill_polygon(ImlibPolygon poly); foreign import ccall "static Imlib2.h" imlib_image_fill_polygon :: Ptr Imlib_Polygon -> IO () image_fill_polygon = imlib_image_fill_polygon --void imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2, int *py2); foreign import ccall "static Imlib2.h" imlib_polygon_get_bounds :: Ptr Imlib_Polygon -> Ptr Int -> Ptr Int -> Ptr Int -> Ptr Int -> IO () polygon_get_bounds poly = do [x1,y1,x2,y2] <- nmalloc 4 imlib_polygon_get_bounds poly x1 y1 x2 y2 [rx1,ry1,rx2,ry2] <- mapM peek [x1,y1,x2,y2] mapM_ free [x1,y1,x2,y2] return (rx1,ry1,rx2,ry2) --unsigned char imlib_polygon_contains_point(ImlibPolygon poly, int x, int y); foreign import ccall "static Imlib2.h" imlib_polygon_contains_point :: Ptr Imlib_Polygon -> Int -> Int -> IO Bool polygon_contains_point = imlib_polygon_contains_point --void imlib_image_draw_ellipse(int xc, int yc, int a, int b); foreign import ccall "static Imlib2.h" imlib_image_draw_ellipse :: Int -> Int -> Int -> Int -> IO () image_draw_ellipse = imlib_image_draw_ellipse --void imlib_image_fill_ellipse(int xc, int yc, int a, int b); foreign import ccall "static Imlib2.h" imlib_image_fill_ellipse :: Int -> Int -> Int -> Int -> IO () image_fill_ellipse = imlib_image_fill_ellipse --void imlib_image_filter(void); foreign import ccall "static Imlib2.h" imlib_image_filter :: IO () image_filter = imlib_image_filter --Imlib_Filter imlib_create_filter(int initsize); foreign import ccall "static Imlib2.h" imlib_create_filter :: Int -> IO (Ptr Imlib_Filter) create_filter = imlib_create_filter --void imlib_free_filter(void); foreign import ccall "static Imlib2.h" imlib_free_filter :: IO () free_filter = imlib_free_filter --void imlib_filter_set(int xoff, int yoff, int a, int r, int g, int b); foreign import ccall "static Imlib2.h" imlib_filter_set :: Int -> Int -> Int -> Int -> Int -> Int -> IO () filter_set = imlib_filter_set --void imlib_filter_set_alpha(int xoff, int yoff, int a, int r, int g, int b); foreign import ccall "static Imlib2.h" imlib_filter_set_alpha :: Int -> Int -> Int -> Int -> Int -> Int -> IO () filter_set_alpha = imlib_filter_set_alpha --void imlib_filter_set_red(int xoff, int yoff, int a, int r, int g, int b); foreign import ccall "static Imlib2.h" imlib_filter_set_red :: Int -> Int -> Int -> Int -> Int -> Int -> IO () filter_set_red = imlib_filter_set_red --void imlib_filter_set_green(int xoff, int yoff, int a, int r, int g, int b); foreign import ccall "static Imlib2.h" imlib_filter_set_green :: Int -> Int -> Int -> Int -> Int -> Int -> IO () filter_set_green = imlib_filter_set_green --void imlib_filter_set_blue(int xoff, int yoff, int a, int r, int g, int b); foreign import ccall "static Imlib2.h" imlib_filter_set_blue :: Int -> Int -> Int -> Int -> Int -> Int -> IO () filter_set_blue = imlib_filter_set_blue --void imlib_filter_constants(int a, int r, int g, int b); foreign import ccall "static Imlib2.h" imlib_filter_constants :: Int -> Int -> Int -> Int -> IO () filter_constants = imlib_filter_constants --void imlib_filter_divisors(int a, int r, int g, int b); foreign import ccall "static Imlib2.h" imlib_filter_divisors :: Int -> Int -> Int -> Int -> IO () filter_divisors = imlib_filter_divisors