00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _GAN_IMAGE_DEFS_H
00030 #define _GAN_IMAGE_DEFS_H
00031
00032 #include <stdlib.h>
00033 #include <gandalf/image/pixel.h>
00034 #include <gandalf/common/misc_defs.h>
00035
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039
00045
00046 typedef struct Gan_Image
00047 {
00049 Gan_ImageFormat format;
00050
00052 Gan_Type type;
00053
00055 unsigned long height, width;
00056
00059 unsigned long stride;
00060
00063 unsigned char *pix_data_ptr;
00064
00066 size_t pix_data_size;
00067
00069 Gan_Bool pix_data_alloc;
00070
00072 union
00073 {
00075 union
00076 {
00077 unsigned char **uc;
00078 short **s;
00079 unsigned short **us;
00080 int **i;
00081 unsigned int **ui;
00082 float **f;
00083 double **d;
00084 Gan_BitWord **b;
00085 void ***p;
00086 } gl;
00087
00089 union
00090 {
00091 Gan_GLAPixel_uc **uc;
00092 Gan_GLAPixel_s **s;
00093 Gan_GLAPixel_us **us;
00094 Gan_GLAPixel_i **i;
00095 Gan_GLAPixel_ui **ui;
00096 Gan_GLAPixel_f **f;
00097 Gan_GLAPixel_d **d;
00098 } gla;
00099
00101 union
00102 {
00103 Gan_RGBPixel_uc **uc;
00104 Gan_RGBPixel_s **s;
00105 Gan_RGBPixel_us **us;
00106 Gan_RGBPixel_i **i;
00107 Gan_RGBPixel_ui **ui;
00108 Gan_RGBPixel_f **f;
00109 Gan_RGBPixel_d **d;
00110 } rgb;
00111
00113 union
00114 {
00115 Gan_RGBAPixel_uc **uc;
00116 Gan_RGBAPixel_s **s;
00117 Gan_RGBAPixel_us **us;
00118 Gan_RGBAPixel_i **i;
00119 Gan_RGBAPixel_ui **ui;
00120 Gan_RGBAPixel_f **f;
00121 Gan_RGBAPixel_d **d;
00122 } rgba;
00123
00125 union
00126 {
00127 Gan_Vector2_f **f;
00128 Gan_Vector2 **d;
00129 Gan_Vector2_s **s;
00130 Gan_Vector2_i **i;
00131 } vfield2D;
00132
00134 union
00135 {
00136 Gan_Vector3_f **f;
00137 Gan_Vector3 **d;
00138 Gan_Vector3_s **s;
00139 Gan_Vector3_i **i;
00140 } vfield3D;
00141 } row_data;
00142
00144 void *row_data_ptr;
00145
00147 size_t row_data_size;
00148
00150 Gan_BitArray *ba;
00151
00153 int offset_x, offset_y;
00154
00156 Gan_Bool row_data_alloc;
00157
00159 Gan_Bool struct_alloc;
00160
00162 void (*data_free_func) (void *);
00163
00165 void (*free_func) ( struct Gan_Image *img );
00166
00167 #ifndef NDEBUG
00168
00170 union
00171 {
00173 union
00174 {
00175 Gan_Bool (*uc) ( struct Gan_Image *, unsigned row, unsigned col,
00176 unsigned char pix );
00177 Gan_Bool (*s) ( struct Gan_Image *, unsigned row, unsigned col,
00178 short pix );
00179 Gan_Bool (*us) ( struct Gan_Image *, unsigned row, unsigned col,
00180 unsigned short pix );
00181 Gan_Bool (*i) ( struct Gan_Image *, unsigned row, unsigned col,
00182 int pix );
00183 Gan_Bool (*ui) ( struct Gan_Image *, unsigned row, unsigned col,
00184 unsigned int pix );
00185 Gan_Bool (*f) ( struct Gan_Image *, unsigned row, unsigned col,
00186 float pix );
00187 Gan_Bool (*d) ( struct Gan_Image *, unsigned row, unsigned col,
00188 double pix );
00189 Gan_Bool (*b) ( struct Gan_Image *, unsigned row, unsigned col,
00190 Gan_Bool pix );
00191 Gan_Bool (*p) ( struct Gan_Image *, unsigned row, unsigned col,
00192 void *pix );
00193 } gl;
00194
00196 union
00197 {
00198 Gan_Bool (*uc) ( struct Gan_Image *, unsigned row, unsigned col,
00199 Gan_GLAPixel_uc *pix );
00200 Gan_Bool (*s) ( struct Gan_Image *, unsigned row, unsigned col,
00201 Gan_GLAPixel_s *pix );
00202 Gan_Bool (*us) ( struct Gan_Image *, unsigned row, unsigned col,
00203 Gan_GLAPixel_us *pix );
00204 Gan_Bool (*i) ( struct Gan_Image *, unsigned row, unsigned col,
00205 Gan_GLAPixel_i *pix );
00206 Gan_Bool (*ui) ( struct Gan_Image *, unsigned row, unsigned col,
00207 Gan_GLAPixel_ui *pix );
00208 Gan_Bool (*f) ( struct Gan_Image *, unsigned row, unsigned col,
00209 Gan_GLAPixel_f *pix );
00210 Gan_Bool (*d) ( struct Gan_Image *, unsigned row, unsigned col,
00211 Gan_GLAPixel_d *pix );
00212 } gla;
00213
00215 union
00216 {
00217 Gan_Bool (*uc) ( struct Gan_Image *, unsigned row, unsigned col,
00218 Gan_RGBPixel_uc *pix );
00219 Gan_Bool (*s) ( struct Gan_Image *, unsigned row, unsigned col,
00220 Gan_RGBPixel_s *pix );
00221 Gan_Bool (*us) ( struct Gan_Image *, unsigned row, unsigned col,
00222 Gan_RGBPixel_us *pix );
00223 Gan_Bool (*i) ( struct Gan_Image *, unsigned row, unsigned col,
00224 Gan_RGBPixel_i *pix );
00225 Gan_Bool (*ui) ( struct Gan_Image *, unsigned row, unsigned col,
00226 Gan_RGBPixel_ui *pix );
00227 Gan_Bool (*d) ( struct Gan_Image *, unsigned row, unsigned col,
00228 Gan_RGBPixel_d *pix );
00229 Gan_Bool (*f) ( struct Gan_Image *, unsigned row, unsigned col,
00230 Gan_RGBPixel_f *pix );
00231 } rgb;
00232
00234 union
00235 {
00236 Gan_Bool (*uc) ( struct Gan_Image *, unsigned row, unsigned col,
00237 Gan_RGBAPixel_uc *pix );
00238 Gan_Bool (*s) ( struct Gan_Image *, unsigned row, unsigned col,
00239 Gan_RGBAPixel_s *pix );
00240 Gan_Bool (*us) ( struct Gan_Image *, unsigned row, unsigned col,
00241 Gan_RGBAPixel_us *pix );
00242 Gan_Bool (*i) ( struct Gan_Image *, unsigned row, unsigned col,
00243 Gan_RGBAPixel_i *pix );
00244 Gan_Bool (*ui) ( struct Gan_Image *, unsigned row, unsigned col,
00245 Gan_RGBAPixel_ui *pix );
00246 Gan_Bool (*d) ( struct Gan_Image *, unsigned row, unsigned col,
00247 Gan_RGBAPixel_d *pix );
00248 Gan_Bool (*f) ( struct Gan_Image *, unsigned row, unsigned col,
00249 Gan_RGBAPixel_f *pix );
00250 } rgba;
00251
00253 union
00254 {
00255 Gan_Bool (*f) ( struct Gan_Image *, unsigned row, unsigned col,
00256 Gan_Vector2_f *pix );
00257 Gan_Bool (*d) ( struct Gan_Image *, unsigned row, unsigned col,
00258 Gan_Vector2 *pix );
00259 Gan_Bool (*s) ( struct Gan_Image *, unsigned row, unsigned col,
00260 Gan_Vector2_s *pix );
00261 Gan_Bool (*i) ( struct Gan_Image *, unsigned row, unsigned col,
00262 Gan_Vector2_i *pix );
00263 } vfield2D;
00264
00266 union
00267 {
00268 Gan_Bool (*f) ( struct Gan_Image *, unsigned row, unsigned col,
00269 Gan_Vector3_f *pix );
00270 Gan_Bool (*d) ( struct Gan_Image *, unsigned row, unsigned col,
00271 Gan_Vector3 *pix );
00272 Gan_Bool (*s) ( struct Gan_Image *, unsigned row, unsigned col,
00273 Gan_Vector3_s *pix );
00274 Gan_Bool (*i) ( struct Gan_Image *, unsigned row, unsigned col,
00275 Gan_Vector3_i *pix );
00276 } vfield3D;
00277 } set_pix;
00278
00280 union
00281 {
00283 union
00284 {
00285 unsigned char (*uc) (const struct Gan_Image *, unsigned row, unsigned col);
00286 short (*s) (const struct Gan_Image *, unsigned row, unsigned col);
00287 unsigned short (*us) (const struct Gan_Image *, unsigned row, unsigned col);
00288 int (*i) (const struct Gan_Image *, unsigned row, unsigned col);
00289 unsigned int (*ui) (const struct Gan_Image *, unsigned row, unsigned col);
00290 float (*f) (const struct Gan_Image *, unsigned row, unsigned col);
00291 double (*d) (const struct Gan_Image *, unsigned row, unsigned col);
00292 Gan_Bool (*b) (const struct Gan_Image *, unsigned row, unsigned col);
00293 void * (*p) (const struct Gan_Image *, unsigned row, unsigned col);
00294 } gl;
00295
00297 union
00298 {
00299 Gan_GLAPixel_uc (*uc)( const struct Gan_Image *,
00300 unsigned row, unsigned col );
00301 Gan_GLAPixel_s (*s)( const struct Gan_Image *,
00302 unsigned row, unsigned col );
00303 Gan_GLAPixel_us (*us)( const struct Gan_Image *,
00304 unsigned row, unsigned col );
00305 Gan_GLAPixel_i (*i)( const struct Gan_Image *,
00306 unsigned row, unsigned col );
00307 Gan_GLAPixel_ui (*ui)( const struct Gan_Image *,
00308 unsigned row, unsigned col );
00309 Gan_GLAPixel_f (*f)( const struct Gan_Image *,
00310 unsigned row, unsigned col );
00311 Gan_GLAPixel_d (*d)( const struct Gan_Image *,
00312 unsigned row, unsigned col );
00313 } gla;
00314
00316 union
00317 {
00318 Gan_RGBPixel_uc (*uc) ( const struct Gan_Image *,
00319 unsigned row, unsigned col );
00320 Gan_RGBPixel_s (*s) ( const struct Gan_Image *,
00321 unsigned row, unsigned col );
00322 Gan_RGBPixel_us (*us) ( const struct Gan_Image *,
00323 unsigned row, unsigned col );
00324 Gan_RGBPixel_i (*i) ( const struct Gan_Image *,
00325 unsigned row, unsigned col );
00326 Gan_RGBPixel_ui (*ui) ( const struct Gan_Image *,
00327 unsigned row, unsigned col );
00328 Gan_RGBPixel_f (*f) ( const struct Gan_Image *,
00329 unsigned row, unsigned col );
00330 Gan_RGBPixel_d (*d) ( const struct Gan_Image *,
00331 unsigned row, unsigned col );
00332 } rgb;
00333
00335 union
00336 {
00337 Gan_RGBAPixel_uc (*uc) ( const struct Gan_Image *,
00338 unsigned row, unsigned col );
00339 Gan_RGBAPixel_s (*s) ( const struct Gan_Image *,
00340 unsigned row, unsigned col );
00341 Gan_RGBAPixel_us (*us) ( const struct Gan_Image *,
00342 unsigned row, unsigned col );
00343 Gan_RGBAPixel_i (*i) ( const struct Gan_Image *,
00344 unsigned row, unsigned col );
00345 Gan_RGBAPixel_ui (*ui) ( const struct Gan_Image *,
00346 unsigned row, unsigned col );
00347 Gan_RGBAPixel_f (*f) ( const struct Gan_Image *,
00348 unsigned row, unsigned col );
00349 Gan_RGBAPixel_d (*d) ( const struct Gan_Image *,
00350 unsigned row, unsigned col );
00351 } rgba;
00352
00354 union
00355 {
00356 Gan_Vector2_f (*f) ( const struct Gan_Image *, unsigned row, unsigned col );
00357 Gan_Vector2 (*d) ( const struct Gan_Image *, unsigned row, unsigned col );
00358 Gan_Vector2_s (*s) ( const struct Gan_Image *, unsigned row, unsigned col );
00359 Gan_Vector2_i (*i) ( const struct Gan_Image *, unsigned row, unsigned col );
00360 } vfield2D;
00361
00363 union
00364 {
00365 Gan_Vector3_f (*f) ( const struct Gan_Image *, unsigned row, unsigned col );
00366 Gan_Vector3 (*d) ( const struct Gan_Image *, unsigned row, unsigned col );
00367 Gan_Vector3_s (*s) ( const struct Gan_Image *, unsigned row, unsigned col );
00368 Gan_Vector3_i (*i) ( const struct Gan_Image *, unsigned row, unsigned col );
00369 } vfield3D;
00370 } get_pix;
00371
00372 #endif
00373
00375 union
00376 {
00378 union
00379 {
00380 Gan_Bool (*uc) ( struct Gan_Image *, unsigned char pix );
00381 Gan_Bool (*s) ( struct Gan_Image *, short pix );
00382 Gan_Bool (*us) ( struct Gan_Image *, unsigned short pix );
00383 Gan_Bool (*i) ( struct Gan_Image *, int pix );
00384 Gan_Bool (*ui) ( struct Gan_Image *, unsigned int pix );
00385 Gan_Bool (*f) ( struct Gan_Image *, float pix );
00386 Gan_Bool (*d) ( struct Gan_Image *, double pix );
00387 Gan_Bool (*b) ( struct Gan_Image *, Gan_Bool pix );
00388 Gan_Bool (*p) ( struct Gan_Image *, void * pix );
00389 } gl;
00390
00392 union
00393 {
00394 Gan_Bool (*uc) ( struct Gan_Image *, Gan_GLAPixel_uc *pix );
00395 Gan_Bool (*s) ( struct Gan_Image *, Gan_GLAPixel_s *pix );
00396 Gan_Bool (*us) ( struct Gan_Image *, Gan_GLAPixel_us *pix );
00397 Gan_Bool (*i) ( struct Gan_Image *, Gan_GLAPixel_i *pix );
00398 Gan_Bool (*ui) ( struct Gan_Image *, Gan_GLAPixel_ui *pix );
00399 Gan_Bool (*f) ( struct Gan_Image *, Gan_GLAPixel_f *pix );
00400 Gan_Bool (*d) ( struct Gan_Image *, Gan_GLAPixel_d *pix );
00401 } gla;
00402
00404 union
00405 {
00406 Gan_Bool (*uc) ( struct Gan_Image *, Gan_RGBPixel_uc *pix );
00407 Gan_Bool (*s) ( struct Gan_Image *, Gan_RGBPixel_s *pix );
00408 Gan_Bool (*us) ( struct Gan_Image *, Gan_RGBPixel_us *pix );
00409 Gan_Bool (*i) ( struct Gan_Image *, Gan_RGBPixel_i *pix );
00410 Gan_Bool (*ui) ( struct Gan_Image *, Gan_RGBPixel_ui *pix );
00411 Gan_Bool (*f) ( struct Gan_Image *, Gan_RGBPixel_f *pix );
00412 Gan_Bool (*d) ( struct Gan_Image *, Gan_RGBPixel_d *pix );
00413 } rgb;
00414
00416 union
00417 {
00418 Gan_Bool (*uc) ( struct Gan_Image *, Gan_RGBAPixel_uc *pix );
00419 Gan_Bool (*s) ( struct Gan_Image *, Gan_RGBAPixel_s *pix );
00420 Gan_Bool (*us) ( struct Gan_Image *, Gan_RGBAPixel_us *pix );
00421 Gan_Bool (*i) ( struct Gan_Image *, Gan_RGBAPixel_i *pix );
00422 Gan_Bool (*ui) ( struct Gan_Image *, Gan_RGBAPixel_ui *pix );
00423 Gan_Bool (*f) ( struct Gan_Image *, Gan_RGBAPixel_f *pix );
00424 Gan_Bool (*d) ( struct Gan_Image *, Gan_RGBAPixel_d *pix );
00425 } rgba;
00426
00428 union
00429 {
00430 Gan_Bool (*f) ( struct Gan_Image *, Gan_Vector2_f *pix );
00431 Gan_Bool (*d) ( struct Gan_Image *, Gan_Vector2 *pix );
00432 Gan_Bool (*s) ( struct Gan_Image *, Gan_Vector2_s *pix );
00433 Gan_Bool (*i) ( struct Gan_Image *, Gan_Vector2_i *pix );
00434 } vfield2D;
00435
00437 union
00438 {
00439 Gan_Bool (*f) ( struct Gan_Image *, Gan_Vector3_f *pix );
00440 Gan_Bool (*d) ( struct Gan_Image *, Gan_Vector3 *pix );
00441 Gan_Bool (*s) ( struct Gan_Image *, Gan_Vector3_s *pix );
00442 Gan_Bool (*i) ( struct Gan_Image *, Gan_Vector3_i *pix );
00443 } vfield3D;
00444 } fill_const;
00445
00447 struct Gan_Image * (*copy) ( const struct Gan_Image *, struct Gan_Image * );
00448 } Gan_Image;
00449
00450 #define GAN_IMAGE_STRUCT_DEFINED
00451
00453 typedef struct Gan_ImageWindow
00454 {
00456 int c0, r0;
00457
00459 int width, height;
00460 } Gan_ImageWindow;
00461
00479 Gan_Image *gan_image_alloc ( Gan_ImageFormat format, Gan_Type type,
00480 unsigned long height, unsigned long width );
00481
00496 Gan_Image *gan_image_form ( Gan_Image *img,
00497 Gan_ImageFormat format, Gan_Type type,
00498 unsigned long height, unsigned long width );
00499
00521 Gan_Image *gan_image_alloc_data ( Gan_ImageFormat format, Gan_Type type,
00522 unsigned long height, unsigned long width,
00523 void *pix_data, size_t pix_data_size,
00524 void *row_data, size_t row_data_size );
00525
00546 Gan_Image *gan_image_form_data ( Gan_Image *img,
00547 Gan_ImageFormat format, Gan_Type type,
00548 unsigned long height, unsigned long width,
00549 void *pix_data, size_t pix_data_size,
00550 void *row_data, size_t row_data_size );
00551
00557 void gan_image_free ( Gan_Image *img );
00558
00574 Gan_Image *gan_image_copy_q ( const Gan_Image *img_s, Gan_Image *img_d );
00575
00582 Gan_Image *gan_image_copy_s ( const Gan_Image *img );
00583
00601 Gan_Image *gan_image_set_format_type_dims ( Gan_Image *img,
00602 Gan_ImageFormat format,
00603 Gan_Type type,
00604 unsigned long height,
00605 unsigned long width );
00606
00615 Gan_Image *gan_image_set_format_type ( Gan_Image *img,
00616 Gan_ImageFormat format, Gan_Type type );
00617
00626 Gan_Image *gan_image_set_type ( Gan_Image *img, Gan_Type type );
00627
00636 Gan_Image *gan_image_set_dims ( Gan_Image *img,
00637 unsigned long height, unsigned long width );
00638
00654 Gan_Bool gan_image_test_format ( const Gan_Image *img, Gan_ImageFormat format );
00655
00662 Gan_Bool gan_image_test_type ( const Gan_Image *img, Gan_Type type );
00663
00670 Gan_Bool gan_image_test_dims ( const Gan_Image *img1, const Gan_Image *img2 );
00671
00685 Gan_Bool gan_image_fill_zero_window ( Gan_Image *img,
00686 unsigned r0, unsigned c0,
00687 unsigned height, unsigned width );
00688
00693 Gan_Bool gan_image_fill_zero_mask ( Gan_Image *img, Gan_Image *mask );
00694
00704 Gan_Image *gan_image_form_gen ( Gan_Image *img,
00705 Gan_ImageFormat format, Gan_Type type,
00706 unsigned long height, unsigned long width,
00707 unsigned long stride, Gan_Bool alloc_pix_data,
00708 void *pix_data, size_t pix_data_size,
00709 void *row_data, size_t row_data_size );
00710 Gan_Bool gan_image_set_data_free_func ( Gan_Image *img,
00711 void (*data_free_func)(void *) );
00712
00722 size_t gan_image_pixel_size ( Gan_ImageFormat format, Gan_Type type );
00723 size_t gan_image_min_stride ( Gan_ImageFormat format, Gan_Type type,
00724 unsigned long width, size_t alignment );
00725
00735 Gan_Bool gan_image_fill_const ( Gan_Image *img, Gan_Pixel *pixel );
00736 Gan_Bool gan_image_fill_zero ( Gan_Image *img );
00737 Gan_Bool gan_image_fill_const_window ( Gan_Image *img,
00738 unsigned r0, unsigned c0,
00739 unsigned height, unsigned width,
00740 Gan_Pixel *pixel );
00741 Gan_Bool gan_image_fill_const_mask ( Gan_Image *img, Gan_Image *mask,
00742 Gan_Pixel *pixel );
00743
00753 Gan_Pixel gan_image_get_pix ( const Gan_Image *img, unsigned row, unsigned col );
00754 void *gan_image_get_pixptr ( const Gan_Image *img, unsigned row, unsigned col );
00755 Gan_Bool gan_image_get_pix_zero ( const Gan_Image *img, unsigned row, unsigned col );
00756 Gan_Bool gan_image_set_pix ( Gan_Image *img, unsigned row, unsigned col,
00757 Gan_Pixel *pix );
00758 Gan_Bool gan_image_set_pix_zero ( Gan_Image *img, unsigned row, unsigned col );
00759
00769 Gan_Bool gan_image_get_active_subwindow ( const Gan_Image *image,
00770 Gan_ImageWindow *subwin );
00771
00772 void gan_image_intersect_subwindows_q ( const Gan_ImageWindow *window1, const Gan_ImageWindow *window2,
00773 Gan_ImageWindow *resultwindow );
00774 Gan_ImageWindow gan_image_intersect_subwindows_s ( const Gan_ImageWindow *window1, const Gan_ImageWindow *window2 );
00775 void gan_image_intersect_subwindows_i ( Gan_ImageWindow *sourcedestwindow, const Gan_ImageWindow *window );
00776 void gan_image_fit_subwindow ( Gan_ImageWindow *subwin, const Gan_Image *image );
00777
00787 Gan_Bool gan_image_mask_window ( Gan_Image *image,
00788 unsigned r0, unsigned c0,
00789 unsigned height, unsigned width );
00790 Gan_Bool gan_image_clear_window ( Gan_Image *image,
00791 unsigned r0, unsigned c0,
00792 unsigned height, unsigned width );
00793
00803 Gan_Bool gan_image_get_minimum_pixel ( Gan_Image *image, Gan_Image *mask, Gan_Pixel *minpix );
00804 Gan_Bool gan_image_get_maximum_pixel ( Gan_Image *image, Gan_Image *mask, Gan_Pixel *maxpix );
00805
00815 void gan_image_free_va ( Gan_Image *img, ... );
00816
00826
00827 Gan_Image *gan_image_set_format_type_dims_gen ( Gan_Image *img,
00828 Gan_ImageFormat format,
00829 Gan_Type type,
00830 unsigned long height,
00831 unsigned long width,
00832 unsigned long stride,
00833 Gan_Bool alloc_pix_data );
00834
00843 #ifdef __cplusplus
00844 }
00845 #endif
00846
00847 #endif