git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2765 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
@@ -25,6 +25,7 @@ libpipi_la_SOURCES = \ | |||||
measure.c \ | measure.c \ | ||||
$(codec_sources) \ | $(codec_sources) \ | ||||
$(paint_sources) \ | $(paint_sources) \ | ||||
$(render_sources) \ | |||||
$(combine_sources) \ | $(combine_sources) \ | ||||
$(filter_sources) \ | $(filter_sources) \ | ||||
$(quantize_sources) \ | $(quantize_sources) \ | ||||
@@ -44,6 +45,10 @@ paint_sources = \ | |||||
paint/floodfill.c \ | paint/floodfill.c \ | ||||
paint/tile.c | paint/tile.c | ||||
render_sources = \ | |||||
render/noise.c \ | |||||
render/screen.c | |||||
combine_sources = \ | combine_sources = \ | ||||
combine/rgb.c \ | combine/rgb.c \ | ||||
combine/mean.c \ | combine/mean.c \ | ||||
@@ -105,6 +105,9 @@ extern double pipi_measure_rmsd(pipi_image_t *, pipi_image_t *); | |||||
extern pipi_image_t *pipi_resize(pipi_image_t *, int, int); | extern pipi_image_t *pipi_resize(pipi_image_t *, int, int); | ||||
extern pipi_image_t *pipi_render_random(int, int); | |||||
extern pipi_image_t *pipi_render_bayer(int, int); | |||||
extern pipi_image_t *pipi_rgb(pipi_image_t *, pipi_image_t *, pipi_image_t *); | extern pipi_image_t *pipi_rgb(pipi_image_t *, pipi_image_t *, pipi_image_t *); | ||||
extern pipi_image_t *pipi_red(pipi_image_t *); | extern pipi_image_t *pipi_red(pipi_image_t *); | ||||
extern pipi_image_t *pipi_green(pipi_image_t *); | extern pipi_image_t *pipi_green(pipi_image_t *); | ||||
@@ -0,0 +1,62 @@ | |||||
/* | |||||
* libpipi Proper image processing implementation library | |||||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id$ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
* noise.c: noise rendering functions | |||||
*/ | |||||
#include "config.h" | |||||
#include "common.h" | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include "pipi.h" | |||||
#include "pipi_internals.h" | |||||
pipi_image_t *pipi_render_random(int w, int h) | |||||
{ | |||||
pipi_image_t *ret; | |||||
pipi_pixels_t *pix; | |||||
float *data; | |||||
unsigned int ctx = 1; | |||||
int x, y, t; | |||||
ret = pipi_new(w, h); | |||||
pix = pipi_getpixels(ret, PIPI_PIXELS_RGBA_F); | |||||
data = (float *)pix->pixels; | |||||
for(y = 0; y < h; y++) | |||||
for(x = 0; x < w; x++) | |||||
{ | |||||
for(t = 0; t < 3; t++) | |||||
{ | |||||
long hi, lo; | |||||
hi = ctx / 12773L; | |||||
lo = ctx % 12773L; | |||||
ctx = 16807L * lo - 2836L * hi; | |||||
if(ctx <= 0) | |||||
ctx += 0x7fffffffL; | |||||
data[4 * (y * w + x) + t] | |||||
= (double)((ctx % 65536) / 65535.); | |||||
} | |||||
data[4 * (y * w + x) + 3] = 1.0; | |||||
} | |||||
return ret; | |||||
} | |||||
@@ -0,0 +1,66 @@ | |||||
/* | |||||
* libpipi Proper image processing implementation library | |||||
* Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org> | |||||
* All Rights Reserved | |||||
* | |||||
* $Id$ | |||||
* | |||||
* This library is free software. It comes without any warranty, to | |||||
* the extent permitted by applicable law. You can redistribute it | |||||
* and/or modify it under the terms of the Do What The Fuck You Want | |||||
* To Public License, Version 2, as published by Sam Hocevar. See | |||||
* http://sam.zoy.org/wtfpl/COPYING for more details. | |||||
*/ | |||||
/* | |||||
* screen.c: halftoning screen functions | |||||
*/ | |||||
#include "config.h" | |||||
#include "common.h" | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include "pipi.h" | |||||
#include "pipi_internals.h" | |||||
pipi_image_t *pipi_render_bayer(int w, int h) | |||||
{ | |||||
pipi_image_t *ret; | |||||
pipi_pixels_t *pix; | |||||
float *data; | |||||
int i, j, n; | |||||
if(w <= 0 || h <= 0) | |||||
return NULL; | |||||
for(n = 1; n < w || n < h; n *= 2) | |||||
; | |||||
ret = pipi_new(w, h); | |||||
pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F); | |||||
data = (float *)pix->pixels; | |||||
for(j = 0; j < h; j++) | |||||
for(i = 0; i < w; i++) | |||||
{ | |||||
int k, l, x = 0; | |||||
for(k = 1, l = n * n / 4; k < n; k *= 2, l /= 4) | |||||
{ | |||||
if((i & k) && (j & k)) | |||||
x += l; | |||||
else if(i & k) | |||||
x += 3 * l; | |||||
else if(j & k) | |||||
x += 2 * l; | |||||
} | |||||
data[j * w + i] = (double)(x + 1) / (n * n + 1); | |||||
} | |||||
return ret; | |||||
} | |||||
@@ -35,42 +35,15 @@ pipi_image_t *pipi_load_stock(char const *name) | |||||
/* Generate a Bayer dithering pattern. */ | /* Generate a Bayer dithering pattern. */ | ||||
if(!strncmp(name, "bayer:", 6)) | if(!strncmp(name, "bayer:", 6)) | ||||
{ | { | ||||
int i, j, w, h, n; | |||||
int w, h; | |||||
w = atoi(name + 6); | w = atoi(name + 6); | ||||
name = strchr(name + 6, 'x'); | name = strchr(name + 6, 'x'); | ||||
if(!name) | if(!name) | ||||
return NULL; | return NULL; | ||||
h = atoi(name + 1); | h = atoi(name + 1); | ||||
if(w <= 0 || h <= 0) | |||||
return NULL; | |||||
for(n = 1; n < w || n < h; n *= 2) | |||||
; | |||||
ret = pipi_new(w, h); | |||||
pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F); | |||||
data = (float *)pix->pixels; | |||||
for(j = 0; j < h; j++) | |||||
for(i = 0; i < w; i++) | |||||
{ | |||||
int k, l, x = 0; | |||||
for(k = 1, l = n * n / 4; k < n; k *= 2, l /= 4) | |||||
{ | |||||
if((i & k) && (j & k)) | |||||
x += l; | |||||
else if(i & k) | |||||
x += 3 * l; | |||||
else if(j & k) | |||||
x += 2 * l; | |||||
} | |||||
data[j * w + i] = (double)(x + 1) / (n * n + 1); | |||||
} | |||||
return ret; | |||||
return pipi_render_bayer(w, h); | |||||
} | } | ||||
/* Generate an error diffusion matrix. */ | /* Generate an error diffusion matrix. */ | ||||
@@ -195,8 +168,7 @@ pipi_image_t *pipi_load_stock(char const *name) | |||||
/* Generate a completely random image. */ | /* Generate a completely random image. */ | ||||
if(!strncmp(name, "random:", 7)) | if(!strncmp(name, "random:", 7)) | ||||
{ | { | ||||
unsigned int ctx = 1; | |||||
int x, y, t, w, h; | |||||
int w, h; | |||||
w = atoi(name + 7); | w = atoi(name + 7); | ||||
name = strchr(name + 7, 'x'); | name = strchr(name + 7, 'x'); | ||||
@@ -206,30 +178,7 @@ pipi_image_t *pipi_load_stock(char const *name) | |||||
if(w <= 0 || h <= 0) | if(w <= 0 || h <= 0) | ||||
return NULL; | return NULL; | ||||
ret = pipi_new(w, h); | |||||
pix = pipi_getpixels(ret, PIPI_PIXELS_RGBA_F); | |||||
data = (float *)pix->pixels; | |||||
for(y = 0; y < h; y++) | |||||
for(x = 0; x < w; x++) | |||||
{ | |||||
for(t = 0; t < 3; t++) | |||||
{ | |||||
long hi, lo; | |||||
hi = ctx / 12773L; | |||||
lo = ctx % 12773L; | |||||
ctx = 16807L * lo - 2836L * hi; | |||||
if(ctx <= 0) | |||||
ctx += 0x7fffffffL; | |||||
data[4 * (y * w + x) + t] | |||||
= (double)((ctx % 65536) / 65535.); | |||||
} | |||||
data[4 * (y * w + x) + 3] = 1.0; | |||||
} | |||||
return ret; | |||||
return pipi_render_random(w, h); | |||||
} | } | ||||
return NULL; | return NULL; | ||||