2009-01-13 01:45:06 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gb.image.h
|
|
|
|
|
2011-03-21 01:04:10 +01:00
|
|
|
(c) 2000-2011 Benoît Minisini <gambas@users.sourceforge.net>
|
2009-01-13 01:45:06 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2009-01-13 01:45:06 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __GB_IMAGE_H
|
|
|
|
#define __GB_IMAGE_H
|
|
|
|
|
|
|
|
#include "gambas.h"
|
|
|
|
|
|
|
|
/* constants used by image data format */
|
|
|
|
|
|
|
|
#define GB_IMAGE_BGRX 0 // 00000
|
|
|
|
#define GB_IMAGE_XRGB 1 // 00001
|
|
|
|
#define GB_IMAGE_RGBX 2 // 00010
|
|
|
|
#define GB_IMAGE_XBGR 3 // 00011
|
|
|
|
#define GB_IMAGE_BGR 4 // 00100
|
|
|
|
#define GB_IMAGE_RGB 5 // 00101
|
|
|
|
|
|
|
|
#define GB_IMAGE_BGRA 8 // 01000
|
|
|
|
#define GB_IMAGE_ARGB 9 // 01001
|
|
|
|
#define GB_IMAGE_RGBA 10 // 01010
|
|
|
|
#define GB_IMAGE_ABGR 11 // 01011
|
|
|
|
|
|
|
|
#define GB_IMAGE_BGRP 24 // 11000
|
|
|
|
#define GB_IMAGE_PRGB 25 // 11001
|
|
|
|
#define GB_IMAGE_RGBP 26 // 11010
|
|
|
|
#define GB_IMAGE_PBGR 27 // 11011
|
|
|
|
|
|
|
|
/* format test functions */
|
|
|
|
|
2009-01-17 00:12:10 +01:00
|
|
|
#define GB_IMAGE_FMT_IS_24_BITS(_format) ((_format) & 4)
|
2009-02-03 00:46:01 +01:00
|
|
|
#define GB_IMAGE_FMT_IS_32_BITS(_format) (((_format) & 4) == 0)
|
2009-01-13 01:45:06 +01:00
|
|
|
|
2009-01-21 02:25:13 +01:00
|
|
|
#define GB_IMAGE_FMT_IS_RGBA(_format) ((_format) & 2)
|
|
|
|
|
2009-01-17 00:12:10 +01:00
|
|
|
#define GB_IMAGE_FMT_IS_SWAPPED(_format) ((_format) & 1)
|
|
|
|
|
|
|
|
#define GB_IMAGE_FMT_IS_TRANSPARENT(_format) ((_format) & 8)
|
|
|
|
|
|
|
|
#define GB_IMAGE_FMT_IS_PREMULTIPLIED(_format) ((_format) & 16)
|
|
|
|
#define GB_IMAGE_FMT_SET_PREMULTIPLIED(_format) ((_format) | 16)
|
|
|
|
#define GB_IMAGE_FMT_CLEAR_PREMULTIPLIED(_format) ((_format) & ~16)
|
|
|
|
|
|
|
|
/* Image owner information */
|
|
|
|
|
|
|
|
struct GB_IMG;
|
2009-01-13 01:45:06 +01:00
|
|
|
|
|
|
|
typedef
|
|
|
|
struct {
|
2009-01-22 01:47:14 +01:00
|
|
|
const char *name; // owner name (this is the name of the component)
|
2009-01-27 14:39:38 +01:00
|
|
|
int format; // preferred format
|
2009-01-22 01:47:14 +01:00
|
|
|
void (*free)(struct GB_IMG *img, void *handle); // free owner handle
|
|
|
|
void (*release)(struct GB_IMG *img, void *handle); // free temporary handle
|
|
|
|
void *(*temp)(struct GB_IMG *img); // create a temporary handle for an image and returns it
|
2010-06-19 14:38:28 +02:00
|
|
|
void (*sync)(struct GB_IMG *img); // synchronize the data. Called only if the GB_IMG.sync flag is set
|
2009-01-13 01:45:06 +01:00
|
|
|
}
|
2009-01-17 00:12:10 +01:00
|
|
|
GB_IMG_OWNER;
|
|
|
|
|
2009-01-13 01:45:06 +01:00
|
|
|
/* Gambas image */
|
|
|
|
|
|
|
|
typedef
|
2009-01-17 00:12:10 +01:00
|
|
|
struct GB_IMG {
|
|
|
|
GB_BASE ob;
|
2009-01-13 01:45:06 +01:00
|
|
|
unsigned char *data; // points at the image data
|
|
|
|
int width; // image width in pixels
|
|
|
|
int height; // image height in pixels
|
|
|
|
int format; // image format (RGB, BGR, RGBA...)
|
2009-01-17 00:12:10 +01:00
|
|
|
GB_IMG_OWNER *owner; // owner of the data, NULL means gb.image
|
|
|
|
void *owner_handle; // handle for the owner
|
2009-01-22 01:47:14 +01:00
|
|
|
GB_IMG_OWNER *temp_owner; // owner of the temporary handle that does not own the data
|
2009-01-17 00:12:10 +01:00
|
|
|
void *temp_handle; // temporary handle
|
2010-06-19 14:38:28 +02:00
|
|
|
unsigned modified : 1; // data has been modified by gb.image
|
|
|
|
unsigned sync : 1; // data must be synchronized by calling GB_IMG_OWNER.sync()
|
2011-02-25 01:26:22 +01:00
|
|
|
unsigned is_void : 1; // void image (no data)
|
2009-01-13 01:45:06 +01:00
|
|
|
}
|
2009-01-17 00:12:10 +01:00
|
|
|
GB_IMG;
|
|
|
|
|
|
|
|
#ifndef __GB_IMAGE_DEFINED
|
|
|
|
#define __GB_IMAGE_DEFINED
|
|
|
|
typedef
|
|
|
|
void *GB_IMAGE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Pixel color: the color is not premultiplied, and the alpha component is inverted (0 = solid / 255 = transparent) */
|
|
|
|
|
2009-12-24 03:02:05 +01:00
|
|
|
#ifndef __GB_COLOR_DEFINED
|
|
|
|
#define __GB_COLOR_DEFINED
|
2009-01-17 00:12:10 +01:00
|
|
|
typedef
|
|
|
|
unsigned int GB_COLOR;
|
2009-12-24 03:02:05 +01:00
|
|
|
#endif
|
2009-01-13 01:45:06 +01:00
|
|
|
|
2009-12-29 19:08:06 +01:00
|
|
|
/* Split a color into its component. Uninvert the alpha component */
|
|
|
|
|
|
|
|
#define GB_COLOR_SPLIT(_color, _r, _g, _b, _a) \
|
|
|
|
{ \
|
|
|
|
_b = (_color) & 0xFF; \
|
|
|
|
_g = ((_color) >> 8) & 0xFF; \
|
|
|
|
_r = ((_color) >> 16) & 0xFF; \
|
2009-12-29 19:19:33 +01:00
|
|
|
_a = ((_color) >> 24) ^ 0xFF; \
|
2009-12-29 19:08:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-13 01:45:06 +01:00
|
|
|
/* Gambas image component interface */
|
|
|
|
|
2009-01-17 00:12:10 +01:00
|
|
|
#define IMAGE_INTERFACE_VERSION 1
|
|
|
|
|
2009-01-13 01:45:06 +01:00
|
|
|
typedef
|
|
|
|
struct {
|
|
|
|
intptr_t version;
|
2009-01-22 01:47:14 +01:00
|
|
|
// Create an image
|
2009-01-17 00:12:10 +01:00
|
|
|
GB_IMG *(*Create)(int width, int height, int format, unsigned char *data);
|
2009-01-22 01:47:14 +01:00
|
|
|
// Take image ownership by giving the image handle and information
|
2009-01-17 00:12:10 +01:00
|
|
|
void (*Take)(GB_IMG *img, GB_IMG_OWNER *owner, void *owner_handle, int width, int height, unsigned char *data);
|
2009-01-22 01:47:14 +01:00
|
|
|
// Create a temporary handle on the image without becoming the owner.
|
2009-01-27 14:39:38 +01:00
|
|
|
void *(*Check)(GB_IMG *img, GB_IMG_OWNER *temp_owner);
|
2010-06-19 14:38:28 +02:00
|
|
|
// Synchronize the image data if needed
|
|
|
|
void (*Synchronize)(GB_IMG *img);
|
2009-01-22 01:47:14 +01:00
|
|
|
// Return the size of the image data in bytes
|
2009-01-21 02:25:13 +01:00
|
|
|
int (*Size)(GB_IMG *img);
|
2009-01-22 01:47:14 +01:00
|
|
|
// Set the default format used when creating images
|
2009-01-21 02:25:13 +01:00
|
|
|
void (*SetDefaultFormat)(int format);
|
2009-08-25 23:54:26 +02:00
|
|
|
// Get the default format used when creating images
|
|
|
|
int (*GetDefaultFormat)(void);
|
2009-01-25 23:23:04 +01:00
|
|
|
// Get the color of a pixel
|
|
|
|
GB_COLOR (*GetPixel)(GB_IMG *img, int x, int y);
|
2009-01-27 02:24:19 +01:00
|
|
|
// Converts an image to one of the following formats: BGRA, RGBA, BGRP, RGBP
|
|
|
|
void (*Convert)(GB_IMG *img, int format);
|
2009-09-01 11:29:40 +02:00
|
|
|
// Merge two colors
|
|
|
|
GB_COLOR (*MergeColor)(GB_COLOR col1, GB_COLOR col2, double weight);
|
|
|
|
// Make a color lighter
|
|
|
|
GB_COLOR (*LighterColor)(GB_COLOR col);
|
|
|
|
// Make a color darker
|
|
|
|
GB_COLOR (*DarkerColor)(GB_COLOR col);
|
2009-01-13 01:45:06 +01:00
|
|
|
}
|
|
|
|
IMAGE_INTERFACE;
|
|
|
|
|
2009-01-17 00:12:10 +01:00
|
|
|
#define GB_IMG_HANDLE(_image) ((_image)->temp_handle)
|
|
|
|
|
2010-06-19 14:38:28 +02:00
|
|
|
#define SYNCHRONIZE_IMAGE(_image) (IMAGE.Synchronize(_image))
|
|
|
|
#define MODIFY_IMAGE(_image) ((_image)->modified = 1)
|
|
|
|
|
2009-01-27 14:39:38 +01:00
|
|
|
#define COLOR_DEFAULT (-1)
|
|
|
|
|
2009-01-13 01:45:06 +01:00
|
|
|
#endif
|
|
|
|
|