LibMB  1.9
mbpixbuf.h
1 #ifndef _HAVE_MBPIXBUF_H
2 #define _HAVE_MBPIXBUF_H
3 
4 /* libmb
5  * Copyright (C) 2002 Matthew Allum
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
23 #include "libmb/mbconfig.h"
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <signal.h>
30 
31 #ifdef USE_PNG
32 #include <png.h>
33 #endif
34 
35 #include <X11/Xlib.h>
36 #include <X11/Xutil.h>
37 #include <X11/Xatom.h>
38 
39 /* XXX if have_shm */
40 
41 #include <sys/ipc.h>
42 #include <sys/shm.h>
43 #include <sys/time.h>
44 #include <X11/extensions/XShm.h>
45 #include <X11/Xmd.h>
46 
47 #ifdef USE_JPG
48 #include "jpeglib.h"
49 #endif
50 
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
116 typedef enum
117 {
118  MBPIXBUF_TRANS_ROTATE_90,
119  MBPIXBUF_TRANS_ROTATE_180,
120  MBPIXBUF_TRANS_ROTATE_270,
121  MBPIXBUF_TRANS_FLIP_VERT,
122  MBPIXBUF_TRANS_FLIP_HORIZ
124 
125 
126 typedef struct _mb_pixbuf_col {
127  int r, g, b;
128  unsigned long pixel;
129 } MBPixbufColor;
130 
136 typedef struct MBPixbuf
137 {
138  Display *dpy;
139  int scr;
140  Visual *vis;
141  Window root;
142  int depth;
143  Colormap root_cmap;
144  int byte_order;
145  int num_of_cols;
146  GC gc;
147  MBPixbufColor *palette;
148  Bool have_shm;
149 
150  int internal_bytespp;
151 
152 } MBPixbuf;
153 
160 typedef struct MBPixbufImage
161 {
162  int width;
163  int height;
164  unsigned char *rgba;
165  int has_alpha;
166  XImage *ximg;
168  int internal_bytespp;
169 
170 } MBPixbufImage;
171 
172 /* macros */
173 
179 #define mb_pixbuf_img_set_pixel(i, x, y, r, g, b) { \
180  (i)->rgba[(((y)*(i)->width*4)+((x)*4))] = r; \
181  (i)->rgba[(((y)*(i)->width*4)+((x)*4))+1] = g; \
182  (i)->rgba[(((y)*(i)->width*4)+((x)*4))+2] = b; \
183  (i)->rgba[(((y)*(i)->width*4)+((x)*4))+3] = 0; \
184 }
185 
191 #define mb_pixbuf_img_set_pixel_alpha(i, x, y, a) { \
192  if ((i)->has_alpha) (i)->rgba[(((y)*(i)->width*(i->internal_bytespp+1))+((x)*(i->internal_bytespp+1)))+i->internal_bytespp] = a; \
193 }
194 
195 
196 
202 #define mb_pixbuf_img_get_width(image) (image)->width
203 
209 #define mb_pixbuf_img_get_height(image) (image)->height
210 
216 #define mb_pixbuf_get_depth(pb) (pb)->depth
217 
223 #define mb_pixbuf_img_has_alpha(image) (image)->has_alpha
224 
232 MBPixbuf*
233 mb_pixbuf_new (Display *display,
234  int screen);
235 
236 
246 MBPixbuf *
247 mb_pixbuf_new_extended(Display *dpy,
248  int scr,
249  Visual *vis,
250  int depth);
251 
257 void
258 mb_pixbuf_destroy(MBPixbuf *pixbuf);
259 
271 unsigned long
272 mb_pixbuf_lookup_x_pixel(MBPixbuf *pixbuf, int r, int g, int b, int a);
273 
274 
281  int width,
282  int height);
283 
294  int width,
295  int height);
296 
307  int width,
308  int height);
309 
315  Drawable drawable,
316  Drawable mask,
317  int source_x,
318  int source_y,
319  int source_w,
320  int source_h);
321 
338  Drawable drawable,
339  Drawable mask,
340  int source_x,
341  int source_y,
342  int source_w,
343  int source_h,
344  Bool want_alpha);
345 
346 
357  const char *filename);
358 
371  const unsigned char *data,
372  int width,
373  int height,
374  Bool has_alpha);
375 
376 
389  const int *data,
390  int width,
391  int height);
392 
399 void
401  MBPixbufImage *image);
402 
413  MBPixbufImage *image,
414  Drawable drw,
415  int drw_x,
416  int drw_y);
417 
429 void
431  MBPixbufImage *image,
432  Drawable drw,
433  int drw_x,
434  int drw_y,
435  GC gc);
436 
437 
448  MBPixbufImage *image,
449  Drawable mask,
450  int mask_x,
451  int mask_y);
452 
461  MBPixbufImage *image);
462 
473 void
475  MBPixbufImage *image,
476  int r,
477  int g,
478  int b,
479  int a);
480 
493 void
495  MBPixbufImage *image,
496  int x,
497  int y,
498  unsigned char r,
499  unsigned char g,
500  unsigned char b);
501 
502 
515 void
517  MBPixbufImage *image,
518  int x,
519  int y,
520  unsigned char *r,
521  unsigned char *g,
522  unsigned char *b,
523  unsigned char *a
524  );
525 
533 unsigned char *
535  MBPixbufImage *image);
536 
537 
538 
551 void
553  MBPixbufImage *image,
554  int x,
555  int y,
556  unsigned char r,
557  unsigned char g,
558  unsigned char b,
559  unsigned char a);
560 
575 void mb_pixbuf_img_copy (MBPixbuf *pixbuf,
576  MBPixbufImage *dest,
577  MBPixbufImage *src,
578  int sx,
579  int sy,
580  int sw,
581  int sh,
582  int dx,
583  int dy);
584 
585 
600  MBPixbufImage *dest,
601  MBPixbufImage *src,
602  int sx,
603  int sy,
604  int sw,
605  int sh,
606  int dx,
607  int dy);
608 
624  MBPixbufImage *dest,
625  MBPixbufImage *src,
626  int sx, int sy,
627  int sw, int sh,
628  int dx, int dy,
629  int overall_alpha );
630 
636  MBPixbufImage *dest,
637  MBPixbufImage *src,
638  int dx,
639  int dy);
640 
651  MBPixbufImage *image,
652  int new_width,
653  int new_height);
654 
655 
656 MBPixbufImage *mb_pixbuf_img_scale_down (MBPixbuf *pixbuf,
657  MBPixbufImage *image,
658  int new_width,
659  int new_height);
660 
661 
662 MBPixbufImage *mb_pixbuf_img_scale_up (MBPixbuf *pixbuf,
663  MBPixbufImage *image,
664  int new_width,
665  int new_height);
666 
677  MBPixbufImage *image,
678  MBPixbufTransform transform);
679 
680 
683 #ifdef __cplusplus
684 }
685 #endif
686 
687 
688 #endif
689 
690 
691 
MBPixbufTransform
enumerated types for mb_pixbuf_img_transform
Definition: mbpixbuf.h:116
struct MBPixbufImage MBPixbufImage
Type for representing an mbpixbuf image.
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.
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.
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.
unsigned char * mb_pixbuf_img_data(MBPixbuf *pixbuf, MBPixbufImage *image)
Gets rgb(a) internal data representation of an image.
MBPixbufImage * mb_pixbuf_img_new(MBPixbuf *pb, int width, int height)
DEPRECIATED.
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.
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.
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.
MBPixbufImage * mb_pixbuf_img_transform(MBPixbuf *pixbuf, MBPixbufImage *image, MBPixbufTransform transform)
Performs a basic transform on an image.
MBPixbufImage * mb_pixbuf_img_clone(MBPixbuf *pixbuf, MBPixbufImage *image)
Clones a exisiting mbpixbuf 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)
Plots a pixel on specified image with alpha channel value.
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.
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.
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.
MBPixbuf * mb_pixbuf_new(Display *display, int screen)
Constructs a new MBPixbuf instance.
MBPixbufImage * mb_pixbuf_img_new_from_file(MBPixbuf *pixbuf, const char *filename)
Creates an mbpixbuf image from a file on disk.
void mb_pixbuf_img_free(MBPixbuf *pixbuf, MBPixbufImage *image)
Frees up a mbpixbuf image.
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.
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.
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.
MBPixbufImage * mb_pixbuf_img_rgb_new(MBPixbuf *pixbuf, int width, int height)
Constructs a new blank mbpixbuf image without an alpha channel.
struct MBPixbuf MBPixbuf
Opaque structure used for all operations.
void mb_pixbuf_destroy(MBPixbuf *pixbuf)
Destroys a new MBPixbuf instance.
MBPixbufImage * mb_pixbuf_img_rgba_new(MBPixbuf *pixbuf, int width, int height)
Constructs a new blank mbpixbuf image with an alpha channel.
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.
MBPixbufImage * mb_pixbuf_img_scale(MBPixbuf *pixbuf, MBPixbufImage *image, int new_width, int new_height)
Scales an image arbitually.
MBPixbuf * mb_pixbuf_new_extended(Display *dpy, int scr, Visual *vis, int depth)
Constructs a new MBPixbuf instance with non default depth and visual.
void mb_pixbuf_img_composite(MBPixbuf *pb, MBPixbufImage *dest, MBPixbufImage *src, int dx, int dy)
DEPRECATED.
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.