Changeset 2609
- Timestamp:
- Jul 30, 2008, 12:17:43 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/pipi/pixels.c
r2605 r2609 29 29 #include "pipi_internals.h" 30 30 31 #define C2I(p) (pow(((double)p)/255., 2.2)) 32 #define I2C(p) ((int)255.999*pow(((double)p), 1./2.2)) 31 static void init_tables(void); 32 33 static float u8tof32_table[256]; 34 static inline float u8tof32(uint8_t p) { return u8tof32_table[(int)p]; } 35 33 36 34 37 /* Return a direct pointer to an image's pixels. */ … … 69 72 float *dest = (float *)img->p[type].pixels; 70 73 74 init_tables(); 75 71 76 for(y = 0; y < img->h; y++) 72 77 for(x = 0; x < img->w; x++) 73 78 for(i = 0; i < 4; i++) 74 79 dest[4 * (y * img->w + x) + i] 75 = C2I(src[4 * (y * img->w + x) + i]);80 = u8tof32(src[4 * (y * img->w + x) + i]); 76 81 } 77 82 else if(img->last_modified == PIPI_PIXELS_RGBA_F … … 84 89 for(x = 0; x < img->w; x++) 85 90 for(i = 0; i < 4; i++) 91 { 92 double p = src[4 * (y * img->w + x) + i]; 86 93 dest[4 * (y * img->w + x) + i] 87 = I2C(src[4 * (y * img->w + x) + i]); 94 = (int)(255.999 * pow(p, 1. / 2.2)); 95 } 88 96 } 89 97 else … … 97 105 } 98 106 107 108 static void init_tables(void) 109 { 110 static int done = 0; 111 int i; 112 113 if(done) 114 return; 115 116 for(i = 0; i < 256; i++) 117 u8tof32_table[i] = pow((double)i / 255., 2.2); 118 119 done = 1; 120 } 121
Note: See TracChangeset
for help on using the changeset viewer.