Name

Pixbuf —

Pixbufs are bitmap images in memory.

Synopsis

data
        Colorspace
type
        ImageType
data
        InlineImage
data
        InterpType
data
        PixbufError
pixbufCopy:: Pixbuf -> IO Pixbuf
pixbufNew:: Colorspace -> Bool -> Int -> Int -> Int -> IO Pixbuf
pixbufNewFromFile:: FilePath -> IO (Either (PixbufError,String) Pixbuf)
pixbufNewFromInline:: Ptr InlineImage -> IO Pixbuf
pixbufNewFromXPMData:: [String] -> IO Pixbuf
pixbufGetFormats:: [ImageType]
pixbufAddAlpha:: Pixbuf -> Maybe (Word8,Word8,Word8) -> IO Pixbuf
pixbufComposite:: Pixbuf -> Pixbuf -> Int -> Int -> Int -> Int -> Double -> Double -> Double -> Double -> InterpType -> Word8 -> IO ()
pixbufCopyArea:: Pixbuf -> Int -> Int -> Int -> Int -> Pixbuf -> Int -> Int -> IO ()
pixbufFill:: Pixbuf -> Word8 -> Word8 -> Word8 -> Word8 -> IO ()
pixbufGetBitsPerSample:: Pixbuf -> IO Int
pixbufGetColorSpace:: Pixbuf -> IO Colorspace
pixbufGetFromDrawable:: DrawableClass d => d -> Rectangle -> IO (Maybe Pixbuf)
pixbufGetHasAlpha:: Pixbuf -> IO Bool
pixbufGetHeight:: Pixbuf -> IO Int
pixbufGetNChannels:: Pixbuf -> IO Int
pixbufGetOption:: Pixbuf -> String -> IO (Maybe String)
pixbufGetRowstride:: Pixbuf -> IO Int
pixbufGetWidth:: Pixbuf -> IO Int
pixbufNewSubpixbuf:: Pixbuf -> Int -> Int -> Int -> Int -> IO Pixbuf
pixbufSave:: Pixbuf -> FilePath -> ImageType -> [(String,String)] -> IO (Maybe (PixbufError,String))
pixbufScale:: Pixbuf -> Pixbuf -> Int -> Int -> Int -> Int -> Double -> Double -> Double -> Double -> InterpType -> IO ()
pixbufScaleSimple:: Pixbuf -> Int -> Int -> InterpType -> IO Pixbuf

Introduction

A Pixbuf is used to represent images. It contains information about the image's pixel data, its color space, bits per sample, width and height, and the rowstride or number of bytes between rows.

This module contains functions to scale and crop Pixbufs and to scale and crop a Pixbuf and compose the result with an existing image.

Todo

if there is a portable way of modifying external arrays in Haskell do: gdk_pixbuf_get_pixels, gdk_pixbuf_new_from_data, everything in Inline data,

if anybody writes an image manipulation program, do the checker board functions: gdk_pixbuf_composite_color_simple and gdk_pixbuf_composite_color. Moreover, do: pixbuf_saturate_and_pixelate

the animation functions

pixbuf loader

module interface

rendering function for Bitmaps and Pixmaps when the latter are added

Datatypes

data Colorspace

Enumerate all supported color spaces.

data Colorspace =ColorspaceRgb

Only RGB is supported right now.

type ImageType

ImageTypeString

A string representing an image file format.

data InlineImage

A dymmy type for inline picture data.

data InlineImage =InlineImage

This dummy type is used to declare pointers to image data that is embedded in the executable. See pixbufNewFromInline for an example. A dymmy type for inline picture data.

This dummy type is used to declare pointers to image data that is embedded in the executable. See pixbufNewFromInline for an example.

data InterpType

How an image is scaled.

data InterpType =InterpBilinear
| InterpHyper
| InterpNearest
| InterpTiles

data PixbufError

Error codes for loading image files.

data PixbufError =PixbufErrorBadOption
| PixbufErrorCorruptImage
| PixbufErrorFailed
| PixbufErrorInsufficientMemory
| PixbufErrorUnknownType
| PixbufErrorUnsupportedOperation

Constructors

pixbufCopy

Create a deep copy of an image.

pixbufCopy:: Pixbuf:: IO Pixbuf
pb

pixbufNew

Create a new image in memory.

pixbufNew:: Colorspace:: Bool:: Int:: Int:: Int:: IO Pixbuf
colorspacehasAlphabitsPerSamplewidthheight

Creates a new pixbuf structure and allocates a buffer for it. Note that the buffer is not cleared initially.

pixbufNewFromFile

Load an image synchonously.

pixbufNewFromFile:: FilePath:: IO (Either (PixbufError,String) Pixbuf)
fname

Use this function to load only small images as this call will block.

The function will return Left (err,msg) where err is the error code and msg is a human readable description of the error. If an error occurs which is not captured by any of those in PixbufError, an exception is thrown.

pixbufNewFromInline

Create a new image from a static pointer.

pixbufNewFromInline:: Ptr InlineImage:: IO Pixbuf
iPtr

Like pixbufNewFromXPMData, this function allows to include images in the final binary program. The method used by this function uses a binary representation and therefore needs less space in the final executable. Save the image you want to include as png and run

  echo #include "my_image.h" > my_image.c
  gdk-pixbuf-csource --raw --extern --name=my_image myimage.png >> my_image.c
  

on it. Write a header file my_image.h containing

  #include <gdk/gdk.h>
  extern guint8 my_image[];
  

and save it in the current directory. The created file can be compiled with

  cc -c my_image.c `pkg-config --cflags gdk-2.0`
  

into an object file which must be linked into your Haskell program by specifying my_image.o and "-#include my_image.h" on the command line of GHC. Within you application you delcare a pointer to this image:

  foreign label "my_image" myImage :: Ptr InlineImage
  

Calling pixbufNewFromInline with this pointer will return the image in the object file. Creating the C file with the --raw flag will result in a non-compressed image in the object file. The advantage is that the picture will not be copied when this function is called.

pixbufNewFromXPMData

Create a new image from a String.

pixbufNewFromXPMData:: [String]:: IO Pixbuf
s

Creates a new pixbuf from a string description.

Methods

pixbufAddAlpha

Add an opacity layer to the Pixbuf.

pixbufAddAlpha:: Pixbuf:: Maybe (Word8,Word8,Word8):: IO Pixbuf
pb(Just (r, g, b))
pbNothing

This function returns a copy of the given src Pixbuf, leaving src unmodified. The new Pixbuf has an alpha (opacity) channel which defaults to 255 (fully opaque pixels) unless src already had an alpha channel in which case the original values are kept. Passing in a color triple (r,g,b) makes all pixels that have this color fully transparent (opacity of 0). The pixel color itself remains unchanged during this substitution.

pixbufComposite

Blend a scaled image part onto another image.

pixbufComposite:: Pixbuf:: Pixbuf:: Int:: Int:: Int:: Int:: Double:: Double:: Double:: Double:: InterpType:: Word8:: IO ()
srcdestdestXdestYdestWidthdestHeightoffsetXoffsetYscaleXscaleYinterpalpha

This function is similar to pixbufScale but allows the original image to "shine through". The alpha value determines how opaque the source image is. Passing 0 is equivalent to not calling this function at all, passing 255 has the same effect as calling pixbufScale.

pixbufCopyArea

Copy a rectangular portion into another Pixbuf.

pixbufCopyArea:: Pixbuf:: Int:: Int:: Int:: Int:: Pixbuf:: Int:: Int:: IO ()
srcsrcXsrcYsrcWidthsrcHeightdestdestXdestY

The source Pixbuf remains unchanged. Converion between different formats is done automatically.

pixbufFill

Fills a Pixbuf with a color.

pixbufFill:: Pixbuf:: Word8:: Word8:: Word8:: Word8:: IO ()
pbredgreenbluealpha

The passed-in color is a quadruple consisting of the red, green, blue and alpha component of the pixel. If the Pixbuf does not have an alpha channel, the alpha value is ignored.

pixbufGetBitsPerSample

Queries the number of bits for each color.

pixbufGetBitsPerSample:: Pixbuf:: IO Int
pb

Each pixel is has a number of cannels for each pixel, each channel has this many bits.

pixbufGetColorSpace

Queries the color space of a pixbuf.

pixbufGetColorSpace:: Pixbuf:: IO Colorspace
pb

pixbufGetFromDrawable

Take a screenshot of a Drawable.

pixbufGetFromDrawable:: d:: Rectangle:: IO (Maybe Pixbuf)
d(Rectangle x y width height)

This function creates a Pixbuf and fills it with the image currently in the Drawable (which might be invalid if the window is obscured or minimized). Note that this transfers data from the server to the client on X Windows.

This function will return a Pixbuf with no alpha channel containing the part of the Drawable specified by the rectangle. The function will return Nothing if the window is not currently visible.

pixbufGetHasAlpha

Query if the image has an alpha channel.

pixbufGetHasAlpha:: Pixbuf:: IO Bool
pb

The alpha channel determines the opaqueness of the pixel.

pixbufGetHeight

Queries the height of this image.

pixbufGetHeight:: Pixbuf:: IO Int
pb

pixbufGetNChannels

Queries the number of colors for each pixel.

pixbufGetNChannels:: Pixbuf:: IO Int
pb

pixbufGetOption

Returns an attribut of an image.

pixbufGetOption:: Pixbuf:: String:: IO (Maybe String)
pbkey

Looks up if some information was stored under the key when this image was saved.

pixbufGetRowstride

Queries the rowstride of this image.

pixbufGetRowstride:: Pixbuf:: IO Int
pb

Queries the rowstride of a pixbuf, which is the number of bytes between rows. Use this value to caculate the offset to a certain row.

pixbufGetWidth

Queries the width of this image.

pixbufGetWidth:: Pixbuf:: IO Int
pb

pixbufNewSubpixbuf

Create a restricted view of an image.

pixbufNewSubpixbuf:: Pixbuf:: Int:: Int:: Int:: Int:: IO Pixbuf
pbsrcXsrcYheightwidth

This function returns a Pixbuf object which shares the image of the original one but only shows a part of it. Modifying either buffer will affect the other.

This function throw an exception if the requested bounds are invalid.

pixbufSave

Save an image to disk.

pixbufSave:: Pixbuf:: FilePath:: ImageType:: [(String,String)]:: IO (Maybe (PixbufError,String))
pbfnameiTypeoptions

The function takes a list of key - value pairs to specify either how an image is saved or to actually save this additional data with the image. JPEG images can be saved with a "quality" parameter; its value should be in the range [0,100]. Text chunks can be attached to PNG images by specifying parameters of the form "tEXt::key", where key is an ASCII string of length 1-79. The values are Unicode strings.

The function returns Nothing if writing was successful. Otherwise the error code and a description is returned or, if the error is not captured by one of the error codes in PixbufError, an exception is thrown.

pixbufScale

Copy a scaled image part to another image.

pixbufScale:: Pixbuf:: Pixbuf:: Int:: Int:: Int:: Int:: Double:: Double:: Double:: Double:: InterpType:: IO ()
srcdestdestXdestYdestWidthdestHeightoffsetXoffsetYscaleXscaleYinterp

This function is the generic version of pixbufScaleSimple. It scales src by scaleX and scaleY and translate the image by offsetX and offsetY. Whatever is in the intersection with the rectangle destX, destY, destWidth, destHeight will be rendered into dest.

The rectangle in the destination is simply overwritten. Use pixbufComposite if you need to blend the source image onto the destination.

pixbufScaleSimple

Scale an image.

pixbufScaleSimple:: Pixbuf:: Int:: Int:: InterpType:: IO Pixbuf
pbwidthheightinterp

Creates a new GdkPixbuf containing a copy of src scaled to the given measures. Leaves src unaffected.

interp affects the quality and speed of the scaling function.

Constants

pixbufGetFormats

A list of valid image file formats.

pixbufGetFormats