LibMB 1.12
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
53extern "C" {
54#endif
55
116typedef 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
126typedef struct _mb_pixbuf_col {
127 int r, g, b;
128 unsigned long pixel;
129} MBPixbufColor;
130
136typedef 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
153
160typedef 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
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
232MBPixbuf*
233mb_pixbuf_new (Display *display,
234 int screen);
235
236
246MBPixbuf *
248 int scr,
249 Visual *vis,
250 int depth);
251
257void
258mb_pixbuf_destroy(MBPixbuf *pixbuf);
259
271unsigned long
272mb_pixbuf_lookup_x_pixel(MBPixbuf *pixbuf, int r, int g, int b, int a);
273
274
279MBPixbufImage*
280mb_pixbuf_img_new (MBPixbuf *pb,
281 int width,
282 int height);
283
292MBPixbufImage *
293mb_pixbuf_img_rgba_new(MBPixbuf *pixbuf,
294 int width,
295 int height);
296
305MBPixbufImage *
306mb_pixbuf_img_rgb_new (MBPixbuf *pixbuf,
307 int width,
308 int height);
309
313MBPixbufImage *
315 Drawable drawable,
316 Drawable mask,
317 int source_x,
318 int source_y,
319 int source_w,
320 int source_h);
321
336MBPixbufImage *
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
355MBPixbufImage *
357 const char *filename);
358
369MBPixbufImage *
371 const unsigned char *data,
372 int width,
373 int height,
374 Bool has_alpha);
375
376
387MBPixbufImage *
389 const int *data,
390 int width,
391 int height);
392
406MBPixbufImage *
408 const unsigned long *data,
409 int width,
410 int height);
411
418void
419mb_pixbuf_img_free (MBPixbuf *pixbuf,
420 MBPixbufImage *image);
421
431void mb_pixbuf_img_render_to_drawable (MBPixbuf *pixbuf,
432 MBPixbufImage *image,
433 Drawable drw,
434 int drw_x,
435 int drw_y);
436
448void
450 MBPixbufImage *image,
451 Drawable drw,
452 int drw_x,
453 int drw_y,
454 GC gc);
455
456
466void mb_pixbuf_img_render_to_mask (MBPixbuf *pixbuf,
467 MBPixbufImage *image,
468 Drawable mask,
469 int mask_x,
470 int mask_y);
471
479MBPixbufImage *mb_pixbuf_img_clone (MBPixbuf *pixbuf,
480 MBPixbufImage *image);
481
492void
493mb_pixbuf_img_fill(MBPixbuf *pixbuf,
494 MBPixbufImage *image,
495 int r,
496 int g,
497 int b,
498 int a);
499
512void
513mb_pixbuf_img_plot_pixel (MBPixbuf *pixbuf,
514 MBPixbufImage *image,
515 int x,
516 int y,
517 unsigned char r,
518 unsigned char g,
519 unsigned char b);
520
521
534void
535mb_pixbuf_img_get_pixel (MBPixbuf *pixbuf,
536 MBPixbufImage *image,
537 int x,
538 int y,
539 unsigned char *r,
540 unsigned char *g,
541 unsigned char *b,
542 unsigned char *a
543 );
544
552unsigned char *
553mb_pixbuf_img_data (MBPixbuf *pixbuf,
554 MBPixbufImage *image);
555
556
557
570void
572 MBPixbufImage *image,
573 int x,
574 int y,
575 unsigned char r,
576 unsigned char g,
577 unsigned char b,
578 unsigned char a);
579
594void mb_pixbuf_img_copy (MBPixbuf *pixbuf,
595 MBPixbufImage *dest,
596 MBPixbufImage *src,
597 int sx,
598 int sy,
599 int sw,
600 int sh,
601 int dx,
602 int dy);
603
604
618void mb_pixbuf_img_copy_composite (MBPixbuf *pixbuf,
619 MBPixbufImage *dest,
620 MBPixbufImage *src,
621 int sx,
622 int sy,
623 int sw,
624 int sh,
625 int dx,
626 int dy);
627
643 MBPixbufImage *dest,
644 MBPixbufImage *src,
645 int sx, int sy,
646 int sw, int sh,
647 int dx, int dy,
648 int overall_alpha );
649
654void mb_pixbuf_img_composite (MBPixbuf *pb,
655 MBPixbufImage *dest,
656 MBPixbufImage *src,
657 int dx,
658 int dy);
659
669MBPixbufImage *mb_pixbuf_img_scale (MBPixbuf *pixbuf,
670 MBPixbufImage *image,
671 int new_width,
672 int new_height);
673
674
675MBPixbufImage *mb_pixbuf_img_scale_down (MBPixbuf *pixbuf,
676 MBPixbufImage *image,
677 int new_width,
678 int new_height);
679
680
681MBPixbufImage *mb_pixbuf_img_scale_up (MBPixbuf *pixbuf,
682 MBPixbufImage *image,
683 int new_width,
684 int new_height);
685
694MBPixbufImage *
695mb_pixbuf_img_transform (MBPixbuf *pixbuf,
696 MBPixbufImage *image,
697 MBPixbufTransform transform);
698
699
702#ifdef __cplusplus
703}
704#endif
705
706
707#endif
708
709
710
MBPixbufImage * mb_pixbuf_img_new(MBPixbuf *pb, int width, int height)
DEPRECIATED.
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.
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_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.
MBPixbufImage * mb_pixbuf_img_clone(MBPixbuf *pixbuf, MBPixbufImage *image)
Clones a exisiting mbpixbuf image.
void mb_pixbuf_img_free(MBPixbuf *pixbuf, MBPixbufImage *image)
Frees up a mbpixbuf image.
MBPixbufImage * mb_pixbuf_img_scale(MBPixbuf *pixbuf, MBPixbufImage *image, int new_width, int new_height)
Scales an image arbitually.
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.
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.
void mb_pixbuf_img_composite(MBPixbuf *pb, MBPixbufImage *dest, MBPixbufImage *src, int dx, int dy)
DEPRECATED.
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_render_to_drawable(MBPixbuf *pixbuf, MBPixbufImage *image, Drawable drw, int drw_x, int drw_y)
Renders a mbpixbuf image to an X Drawable.
struct MBPixbuf MBPixbuf
Opaque structure used for all operations.
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.
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.
void mb_pixbuf_destroy(MBPixbuf *pixbuf)
Destroys a new MBPixbuf instance.
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.
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.
MBPixbufImage * mb_pixbuf_img_transform(MBPixbuf *pixbuf, MBPixbufImage *image, MBPixbufTransform transform)
Performs a basic transform on an 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_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.
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.
MBPixbuf * mb_pixbuf_new(Display *display, int screen)
Constructs a new MBPixbuf instance.
MBPixbufTransform
enumerated types for mb_pixbuf_img_transform
Definition mbpixbuf.h:117
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.
MBPixbufImage * mb_pixbuf_img_rgb_new(MBPixbuf *pixbuf, int width, int height)
Constructs a new blank mbpixbuf image without an alpha channel.
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.
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_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.
struct MBPixbufImage MBPixbufImage
Type for representing an mbpixbuf image.
MBPixbuf * mb_pixbuf_new_extended(Display *dpy, int scr, Visual *vis, int depth)
Constructs a new MBPixbuf instance with non default depth and visual.