mbpixbuf.h
#ifndef _HAVE_MBPIXBUF_H
#define _HAVE_MBPIXBUF_H
/* libmb
* Copyright (C) 2002 Matthew Allum
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <libmb/mbconfig.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#ifdef USE_PNG
#include <png.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
/* XXX if have_shm */
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <X11/extensions/XShm.h>
#include <X11/Xmd.h>
#ifdef USE_JPG
#include "jpeglib.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
MBPIXBUF_TRANS_ROTATE_90,
MBPIXBUF_TRANS_ROTATE_180,
MBPIXBUF_TRANS_ROTATE_270,
MBPIXBUF_TRANS_FLIP_VERT,
MBPIXBUF_TRANS_FLIP_HORIZ
} MBPixbufTransform;
typedef struct _mb_pixbuf_col {
int r, g, b;
unsigned long pixel;
} MBPixbufColor;
typedef struct MBPixbuf
{
Display *dpy;
int scr;
Visual *vis;
Window root;
int depth;
Colormap root_cmap;
int byte_order;
int num_of_cols;
GC gc;
MBPixbufColor *palette;
Bool have_shm;
int internal_bytespp;
} MBPixbuf;
typedef struct MBPixbufImage
{
int width;
int height;
unsigned char *rgba;
int has_alpha;
XImage *ximg;
int internal_bytespp;
} MBPixbufImage;
/* macros */
#define mb_pixbuf_img_set_pixel(i, x, y, r, g, b) { \
(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; \
}
#define mb_pixbuf_img_set_pixel_alpha(i, x, y, a) { \
if ((i)->has_alpha) (i)->rgba[(((y)*(i)->width*(i->internal_bytespp+1))+((x)*(i->internal_bytespp+1)))+i->internal_bytespp] = 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
MBPixbuf*
mb_pixbuf_new (Display *display,
int screen);
MBPixbuf *
mb_pixbuf_new_extended(Display *dpy,
int scr,
Visual *vis,
int depth);
void
mb_pixbuf_destroy(MBPixbuf *pixbuf);
unsigned long
mb_pixbuf_lookup_x_pixel(MBPixbuf *pixbuf, int r, int g, int b, int a);
MBPixbufImage*
mb_pixbuf_img_new (MBPixbuf *pb,
int width,
int height);
MBPixbufImage *
mb_pixbuf_img_rgba_new(MBPixbuf *pixbuf,
int width,
int height);
MBPixbufImage *
mb_pixbuf_img_rgb_new (MBPixbuf *pixbuf,
int width,
int height);
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);
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);
MBPixbufImage *
mb_pixbuf_img_new_from_file (MBPixbuf *pixbuf,
const char *filename);
MBPixbufImage *
mb_pixbuf_img_new_from_data(MBPixbuf *pixbuf,
const unsigned char *data,
int width,
int height,
Bool has_alpha);
MBPixbufImage *
mb_pixbuf_img_new_from_int_data(MBPixbuf *pixbuf,
const int *data,
int width,
int height);
MBPixbufImage *
mb_pixbuf_img_new_from_long_data(MBPixbuf *pixbuf,
const unsigned long *data,
int width,
int height);
void
mb_pixbuf_img_free (MBPixbuf *pixbuf,
MBPixbufImage *image);
void mb_pixbuf_img_render_to_drawable (MBPixbuf *pixbuf,
MBPixbufImage *image,
Drawable drw,
int drw_x,
int drw_y);
void
mb_pixbuf_img_render_to_drawable_with_gc(MBPixbuf *pixbuf,
MBPixbufImage *image,
Drawable drw,
int drw_x,
int drw_y,
GC gc);
void mb_pixbuf_img_render_to_mask (MBPixbuf *pixbuf,
MBPixbufImage *image,
Drawable mask,
int mask_x,
int mask_y);
MBPixbufImage *mb_pixbuf_img_clone (MBPixbuf *pixbuf,
MBPixbufImage *image);
void
mb_pixbuf_img_fill(MBPixbuf *pixbuf,
MBPixbufImage *image,
int r,
int g,
int b,
int a);
void
mb_pixbuf_img_plot_pixel (MBPixbuf *pixbuf,
MBPixbufImage *image,
int x,
int y,
unsigned char r,
unsigned char g,
unsigned char b);
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
);
unsigned char *
mb_pixbuf_img_data (MBPixbuf *pixbuf,
MBPixbufImage *image);
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);
void mb_pixbuf_img_copy (MBPixbuf *pixbuf,
MBPixbufImage *dest,
MBPixbufImage *src,
int sx,
int sy,
int sw,
int sh,
int dx,
int dy);
void mb_pixbuf_img_copy_composite (MBPixbuf *pixbuf,
MBPixbufImage *dest,
MBPixbufImage *src,
int sx,
int sy,
int sw,
int sh,
int dx,
int dy);
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 );
void mb_pixbuf_img_composite (MBPixbuf *pb,
MBPixbufImage *dest,
MBPixbufImage *src,
int dx,
int dy);
MBPixbufImage *mb_pixbuf_img_scale (MBPixbuf *pixbuf,
MBPixbufImage *image,
int new_width,
int new_height);
MBPixbufImage *mb_pixbuf_img_scale_down (MBPixbuf *pixbuf,
MBPixbufImage *image,
int new_width,
int new_height);
MBPixbufImage *mb_pixbuf_img_scale_up (MBPixbuf *pixbuf,
MBPixbufImage *image,
int new_width,
int new_height);
MBPixbufImage *
mb_pixbuf_img_transform (MBPixbuf *pixbuf,
MBPixbufImage *image,
MBPixbufTransform transform);
#ifdef __cplusplus
}
#endif
#endif
mb_pixbuf_img_new
MBPixbufImage * mb_pixbuf_img_new(MBPixbuf *pb, int width, int height)
DEPRECIATED.
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.
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.
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.
mb_pixbuf_img_clone
MBPixbufImage * mb_pixbuf_img_clone(MBPixbuf *pixbuf, MBPixbufImage *image)
Clones a exisiting mbpixbuf image.
mb_pixbuf_img_free
void mb_pixbuf_img_free(MBPixbuf *pixbuf, MBPixbufImage *image)
Frees up a mbpixbuf image.
mb_pixbuf_img_scale
MBPixbufImage * mb_pixbuf_img_scale(MBPixbuf *pixbuf, MBPixbufImage *image, int new_width, int new_height)
Scales an image arbitually.
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.
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.
mb_pixbuf_img_composite
void mb_pixbuf_img_composite(MBPixbuf *pb, MBPixbufImage *dest, MBPixbufImage *src, int dx, int dy)
DEPRECATED.
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.
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.
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.
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.
mb_pixbuf_destroy
void mb_pixbuf_destroy(MBPixbuf *pixbuf)
Destroys a new MBPixbuf instance.
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.
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.
mb_pixbuf_img_transform
MBPixbufImage * mb_pixbuf_img_transform(MBPixbuf *pixbuf, MBPixbufImage *image, MBPixbufTransform transform)
Performs a basic transform on an image.
mb_pixbuf_img_data
unsigned char * mb_pixbuf_img_data(MBPixbuf *pixbuf, MBPixbufImage *image)
Gets rgb(a) internal data representation of an image.
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.
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.
mb_pixbuf_new
MBPixbuf * mb_pixbuf_new(Display *display, int screen)
Constructs a new MBPixbuf instance.
MBPixbufTransform
MBPixbufTransform
enumerated types for mb_pixbuf_img_transform
Definition mbpixbuf.h:117
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.
MBPixbufImage
struct MBPixbufImage MBPixbufImage
Type for representing an mbpixbuf 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.
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.
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.
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.
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.
MBPixbuf
struct MBPixbuf MBPixbuf
Opaque structure used for all operations.
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.