LibMB  1.12
Macros | Typedefs | Enumerations | Functions
MBPixbuf - Simple image manipulation tools

mbpixbuf contains simple image manipulation and composition functions for client side images. More...

Macros

#define mb_pixbuf_img_set_pixel(i, x, y, r, g, b)
 
#define mb_pixbuf_img_set_pixel_alpha(i, x, y, a)
 
#define mb_pixbuf_img_get_width(image)   (image)->width
 
#define mb_pixbuf_img_get_height(image)   (image)->height
 
#define mb_pixbuf_get_depth(pb)   (pb)->depth
 
#define mb_pixbuf_img_has_alpha(image)   (image)->has_alpha
 

Typedefs

typedef struct MBPixbuf MBPixbuf
 
typedef struct MBPixbufImage MBPixbufImage
 

Enumerations

enum  MBPixbufTransform
 

Functions

MBPixbufmb_pixbuf_new (Display *display, int screen)
 Constructs a new MBPixbuf instance. More...
 
MBPixbufmb_pixbuf_new_extended (Display *dpy, int scr, Visual *vis, int depth)
 Constructs a new MBPixbuf instance with non default depth and visual. More...
 
void mb_pixbuf_destroy (MBPixbuf *pixbuf)
 Destroys a new MBPixbuf instance. More...
 
unsigned long mb_pixbuf_lookup_x_pixel (MBPixbuf *pixbuf, int r, int g, int b, int a)
 Get the X pixel representation for a given color. More...
 
MBPixbufImagemb_pixbuf_img_new (MBPixbuf *pb, int width, int height)
 DEPRECIATED. More...
 
MBPixbufImagemb_pixbuf_img_rgba_new (MBPixbuf *pixbuf, int width, int height)
 Constructs a new blank mbpixbuf image with an alpha channel. More...
 
MBPixbufImagemb_pixbuf_img_rgb_new (MBPixbuf *pixbuf, int width, int height)
 Constructs a new blank mbpixbuf image without an alpha channel. More...
 
MBPixbufImagemb_pixbuf_img_new_from_drawable (MBPixbuf *pixbuf, Drawable drawable, Drawable mask, int source_x, int source_y, int source_w, int source_h)
 Depreicated. More...
 
MBPixbufImagemb_pixbuf_img_new_from_x_drawable (MBPixbuf *pixbuf, Drawable drawable, Drawable mask, int source_x, int source_y, int source_w, int source_h, Bool want_alpha)
 Constructs a new blank mbpixbuf image with/without an alpha channel. More...
 
MBPixbufImagemb_pixbuf_img_new_from_file (MBPixbuf *pixbuf, const char *filename)
 Creates an mbpixbuf image from a file on disk. More...
 
MBPixbufImagemb_pixbuf_img_new_from_data (MBPixbuf *pixbuf, const unsigned char *data, int width, int height, Bool has_alpha)
 Creates an mbpixbuf image from arbituary supplied rgb(a) data. More...
 
MBPixbufImagemb_pixbuf_img_new_from_int_data (MBPixbuf *pixbuf, const int *data, int width, int height)
 Creates an mbpixbuf image from arbituary supplied INT ARGB data. More...
 
MBPixbufImagemb_pixbuf_img_new_from_long_data (MBPixbuf *pixbuf, const unsigned long *data, int width, int height)
 Creates an mbpixbuf image from arbituary supplied long ARGB data. More...
 
void mb_pixbuf_img_free (MBPixbuf *pixbuf, MBPixbufImage *image)
 Frees up a mbpixbuf image. More...
 
void mb_pixbuf_img_render_to_drawable (MBPixbuf *pixbuf, MBPixbufImage *image, Drawable drw, int drw_x, int drw_y)
 Renders a mbpixbuf image to an X Drawable. More...
 
void mb_pixbuf_img_render_to_drawable_with_gc (MBPixbuf *pixbuf, MBPixbufImage *image, Drawable drw, int drw_x, int drw_y, GC gc)
 Renders a mbpixbuf image to an X Drawable with a specified. More...
 
void mb_pixbuf_img_render_to_mask (MBPixbuf *pixbuf, MBPixbufImage *image, Drawable mask, int mask_x, int mask_y)
 Renders alpha component mbpixbuf image to an X Bitmap. More...
 
MBPixbufImagemb_pixbuf_img_clone (MBPixbuf *pixbuf, MBPixbufImage *image)
 Clones a exisiting mbpixbuf image. More...
 
void mb_pixbuf_img_fill (MBPixbuf *pixbuf, MBPixbufImage *image, int r, int g, int b, int a)
 Fills an image with specified color / alpha level. More...
 
void mb_pixbuf_img_plot_pixel (MBPixbuf *pixbuf, MBPixbufImage *image, int x, int y, unsigned char r, unsigned char g, unsigned char b)
 Plots a pixel on specified image. More...
 
void mb_pixbuf_img_get_pixel (MBPixbuf *pixbuf, MBPixbufImage *image, int x, int y, unsigned char *r, unsigned char *g, unsigned char *b, unsigned char *a)
 Gets the component values for a specified pixel. More...
 
unsigned char * mb_pixbuf_img_data (MBPixbuf *pixbuf, MBPixbufImage *image)
 Gets rgb(a) internal data representation of an image. More...
 
void mb_pixbuf_img_plot_pixel_with_alpha (MBPixbuf *pixbuf, MBPixbufImage *image, int x, int y, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 Plots a pixel on specified image with alpha channel value. More...
 
void mb_pixbuf_img_copy (MBPixbuf *pixbuf, MBPixbufImage *dest, MBPixbufImage *src, int sx, int sy, int sw, int sh, int dx, int dy)
 Copys an specified area of an image to another. More...
 
void mb_pixbuf_img_copy_composite (MBPixbuf *pixbuf, MBPixbufImage *dest, MBPixbufImage *src, int sx, int sy, int sw, int sh, int dx, int dy)
 Alpha composites an specified area of an image with another. More...
 
void mb_pixbuf_img_copy_composite_with_alpha (MBPixbuf *pixbuf, MBPixbufImage *dest, MBPixbufImage *src, int sx, int sy, int sw, int sh, int dx, int dy, int overall_alpha)
 Like mb_pixbuf_img_copy_composite but sets an overall alpha value. More...
 
void mb_pixbuf_img_composite (MBPixbuf *pb, MBPixbufImage *dest, MBPixbufImage *src, int dx, int dy)
 DEPRECATED. More...
 
MBPixbufImagemb_pixbuf_img_scale (MBPixbuf *pixbuf, MBPixbufImage *image, int new_width, int new_height)
 Scales an image arbitually. More...
 
MBPixbufImagemb_pixbuf_img_transform (MBPixbuf *pixbuf, MBPixbufImage *image, MBPixbufTransform transform)
 Performs a basic transform on an image. More...
 

Detailed Description

mbpixbuf contains simple image manipulation and composition functions for client side images.

Example: Simple example to load an image and display it on root window.

 #include <libmb/mb.h>
 int 
 main(int argc, char **argv)
 {
   Display       *dpy;
   Window         win_root;
   XEvent         xevent;
   MBPixbufImage *img, *img_scaled;
   MBPixbuf      *pb;
   if (argc < 2) 
     { fprintf(stderr, "usage: %s image file\\n", argv[0]); exit(1); }
   dpy = XOpenDisplay(NULL);
   pb = mb_pixbuf_new(dpy, DefaultScreen(dpy));
   img = mb_pixbuf_img_new_from_file(pb, argv[1]);
   if (!img) { fprintf(stderr, "image load failed\\n"); exit(1); }
   img_scaled = mb_pixbuf_img_scale(pb, img, 
                                    DisplayWidth(dpy), DisplayHeight(dpy));
   if (!img_scaled) { fprintf(stderr, "image scale failed\\n"); exit(1); }
   mb_pixbuf_img_free(pb, img);
   mb_pixbuf_img_render_to_drawable(pb, img_scaled,
                                    RootWindow(dpy, DefaultScreen(dpy))
                             0, 0);
   for (;;) 
      XNextEvent(dpy, &xevent);
   exit(0);
 }

Notes: if the enviromental varible 'MBPIXBUF_NO_SHM' is set, the MIT-SHM extension will not be used.

Macro Definition Documentation

◆ mb_pixbuf_get_depth

#define mb_pixbuf_get_depth (   pb)    (pb)->depth

returns pixbuf instance depth

Definition at line 216 of file mbpixbuf.h.

◆ mb_pixbuf_img_get_height

#define mb_pixbuf_img_get_height (   image)    (image)->height

returns image height

Definition at line 209 of file mbpixbuf.h.

◆ mb_pixbuf_img_get_width

#define mb_pixbuf_img_get_width (   image)    (image)->width

returns image width

Definition at line 202 of file mbpixbuf.h.

◆ mb_pixbuf_img_has_alpha

#define mb_pixbuf_img_has_alpha (   image)    (image)->has_alpha

Returns True if image has an alpha channel.

Definition at line 223 of file mbpixbuf.h.

◆ mb_pixbuf_img_set_pixel

#define mb_pixbuf_img_set_pixel (   i,
  x,
  y,
  r,
  g,
 
)
Value:
{ \
(i)->rgba[(((y)*(i)->width*4)+((x)*4))] = r; \
(i)->rgba[(((y)*(i)->width*4)+((x)*4))+1] = g; \
(i)->rgba[(((y)*(i)->width*4)+((x)*4))+2] = b; \
(i)->rgba[(((y)*(i)->width*4)+((x)*4))+3] = 0; \
}

DEPRICIATED. Use mb_pixbuf_img_plot_pixel instead.

Definition at line 179 of file mbpixbuf.h.

◆ mb_pixbuf_img_set_pixel_alpha

#define mb_pixbuf_img_set_pixel_alpha (   i,
  x,
  y,
 
)
Value:
{ \
if ((i)->has_alpha) (i)->rgba[(((y)*(i)->width*(i->internal_bytespp+1))+((x)*(i->internal_bytespp+1)))+i->internal_bytespp] = a; \
}

sets a pixels alpha value

Definition at line 191 of file mbpixbuf.h.

Typedef Documentation

◆ MBPixbuf

MBPixbuf

Opaque structure used for all operations.

◆ MBPixbufImage

MBPixbufImage

Type for representing an mbpixbuf image. Its not recommended you touch this directly.

Enumeration Type Documentation

◆ MBPixbufTransform

enumerated types for mb_pixbuf_img_transform

Definition at line 116 of file mbpixbuf.h.

Function Documentation

◆ mb_pixbuf_destroy()

void mb_pixbuf_destroy ( MBPixbuf pixbuf)

Destroys a new MBPixbuf instance.

Parameters
pixbufMBPixbuf object

◆ mb_pixbuf_img_clone()

MBPixbufImage* mb_pixbuf_img_clone ( MBPixbuf pixbuf,
MBPixbufImage image 
)

Clones a exisiting mbpixbuf image.

Parameters
pixbufmbpixbuf object
imageimage to clone
Returns
a new cloned image

◆ mb_pixbuf_img_composite()

void mb_pixbuf_img_composite ( MBPixbuf pb,
MBPixbufImage dest,
MBPixbufImage src,
int  dx,
int  dy 
)

DEPRECATED.

Use mb_pixbuf_img_copy_composite instead.

◆ mb_pixbuf_img_copy()

void mb_pixbuf_img_copy ( MBPixbuf pixbuf,
MBPixbufImage dest,
MBPixbufImage src,
int  sx,
int  sy,
int  sw,
int  sh,
int  dx,
int  dy 
)

Copys an specified area of an image to another.

No Alpha composition is performed.

Parameters
pixbufmbpixbuf object
destdestination image
srcsource image
sxsource area X co-ord
sysource area Y co-ord
swsource area width.
shsource area height.
dxdestination image X co-ord.
dydestination image Y co-ord.

◆ mb_pixbuf_img_copy_composite()

void mb_pixbuf_img_copy_composite ( MBPixbuf pixbuf,
MBPixbufImage dest,
MBPixbufImage src,
int  sx,
int  sy,
int  sw,
int  sh,
int  dx,
int  dy 
)

Alpha composites an specified area of an image with another.

Parameters
pixbufmbpixbuf object
destdestination image
srcsource image
sxsource area X co-ord
sysource area Y co-ord
swsource area width.
shsource area height.
dxdestination image X co-ord.
dydestination image Y co-ord.

◆ mb_pixbuf_img_copy_composite_with_alpha()

void mb_pixbuf_img_copy_composite_with_alpha ( MBPixbuf pixbuf,
MBPixbufImage dest,
MBPixbufImage src,
int  sx,
int  sy,
int  sw,
int  sh,
int  dx,
int  dy,
int  overall_alpha 
)

Like mb_pixbuf_img_copy_composite but sets an overall alpha value.

Parameters
pixbufmbpixbuf object
destdestination image
srcsource image
sxsource area X co-ord
sysource area Y co-ord
swsource area width.
shsource area height.
dxdestination image X co-ord.
dydestination image Y co-ord.
overall_alphaThe overall alpha value to set after composition.

◆ mb_pixbuf_img_data()

unsigned char* mb_pixbuf_img_data ( MBPixbuf pixbuf,
MBPixbufImage image 
)

Gets rgb(a) internal data representation of an image.

Parameters
pixbufmbpixbuf object
imagedestination image
Returns
rgb(a) data

◆ mb_pixbuf_img_fill()

void mb_pixbuf_img_fill ( MBPixbuf pixbuf,
MBPixbufImage image,
int  r,
int  g,
int  b,
int  a 
)

Fills an image with specified color / alpha level.

Parameters
pixbufmbpixbuf object
imageimage to fill.
rred component of color
ggreen component of color
bblue component of color
aalpha component

◆ mb_pixbuf_img_free()

void mb_pixbuf_img_free ( MBPixbuf pixbuf,
MBPixbufImage image 
)

Frees up a mbpixbuf image.

Parameters
pixbufmbpixbuf object
imageimage to free

◆ mb_pixbuf_img_get_pixel()

void mb_pixbuf_img_get_pixel ( MBPixbuf pixbuf,
MBPixbufImage image,
int  x,
int  y,
unsigned char *  r,
unsigned char *  g,
unsigned char *  b,
unsigned char *  a 
)

Gets the component values for a specified pixel.

Parameters
pixbufmbpixbuf object
imagedestination image
xX co-ord on destination image
yY co-ord on destination image
rred component of color
ggreen component of color
bblue component of color
aalpha component of pixel

◆ mb_pixbuf_img_new()

MBPixbufImage* mb_pixbuf_img_new ( MBPixbuf pb,
int  width,
int  height 
)

DEPRECIATED.

Use mb_pixbuf_img_rgb_new, mb_pixbuf_img_rgba_new instead.

◆ mb_pixbuf_img_new_from_data()

MBPixbufImage* mb_pixbuf_img_new_from_data ( MBPixbuf pixbuf,
const unsigned char *  data,
int  width,
int  height,
Bool  has_alpha 
)

Creates an mbpixbuf image from arbituary supplied rgb(a) data.

Parameters
pixbufmbpixbuf object
datargb(a) data
widthimage width
heightimage height
has_alphaTrue if data has alpha component
Returns
a MBPixbufImage object, NULL on faliure

◆ mb_pixbuf_img_new_from_drawable()

MBPixbufImage* mb_pixbuf_img_new_from_drawable ( MBPixbuf pixbuf,
Drawable  drawable,
Drawable  mask,
int  source_x,
int  source_y,
int  source_w,
int  source_h 
)

Depreicated.

use mb_pixbuf_img_new_from_x_drawable instead.

◆ mb_pixbuf_img_new_from_file()

MBPixbufImage* mb_pixbuf_img_new_from_file ( MBPixbuf pixbuf,
const char *  filename 
)

Creates an mbpixbuf image from a file on disk.

Supports PNG, JPEGS and XPMS.

Parameters
pixbufmbpixbuf object
filenamefull filename of image to be loaded
Returns
a MBPixbufImage object, NULL on faliure

◆ mb_pixbuf_img_new_from_int_data()

MBPixbufImage* mb_pixbuf_img_new_from_int_data ( MBPixbuf pixbuf,
const int *  data,
int  width,
int  height 
)

Creates an mbpixbuf image from arbituary supplied INT ARGB data.

Parameters
pixbufmbpixbuf object
dataargb data
widthimage width
heightimage height
Returns
a MBPixbufImage object, NULL on faliure

◆ mb_pixbuf_img_new_from_long_data()

MBPixbufImage* mb_pixbuf_img_new_from_long_data ( MBPixbuf pixbuf,
const unsigned long *  data,
int  width,
int  height 
)

Creates an mbpixbuf image from arbituary supplied long ARGB data.

Useful for example to parse _NET_WM_ICON image data, which XLib kindly returns in long arrays instead of int arrays.

Parameters
pixbufmbpixbuf object
dataargb data
widthimage width
heightimage height
Returns
a MBPixbufImage object, NULL on faliure

◆ mb_pixbuf_img_new_from_x_drawable()

MBPixbufImage* mb_pixbuf_img_new_from_x_drawable ( MBPixbuf pixbuf,
Drawable  drawable,
Drawable  mask,
int  source_x,
int  source_y,
int  source_w,
int  source_h,
Bool  want_alpha 
)

Constructs a new blank mbpixbuf image with/without an alpha channel.

Parameters
pixbufmbpixbuf object
drawablean X drawable ( window or pixmap )
maskset to none if alpha channel not required
source_xx co-ord of X drawable
source_yy co-ord of X drawable
source_wwidth of X drawable
source_hheight of X drawable
want_alphaforce created image to have an ( empty ) alpha channel even if no mask is supplied.
Returns
a MBPixbufImage object, NULL on faliure

◆ mb_pixbuf_img_plot_pixel()

void mb_pixbuf_img_plot_pixel ( MBPixbuf pixbuf,
MBPixbufImage image,
int  x,
int  y,
unsigned char  r,
unsigned char  g,
unsigned char  b 
)

Plots a pixel on specified image.

Note: on a RGBA image the alpha channel is left as-is.

Parameters
pixbufmbpixbuf object
imagedestination image
xX co-ord on destination image
yY co-ord on destination image
rred component of color
ggreen component of color
bblue component of color

◆ mb_pixbuf_img_plot_pixel_with_alpha()

void mb_pixbuf_img_plot_pixel_with_alpha ( MBPixbuf pixbuf,
MBPixbufImage image,
int  x,
int  y,
unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)

Plots a pixel on specified image with alpha channel value.

Parameters
pixbufmbpixbuf object
imagedestination image
xX co-ord on destination image
yY co-ord on destination image
rred component of color
ggreen component of color
bblue component of color
aalpha component

◆ mb_pixbuf_img_render_to_drawable()

void mb_pixbuf_img_render_to_drawable ( MBPixbuf pixbuf,
MBPixbufImage image,
Drawable  drw,
int  drw_x,
int  drw_y 
)

Renders a mbpixbuf image to an X Drawable.

Parameters
pixbufmbpixbuf object
imagembpixbuf image to render
drwX11 drawable ( window or pixmap ) to render roo.
drw_xX co-ord on drawable to render too.
drw_yY co-ord on drawable to render too.

◆ mb_pixbuf_img_render_to_drawable_with_gc()

void mb_pixbuf_img_render_to_drawable_with_gc ( MBPixbuf pixbuf,
MBPixbufImage image,
Drawable  drw,
int  drw_x,
int  drw_y,
GC  gc 
)

Renders a mbpixbuf image to an X Drawable with a specified.

X Graphics Context ( GC ).

Parameters
pixbufmbpixbuf object
imagembpixbuf image to render
drwX11 drawable ( window or pixmap ) to render roo.
drw_xX co-ord on drawable to render too.
drw_yY co-ord on drawable to render too.
gcX11 GC to use on drawable.

◆ mb_pixbuf_img_render_to_mask()

void mb_pixbuf_img_render_to_mask ( MBPixbuf pixbuf,
MBPixbufImage image,
Drawable  mask,
int  mask_x,
int  mask_y 
)

Renders alpha component mbpixbuf image to an X Bitmap.

Parameters
pixbufmbpixbuf object
imagembpixbuf image to render
maskX11 bitmap.
mask_xX co-ord on drawable to render too.
mask_yY co-ord on drawable to render too.

◆ mb_pixbuf_img_rgb_new()

MBPixbufImage* mb_pixbuf_img_rgb_new ( MBPixbuf pixbuf,
int  width,
int  height 
)

Constructs a new blank mbpixbuf image without an alpha channel.

Parameters
pixbufmbpixbuf object
widthwidth in pixels of new image
heightheight in pixels of new image
Returns
a MBPixbufImage object

◆ mb_pixbuf_img_rgba_new()

MBPixbufImage* mb_pixbuf_img_rgba_new ( MBPixbuf pixbuf,
int  width,
int  height 
)

Constructs a new blank mbpixbuf image with an alpha channel.

Parameters
pixbufmbpixbuf object
widthwidth in pixels of new image
heightheight in pixels of new image
Returns
a MBPixbufImage object

◆ mb_pixbuf_img_scale()

MBPixbufImage* mb_pixbuf_img_scale ( MBPixbuf pixbuf,
MBPixbufImage image,
int  new_width,
int  new_height 
)

Scales an image arbitually.

Parameters
pixbufmbpixbuf object
imagembpixbuf image to scale
new_widthnew image width
new_heightnew image height
Returns
a new scaled image

◆ mb_pixbuf_img_transform()

MBPixbufImage* mb_pixbuf_img_transform ( MBPixbuf pixbuf,
MBPixbufImage image,
MBPixbufTransform  transform 
)

Performs a basic transform on an image.

Parameters
pixbufmbpixbuf object
imagembpixbuf image to scale
transformthe type of transform to perform
Returns
a new transformed image

◆ mb_pixbuf_lookup_x_pixel()

unsigned long mb_pixbuf_lookup_x_pixel ( MBPixbuf pixbuf,
int  r,
int  g,
int  b,
int  a 
)

Get the X pixel representation for a given color.

Parameters
pixbufmbpixbuf object
rred component of color
ggreen component of color
bblue component of color
aalpha component
Returns
x pixel value

◆ mb_pixbuf_new()

MBPixbuf* mb_pixbuf_new ( Display *  display,
int  screen 
)

Constructs a new MBPixbuf instance.

Parameters
display
screen
Returns
a MBPixbuf object

◆ mb_pixbuf_new_extended()

MBPixbuf* mb_pixbuf_new_extended ( Display *  dpy,
int  scr,
Visual *  vis,
int  depth 
)

Constructs a new MBPixbuf instance with non default depth and visual.

Parameters
dpyX display
scrX Screen
visX Visual to use
depthDepth to use
Returns
a MBPixbuf object