00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _GAN_PIXEL_H
00030 #define _GAN_PIXEL_H
00031
00032 #include <gandalf/common/misc_defs.h>
00033 #include <gandalf/common/bit_array.h>
00034 #include <gandalf/linalg/2vector.h>
00035 #include <gandalf/linalg/2vectorf.h>
00036 #include <gandalf/linalg/3vector.h>
00037 #include <gandalf/linalg/3vectorf.h>
00038
00039 #ifdef __cplusplus
00040 extern "C" {
00041 #endif
00042
00056 typedef enum
00057 {
00058 GAN_GREY_LEVEL_IMAGE,
00059 GAN_GREY_LEVEL_ALPHA_IMAGE,
00060 GAN_RGB_COLOUR_IMAGE,
00061 GAN_RGB_COLOUR_ALPHA_IMAGE,
00062 GAN_VECTOR_FIELD_2D,
00063 GAN_VECTOR_FIELD_3D,
00064 GAN_UNDEFINED_IMAGE_FORMAT
00065 } Gan_ImageFormat;
00066
00070 typedef struct Gan_GLAPixel_uc
00071 {
00072 unsigned char I,
00073 A;
00074 } Gan_GLAPixel_uc;
00075
00079 typedef struct Gan_GLAPixel_s
00080 {
00081 short I,
00082 A;
00083 } Gan_GLAPixel_s;
00084
00088 typedef struct Gan_GLAPixel_us
00089 {
00090 unsigned short I,
00091 A;
00092 } Gan_GLAPixel_us;
00093
00097 typedef struct Gan_GLAPixel_i
00098 {
00099 int I,
00100 A;
00101 } Gan_GLAPixel_i;
00102
00106 typedef struct Gan_GLAPixel_ui
00107 {
00108 unsigned int I,
00109 A;
00110 } Gan_GLAPixel_ui;
00111
00115 typedef struct Gan_GLAPixel_f
00116 {
00117 float I,
00118 A;
00119 } Gan_GLAPixel_f;
00120
00124 typedef struct Gan_GLAPixel_d
00125 {
00126 double I,
00127 A;
00128 } Gan_GLAPixel_d;
00129
00133 typedef struct Gan_RGBPixel_uc
00134 {
00135 unsigned char R,
00136 G,
00137 B;
00138 } Gan_RGBPixel_uc;
00139
00143 typedef struct Gan_RGBPixel_s
00144 {
00145 short R,
00146 G,
00147 B;
00148 } Gan_RGBPixel_s;
00149
00153 typedef struct Gan_RGBPixel_us
00154 {
00155 unsigned short R,
00156 G,
00157 B;
00158 } Gan_RGBPixel_us;
00159
00163 typedef struct Gan_RGBPixel_i
00164 {
00165 int R,
00166 G,
00167 B;
00168 } Gan_RGBPixel_i;
00169
00173 typedef struct Gan_RGBPixel_ui
00174 {
00175 unsigned int R,
00176 G,
00177 B;
00178 } Gan_RGBPixel_ui;
00179
00183 typedef struct Gan_RGBPixel_f
00184 {
00185 float R,
00186 G,
00187 B;
00188 } Gan_RGBPixel_f;
00189
00193 typedef struct Gan_RGBPixel_d
00194 {
00195 double R,
00196 G,
00197 B;
00198 } Gan_RGBPixel_d;
00199
00203 typedef struct Gan_RGBAPixel_uc
00204 {
00205 unsigned char R,
00206 G,
00207 B,
00208 A;
00209 } Gan_RGBAPixel_uc;
00210
00214 typedef struct Gan_RGBAPixel_s
00215 {
00216 short R,
00217 G,
00218 B,
00219 A;
00220 } Gan_RGBAPixel_s;
00221
00225 typedef struct Gan_RGBAPixel_us
00226 {
00227 unsigned short R,
00228 G,
00229 B,
00230 A;
00231 } Gan_RGBAPixel_us;
00232
00236 typedef struct Gan_RGBAPixel_i
00237 {
00238 int R,
00239 G,
00240 B,
00241 A;
00242 } Gan_RGBAPixel_i;
00243
00247 typedef struct Gan_RGBAPixel_ui
00248 {
00249 unsigned int R,
00250 G,
00251 B,
00252 A;
00253 } Gan_RGBAPixel_ui;
00254
00258 typedef struct Gan_RGBAPixel_f
00259 {
00260 float R,
00261 G,
00262 B,
00263 A;
00264 } Gan_RGBAPixel_f;
00265
00269 typedef struct Gan_RGBAPixel_d
00270 {
00271 double R,
00272 G,
00273 B,
00274 A;
00275 } Gan_RGBAPixel_d;
00276
00277 #if (SIZEOF_CHAR == 1)
00278
00281 typedef struct Gan_GLAPixel_uc Gan_GLAPixel_ui8;
00282
00286 typedef struct Gan_RGBPixel_uc Gan_RGBPixel_ui8;
00287
00292 typedef struct Gan_RGBAPixel_uc Gan_RGBAPixel_ui8;
00293 #else
00294 #error "8-bit type conflict"
00295 #endif
00296
00297 #if (SIZEOF_SHORT == 2)
00298
00302 typedef struct Gan_GLAPixel_us Gan_GLAPixel_ui16;
00303
00307 typedef struct Gan_RGBPixel_us Gan_RGBPixel_ui16;
00308
00313 typedef struct Gan_RGBAPixel_us Gan_RGBAPixel_ui16;
00314 #else
00315 #error "16-bit type conflict"
00316 #endif
00317
00318 #if (SIZEOF_INT == 4)
00319
00323 typedef struct Gan_GLAPixel_ui Gan_GLAPixel_ui32;
00324
00328 typedef struct Gan_RGBPixel_ui Gan_RGBPixel_ui32;
00329
00334 typedef struct Gan_RGBAPixel_ui Gan_RGBAPixel_ui32;
00335 #else
00336 #error "32-bit type conflict"
00337 #endif
00338
00339 #if (SIZEOF_FLOAT == 4)
00340
00344 typedef struct Gan_GLAPixel_f Gan_GLAPixel_f32;
00345
00349 typedef struct Gan_RGBPixel_f Gan_RGBPixel_f32;
00350
00355 typedef struct Gan_RGBAPixel_f Gan_RGBAPixel_f32;
00356 #else
00357 #error "32-bit float type conflict"
00358 #endif
00359
00360 #if (SIZEOF_DOUBLE == 8)
00361
00365 typedef struct Gan_GLAPixel_d Gan_GLAPixel_f64;
00366
00370 typedef struct Gan_RGBPixel_d Gan_RGBPixel_f64;
00371
00376 typedef struct Gan_RGBAPixel_d Gan_RGBAPixel_f64;
00377 #else
00378 #error "64-bit float type conflict"
00379 #endif
00380
00384 typedef struct Gan_Pixel
00385 {
00387 Gan_ImageFormat format;
00388
00390 Gan_Type type;
00391
00393 union
00394 {
00396 union
00397 {
00398 unsigned char uc;
00399 short s;
00400 unsigned short us;
00401 int i;
00402 unsigned int ui;
00403 double d;
00404 float f;
00405 Gan_Bool b;
00406 void *p;
00407
00408 gan_uint8 ui8;
00409 gan_uint16 ui16;
00410 gan_uint32 ui32;
00411 } gl;
00412
00414 union
00415 {
00416 Gan_GLAPixel_uc uc;
00417 Gan_GLAPixel_s s;
00418 Gan_GLAPixel_us us;
00419 Gan_GLAPixel_i i;
00420 Gan_GLAPixel_ui ui;
00421 Gan_GLAPixel_d d;
00422 Gan_GLAPixel_f f;
00423
00424 Gan_GLAPixel_ui8 ui8;
00425 Gan_GLAPixel_ui16 ui16;
00426 Gan_GLAPixel_ui32 ui32;
00427 } gla;
00428
00430 union
00431 {
00432 Gan_RGBPixel_uc uc;
00433 Gan_RGBPixel_s s;
00434 Gan_RGBPixel_us us;
00435 Gan_RGBPixel_i i;
00436 Gan_RGBPixel_ui ui;
00437 Gan_RGBPixel_d d;
00438 Gan_RGBPixel_f f;
00439
00440 Gan_RGBPixel_ui8 ui8;
00441 Gan_RGBPixel_ui16 ui16;
00442 Gan_RGBPixel_ui32 ui32;
00443 } rgb;
00444
00446 union
00447 {
00448 Gan_RGBAPixel_uc uc;
00449 Gan_RGBAPixel_s s;
00450 Gan_RGBAPixel_us us;
00451 Gan_RGBAPixel_i i;
00452 Gan_RGBAPixel_ui ui;
00453 Gan_RGBAPixel_d d;
00454 Gan_RGBAPixel_f f;
00455
00456 Gan_RGBAPixel_ui8 ui8;
00457 Gan_RGBAPixel_ui16 ui16;
00458 Gan_RGBAPixel_ui32 ui32;
00459 } rgba;
00460
00462 union
00463 {
00464 Gan_Vector2_f f;
00465 Gan_Vector2 d;
00466 Gan_Vector2_s s;
00467 Gan_Vector2_i i;
00468 } vfield2D;
00469
00471 union
00472 {
00473 Gan_Vector3_f f;
00474 Gan_Vector3 d;
00475 Gan_Vector3_s s;
00476 Gan_Vector3_i i;
00477 } vfield3D;
00478 } data;
00479 } Gan_Pixel;
00480
00481 unsigned char gan_pixel_rgbuc_to_yuc ( const Gan_RGBPixel_uc *rgb );
00482 unsigned short gan_pixel_rgbuc_to_yus ( const Gan_RGBPixel_uc *rgb );
00483 unsigned int gan_pixel_rgbuc_to_yui ( const Gan_RGBPixel_uc *rgb );
00484 unsigned char gan_pixel_rgbus_to_yuc ( const Gan_RGBPixel_us *rgb );
00485 unsigned short gan_pixel_rgbus_to_yus ( const Gan_RGBPixel_us *rgb );
00486 float gan_pixel_rgbui_to_yf ( const Gan_RGBPixel_ui *rgb );
00487 float gan_pixel_rgbf_to_yf ( const Gan_RGBPixel_f *rgb );
00488 double gan_pixel_rgbd_to_yd ( const Gan_RGBPixel_d *rgb );
00489 unsigned char gan_pixel_rgbauc_to_yuc ( const Gan_RGBAPixel_uc *rgba );
00490 unsigned short gan_pixel_rgbauc_to_yus ( const Gan_RGBAPixel_uc *rgba );
00491 unsigned int gan_pixel_rgbauc_to_yui ( const Gan_RGBAPixel_uc *rgba );
00492 unsigned char gan_pixel_rgbaus_to_yuc ( const Gan_RGBAPixel_us *rgba );
00493 unsigned short gan_pixel_rgbaus_to_yus ( const Gan_RGBAPixel_us *rgba );
00494 float gan_pixel_rgbaui_to_yf ( const Gan_RGBAPixel_ui *rgba );
00495 float gan_pixel_rgbaf_to_yf ( const Gan_RGBAPixel_f *rgba );
00496 double gan_pixel_rgbad_to_yd ( const Gan_RGBAPixel_d *rgba );
00497
00498 Gan_Bool gan_image_convert_pixel ( Gan_Pixel *inpix,
00499 Gan_ImageFormat format, Gan_Type type,
00500 Gan_Pixel *outpix, int *error_code );
00501 double gan_image_convert_scale ( Gan_Type gtFromType, Gan_Type gtToType );
00502 Gan_Bool gan_image_offset_pixel_q ( Gan_Pixel *pixel, double offset,
00503 Gan_Pixel *offset_pixel );
00504 Gan_Bool gan_image_scale_pixel_q ( Gan_Pixel *pixel, double scale,
00505 Gan_Pixel *scaled_pixel );
00506 Gan_Bool gan_image_divide_pixel_q ( Gan_Pixel *pixel, double scale,
00507 Gan_Pixel *scaled_pixel );
00508 Gan_Bool gan_image_fill_zero_pixel ( Gan_Pixel *pixel );
00509
00513 unsigned char gan_pixel_us_to_uc ( unsigned short x );
00514
00518 unsigned char gan_pixel_ui_to_uc ( unsigned x );
00519
00525 unsigned char gan_pixel_f_to_uc ( float x );
00526
00532 unsigned char gan_pixel_d_to_uc ( double x );
00533
00537 unsigned short gan_pixel_uc_to_us ( unsigned char x );
00538
00542 unsigned short gan_pixel_ui_to_us ( unsigned x );
00543
00547 short gan_pixel_i_to_s ( int x );
00548
00554 unsigned short gan_pixel_f_to_us ( float x );
00555
00561 unsigned short gan_pixel_d_to_us ( double x );
00562
00566 unsigned int gan_pixel_uc_to_ui ( unsigned char x );
00567
00571 unsigned int gan_pixel_us_to_ui ( unsigned short x );
00572
00576 int gan_pixel_s_to_i ( short x );
00577
00583 unsigned int gan_pixel_f_to_ui ( float x );
00584
00590 unsigned int gan_pixel_d_to_ui ( double x );
00591
00592 extern float lookup_table_8bit[];
00593
00594
00595
00596
00597 float gan_pixel_uc_to_f ( unsigned char x );
00598
00602 float gan_pixel_us_to_f ( unsigned short x );
00603
00607 float gan_pixel_ui_to_f ( unsigned int x );
00608
00612 double gan_pixel_uc_to_d ( unsigned char x );
00613
00617 double gan_pixel_us_to_d ( unsigned short x );
00618
00622 double gan_pixel_ui_to_d ( unsigned int x );
00623
00629 int gan_pixel_f_to_i ( float x );
00630
00636 int gan_pixel_d_to_i ( double x );
00637
00643 short gan_pixel_f_to_s ( float x );
00644
00650 short gan_pixel_d_to_s ( double x );
00651
00655 float gan_pixel_s_to_f ( short x );
00656
00660 double gan_pixel_s_to_d ( short x );
00661
00665 float gan_pixel_i_to_f ( int x );
00666
00670 double gan_pixel_i_to_d ( int x );
00671
00672
00673 #if (SIZEOF_CHAR == 1)
00674
00676 int gan_pixel_f_to_ui8 ( float x );
00677
00679 int gan_pixel_d_to_ui8 ( double x );
00680
00682 float gan_pixel_ui8_to_f ( gan_uint8 x );
00683
00685 double gan_pixel_ui8_to_d ( gan_uint8 x );
00686
00687 #endif
00688
00689
00690 #if (SIZEOF_SHORT == 2)
00691
00693 int gan_pixel_f_to_ui16 ( float x );
00694
00696 int gan_pixel_d_to_ui16 ( double x );
00697
00699 float gan_pixel_ui16_to_f ( gan_uint16 x );
00700
00702 double gan_pixel_ui16_to_d ( gan_uint16 x );
00703
00704 #endif
00705
00706
00707 #if (SIZEOF_INT == 4)
00708
00710 int gan_pixel_f_to_ui32 ( float x );
00711
00713 int gan_pixel_d_to_ui32 ( double x );
00714
00716 float gan_pixel_ui32_to_f ( gan_uint32 x );
00717
00719 double gan_pixel_ui32_to_d ( gan_uint32 x );
00720
00721 #endif
00722
00730 Gan_Bool gan_image_convert_pixel_q ( Gan_Pixel *inpix,
00731 Gan_ImageFormat format, Gan_Type type,
00732 Gan_Pixel *outpix );
00733
00741 Gan_Bool gan_image_convert_pixel_i ( Gan_Pixel *pix,
00742 Gan_ImageFormat format, Gan_Type type );
00743
00751 Gan_Bool gan_image_offset_pixel_i ( Gan_Pixel *pixel, double offset );
00752
00760 Gan_Bool gan_image_scale_pixel_i ( Gan_Pixel *pixel, double scale );
00761
00769 Gan_Bool gan_image_divide_pixel_i ( Gan_Pixel *pixel, double scale );
00770
00779 #ifdef __cplusplus
00780 }
00781 #endif
00782
00783 #endif