This file is indexed.

/usr/include/libmb/mbpixbuf.h is in libmatchbox-dev 1.9-osso8-3.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
#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

/**
 * @defgroup MBPixbuf MBPixbuf - Simple image manipulation tools
 * @brief 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.
 * 
 * <pre>
 * 
 *  #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);
 *  }
 *
 * </pre>
 *
 * Notes: if the enviromental varible 'MBPIXBUF_NO_SHM' is set, the MIT-SHM 
 * extension will not be used.       
 *
 * @{
 */

/**
 * @typedef MBPixbufTransform
 *
 * enumerated types for #mb_pixbuf_img_transform
 */
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 MBPixbuf
 *
 * Opaque structure used for all operations. 
 */ 
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 MBPixbufImage
 *
 * Type for representing an mbpixbuf image.
 * Its not recommended you touch this directly. 
 */
typedef struct MBPixbufImage 
{
  int            width;     /**< width in pixels of image */
  int            height;    /**< height in pixels of image */
  unsigned char *rgba;      /**< rgb(a) raw image data */
  int            has_alpha; /**< has alpha channel flag */
  XImage        *ximg;      /**< ximage, if set */

  int            internal_bytespp;

} MBPixbufImage;

/* macros */

/**
 * @def mb_pixbuf_img_set_pixel(i, x, y, r, g, b)
 *
 * DEPRICIATED. Use #mb_pixbuf_img_plot_pixel instead. 
 */
#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;    \
}

/**
 * @def mb_pixbuf_img_set_pixel_alpha 
 *
 * sets a pixels alpha value
 */
#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;    \
}



/**
 * @def mb_pixbuf_img_get_width
 *
 * returns image width
 */
#define mb_pixbuf_img_get_width(image)  (image)->width

/**
 * @def mb_pixbuf_img_get_height 
 *
 * returns image height
 */
#define mb_pixbuf_img_get_height(image) (image)->height

/**
 * @def mb_pixbuf_get_depth
 *
 * returns pixbuf instance depth
 */
#define mb_pixbuf_get_depth(pb) (pb)->depth

/**
 * @def mb_pixbuf_img_has_alpha 
 *
 * Returns True if image has an alpha channel. 
 */
#define mb_pixbuf_img_has_alpha(image)  (image)->has_alpha

/**
 * Constructs a new MBPixbuf instance
 *
 * @param display 
 * @param screen 
 * @returns a #MBPixbuf object
 */
MBPixbuf*
mb_pixbuf_new (Display *display,
	       int      screen);


/**
 * Constructs a new MBPixbuf instance with non default depth and visual
 *
 * @param dpy X display 
 * @param scr X Screen 
 * @param vis X Visual to use
 * @param depth Depth to use
 * @returns a #MBPixbuf object
 */
MBPixbuf *
mb_pixbuf_new_extended(Display *dpy, 
		       int      scr, 
		       Visual  *vis,
		       int      depth);

/**
 * Destroys a new MBPixbuf instance
 *
 * @param pixbuf MBPixbuf object
 */
void
mb_pixbuf_destroy(MBPixbuf *pixbuf);

/** 
 * Get the X pixel representation for a given color
 * 
 * @param pixbuf mbpixbuf object
 * @param r red component of color
 * @param g green component of color
 * @param b blue component of color
 * @param a alpha component
 *
 * @returns x pixel value 
 */
unsigned long
mb_pixbuf_lookup_x_pixel(MBPixbuf *pixbuf, int r, int g, int b, int a);


/**
 * DEPRECIATED. Use #mb_pixbuf_img_rgb_new, #mb_pixbuf_img_rgba_new instead. 
 *
 */
MBPixbufImage*
mb_pixbuf_img_new (MBPixbuf  *pb,
		   int        width,
		   int        height);

/**
 * Constructs a new blank mbpixbuf image with an alpha channel.
 *
 * @param pixbuf mbpixbuf object
 * @param width  width in pixels of new image
 * @param height  height in pixels of new image
 * @returns a MBPixbufImage object
 */
MBPixbufImage *
mb_pixbuf_img_rgba_new(MBPixbuf *pixbuf, 
		       int       width, 
		       int       height);

/**
 * Constructs a new blank mbpixbuf image without an alpha channel.
 *
 * @param pixbuf mbpixbuf object
 * @param width  width in pixels of new image
 * @param height height in pixels of new image
 * @returns a MBPixbufImage object
 */
MBPixbufImage *
mb_pixbuf_img_rgb_new (MBPixbuf *pixbuf, 
		       int       width, 
		       int       height);

/**
 *  Depreicated. use #mb_pixbuf_img_new_from_x_drawable instead.
 */
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);

/**
 * Constructs a new blank mbpixbuf image with/without an alpha channel.
 *
 * @param pixbuf   mbpixbuf object
 * @param drawable an X drawable ( window or pixmap )
 * @param mask     set to none if alpha channel not required
 * @param source_x x co-ord of X drawable 
 * @param source_y y co-ord of X drawable 
 * @param source_w width of X drawable 
 * @param source_h height of X drawable
 * @param want_alpha force created image to have an ( empty ) alpha channel
 *        even if no mask is supplied.  
 * @returns a MBPixbufImage object, NULL on faliure
 */
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);


/**
 * Creates an mbpixbuf image from a file on disk.
 * Supports PNG, JPEGS and XPMS. 
 *
 * @param pixbuf mbpixbuf object
 * @param filename full filename of image to be loaded
 * @returns a MBPixbufImage object, NULL on faliure
 */
MBPixbufImage *
mb_pixbuf_img_new_from_file (MBPixbuf   *pixbuf,
			     const char *filename);

/**
 * Creates an mbpixbuf image from arbituary supplied rgb(a) data
 *
 * @param pixbuf mbpixbuf object
 * @param data rgb(a) data
 * @param width image width
 * @param height image height
 * @param has_alpha True if data has alpha component
 * @returns a MBPixbufImage object, NULL on faliure
 */
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 INT ARGB data
 *
 * @param pixbuf mbpixbuf object
 * @param data argb data
 * @param width image width
 * @param height image height
 * @returns a MBPixbufImage object, NULL on faliure
 */

MBPixbufImage *
mb_pixbuf_img_new_from_int_data(MBPixbuf            *pixbuf, 
				const int           *data,
				int                  width,
				int                  height);
 
/**
 * Frees up  a mbpixbuf image.
 *
 * @param pixbuf mbpixbuf object
 * @param image image to free
 */
void  
mb_pixbuf_img_free (MBPixbuf      *pixbuf,
		    MBPixbufImage *image);

/**
 * Renders a mbpixbuf image to an X Drawable. 
 *
 * @param pixbuf mbpixbuf object
 * @param image mbpixbuf image to render
 * @param drw X11 drawable ( window or pixmap ) to render roo. 
 * @param drw_x X co-ord on drawable to render too. 
 * @param drw_y Y co-ord on drawable to render too. 
 */
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 with a specified. 
 * X Graphics Context ( GC ).
 *
 * @param pixbuf mbpixbuf object
 * @param image mbpixbuf image to render
 * @param drw X11 drawable ( window or pixmap ) to render roo. 
 * @param drw_x X co-ord on drawable to render too. 
 * @param drw_y Y co-ord on drawable to render too. 
 * @param gc X11 GC to use on drawable.
 */
void
mb_pixbuf_img_render_to_drawable_with_gc(MBPixbuf    *pixbuf,
					 MBPixbufImage *image,
					 Drawable     drw,
					 int drw_x,
					 int drw_y,
					 GC gc);


/**
 * Renders alpha component  mbpixbuf image to an X Bitmap. 
 *
 * @param pixbuf mbpixbuf object
 * @param image mbpixbuf image to render
 * @param mask X11 bitmap. 
 * @param mask_x X co-ord on drawable to render too. 
 * @param mask_y Y co-ord on drawable to render too. 
 */
void mb_pixbuf_img_render_to_mask (MBPixbuf      *pixbuf,
				   MBPixbufImage *image,
				   Drawable       mask,
				   int            mask_x,
				   int            mask_y);

/**
 * Clones a exisiting mbpixbuf image
 *
 * @param pixbuf mbpixbuf object
 * @param image image to clone
 * @returns a new cloned image
 */
MBPixbufImage *mb_pixbuf_img_clone (MBPixbuf      *pixbuf,
				    MBPixbufImage *image);

/**
 * Fills an image with specified color / alpha level. 
 *
 * @param pixbuf mbpixbuf object
 * @param image image to fill.
 * @param r red component of color
 * @param g green component of color
 * @param b blue component of color
 * @param a alpha component
 */
void
mb_pixbuf_img_fill(MBPixbuf *pixbuf, 
		   MBPixbufImage *image,
		   int r, 
		   int g, 
		   int b, 
		   int a);

/**
 * Plots a pixel on specified image. Note: on a RGBA image the alpha channel is
 * left as-is.
 *
 * @param pixbuf mbpixbuf object
 * @param image destination image
 * @param x X co-ord on destination image
 * @param y Y co-ord on destination image
 * @param r red component of color
 * @param g green component of color
 * @param b blue component of color
 */
void
mb_pixbuf_img_plot_pixel (MBPixbuf      *pixbuf,
			  MBPixbufImage *image,
			  int            x,
			  int            y,
			  unsigned char  r,
			  unsigned char  g,
			  unsigned char  b);


/**
 * Gets the component values for a specified pixel
 *
 * @param pixbuf mbpixbuf object
 * @param image destination image
 * @param x X co-ord on destination image
 * @param y Y co-ord on destination image
 * @param r red component of color
 * @param g green component of color
 * @param b blue component of color
 * @param a alpha component of 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 rgb(a) internal data representation of an image
 *
 * @param pixbuf mbpixbuf object
 * @param image destination image
 * @returns rgb(a) data 
 */
unsigned char *
mb_pixbuf_img_data (MBPixbuf      *pixbuf,
		    MBPixbufImage *image);



/**
 * Plots a pixel on specified image with alpha channel value. 
 *
 * @param pixbuf mbpixbuf object
 * @param image destination image
 * @param x X co-ord on destination image
 * @param y Y co-ord on destination image
 * @param r red component of color
 * @param g green component of color
 * @param b blue component of color
 * @param a alpha component
 */
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);

/**
 * Copys an specified area of an image to another. 
 * No Alpha composition is performed. 
 *
 * @param pixbuf mbpixbuf object
 * @param dest destination image
 * @param src  source image
 * @param sx   source area X co-ord
 * @param sy   source area Y co-ord
 * @param sw   source area width. 
 * @param sh   source area height. 
 * @param dx   destination image X co-ord. 
 * @param dy   destination image Y co-ord. 
 */
void mb_pixbuf_img_copy (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. 
 *
 * @param pixbuf mbpixbuf object
 * @param dest destination image
 * @param src  source image
 * @param sx   source area X co-ord
 * @param sy   source area Y co-ord
 * @param sw   source area width. 
 * @param sh   source area height. 
 * @param dx   destination image X co-ord. 
 * @param dy   destination image Y co-ord. 
 */
void mb_pixbuf_img_copy_composite (MBPixbuf      *pixbuf,
				   MBPixbufImage *dest,
				   MBPixbufImage *src,
				   int            sx,
				   int            sy,
				   int            sw,
				   int            sh,
				   int            dx,
				   int            dy);

/**
 * Like #mb_pixbuf_img_copy_composite but sets an overall alpha value
 *
 * @param pixbuf mbpixbuf object
 * @param dest destination image
 * @param src  source image
 * @param sx   source area X co-ord
 * @param sy   source area Y co-ord
 * @param sw   source area width. 
 * @param sh   source area height. 
 * @param dx   destination image X co-ord. 
 * @param dy   destination image Y co-ord. 
 * @param overall_alpha The overall alpha value to set after composition. 
 */
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 );

/**
 * DEPRECATED. Use #mb_pixbuf_img_copy_composite instead. 
 *
 */
void mb_pixbuf_img_composite (MBPixbuf      *pb,
			      MBPixbufImage *dest,
			      MBPixbufImage *src,
			      int            dx,
			      int            dy);

/**
 * Scales an image arbitually. 
 *
 * @param pixbuf mbpixbuf object
 * @param image mbpixbuf image to scale
 * @param new_width new image width
 * @param new_height new image height
 * @returns a new scaled image
 */
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);

/**
 * Performs a basic transform on an image. 
 *
 * @param pixbuf mbpixbuf object
 * @param image mbpixbuf image to scale
 * @param transform the type of transform to perform
 * @returns a new transformed image
 */
MBPixbufImage *
mb_pixbuf_img_transform (MBPixbuf          *pixbuf,
			 MBPixbufImage     *image,
			 MBPixbufTransform  transform);


/** @} */

#ifdef __cplusplus
}
#endif


#endif