|
|
@@ -16,16 +16,21 @@ |
|
|
|
* pixels.c: pixel-level image manipulation |
|
|
|
*/ |
|
|
|
|
|
|
|
#include "config.h" |
|
|
|
#include "common.h" |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
#include "config.h" |
|
|
|
#include "common.h" |
|
|
|
#include <math.h> |
|
|
|
|
|
|
|
#include "pipi_internals.h" |
|
|
|
#include "pipi.h" |
|
|
|
|
|
|
|
#define C2I(p) ((int)255.999*pow(((double)p)/255., 2.2)) |
|
|
|
#define I2C(p) ((int)255.999*pow(((double)p)/255., 1./2.2)) |
|
|
|
|
|
|
|
int pipi_getgray(pipi_image_t const *img, int x, int y, int *g) |
|
|
|
{ |
|
|
|
if(x < 0 || y < 0 || x >= img->width || y >= img->height) |
|
|
@@ -42,6 +47,8 @@ int pipi_getgray(pipi_image_t const *img, int x, int y, int *g) |
|
|
|
int pipi_getpixel(pipi_image_t const *img, |
|
|
|
int x, int y, int *r, int *g, int *b) |
|
|
|
{ |
|
|
|
uint8_t *pixel; |
|
|
|
|
|
|
|
if(x < 0 || y < 0 || x >= img->width || y >= img->height) |
|
|
|
{ |
|
|
|
*r = 255; |
|
|
@@ -50,21 +57,27 @@ int pipi_getpixel(pipi_image_t const *img, |
|
|
|
return -1; |
|
|
|
} |
|
|
|
|
|
|
|
*b = (unsigned char)img->pixels[y * img->pitch + x * img->channels]; |
|
|
|
*g = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 1]; |
|
|
|
*r = (unsigned char)img->pixels[y * img->pitch + x * img->channels + 2]; |
|
|
|
pixel = img->pixels + y * img->pitch + x * img->channels; |
|
|
|
|
|
|
|
*b = C2I((unsigned char)pixel[0]); |
|
|
|
*g = C2I((unsigned char)pixel[1]); |
|
|
|
*r = C2I((unsigned char)pixel[2]); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int pipi_setpixel(pipi_image_t *img, int x, int y, int r, int g, int b) |
|
|
|
{ |
|
|
|
uint8_t *pixel; |
|
|
|
|
|
|
|
if(x < 0 || y < 0 || x >= img->width || y >= img->height) |
|
|
|
return -1; |
|
|
|
|
|
|
|
img->pixels[y * img->pitch + x * img->channels] = b; |
|
|
|
img->pixels[y * img->pitch + x * img->channels + 1] = g; |
|
|
|
img->pixels[y * img->pitch + x * img->channels + 2] = r; |
|
|
|
pixel = img->pixels + y * img->pitch + x * img->channels; |
|
|
|
|
|
|
|
pixel[0] = I2C(b); |
|
|
|
pixel[1] = I2C(g); |
|
|
|
pixel[2] = I2C(r); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|