Changeset 2247 for libpipi/trunk/pipi/pixels.c
- Timestamp:
- 02/27/08 01:41:32 (5 years ago)
- File:
-
- 1 edited
-
libpipi/trunk/pipi/pixels.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libpipi/trunk/pipi/pixels.c
r2228 r2247 17 17 */ 18 18 19 #include "config.h" 20 #include "common.h" 21 19 22 #include <stdio.h> 20 23 #include <stdlib.h> 21 24 #include <string.h> 22 25 23 #include "config.h" 24 #include "common.h" 26 #include <math.h> 25 27 26 28 #include "pipi_internals.h" 27 29 #include "pipi.h" 30 31 #define C2I(p) ((int)255.999*pow(((double)p)/255., 2.2)) 32 #define I2C(p) ((int)255.999*pow(((double)p)/255., 1./2.2)) 28 33 29 34 int pipi_getgray(pipi_image_t const *img, int x, int y, int *g) … … 43 48 int x, int y, int *r, int *g, int *b) 44 49 { 50 uint8_t *pixel; 51 45 52 if(x < 0 || y < 0 || x >= img->width || y >= img->height) 46 53 { … … 51 58 } 52 59 53 *b = (unsigned char)img->pixels[y * img->pitch + x * img->channels]; 54 *g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1]; 55 *r = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 2]; 60 pixel = img->pixels + y * img->pitch + x * img->channels; 61 62 *b = C2I((unsigned char)pixel[0]); 63 *g = C2I((unsigned char)pixel[1]); 64 *r = C2I((unsigned char)pixel[2]); 56 65 57 66 return 0; … … 60 69 int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b) 61 70 { 71 uint8_t *pixel; 72 62 73 if(x < 0 || y < 0 || x >= img->width || y >= img->height) 63 74 return -1; 64 75 65 img->pixels[y * img->pitch + x * img->channels] = b; 66 img->pixels[y * img->pitch + x * img->channels + 1] = g; 67 img->pixels[y * img->pitch + x * img->channels + 2] = r; 76 pixel = img->pixels + y * img->pitch + x * img->channels; 77 78 pixel[0] = I2C(b); 79 pixel[1] = I2C(g); 80 pixel[2] = I2C(r); 68 81 69 82 return 0;
Note: See TracChangeset
for help on using the changeset viewer.
