diff --git a/pipi/Makefile.am b/pipi/Makefile.am index d98ac6f..5051d02 100644 --- a/pipi/Makefile.am +++ b/pipi/Makefile.am @@ -19,6 +19,7 @@ libpipi_la_SOURCES = \ context.c \ pixels.c \ codec.c \ + stock.c \ resize.c \ dither.c \ measure.c \ diff --git a/pipi/codec.c b/pipi/codec.c index 1395bbb..a2e8f03 100644 --- a/pipi/codec.c +++ b/pipi/codec.c @@ -16,17 +16,21 @@ * codec.c: image I/O functions */ -#include -#include - #include "config.h" #include "common.h" +#include +#include +#include + #include "pipi.h" #include "pipi_internals.h" -pipi_image_t *pipi_load(const char *name) +pipi_image_t *pipi_load(char const *name) { + if(!strncmp(name, "pipi:", 5)) + return pipi_load_stock(name + 5); + #if USE_IMLIB2 return pipi_load_imlib2(name); #elif USE_OPENCV diff --git a/pipi/pipi.h b/pipi/pipi.h index 30bb7a9..e963f8b 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -71,7 +71,8 @@ extern pipi_context_t *pipi_create_context(void); extern void pipi_destroy_context(pipi_context_t *); extern int pipi_command(pipi_context_t *, char const *, ...); -extern pipi_image_t *pipi_load(const char *); +extern pipi_image_t *pipi_load(char const *); +extern pipi_image_t *pipi_load_stock(char const *); extern pipi_image_t *pipi_new(int, int); extern pipi_image_t *pipi_copy(pipi_image_t *); extern void pipi_free(pipi_image_t *); diff --git a/pipi/stock.c b/pipi/stock.c new file mode 100644 index 0000000..cdd7c06 --- /dev/null +++ b/pipi/stock.c @@ -0,0 +1,70 @@ +/* + * libpipi Proper image processing implementation library + * Copyright (c) 2004-2008 Sam Hocevar + * 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. + */ + +/* + * stock.c: stock images + */ + +#include "config.h" +#include "common.h" + +#include +#include +#include + +#include "pipi.h" +#include "pipi_internals.h" + +pipi_image_t *pipi_load_stock(char const *name) +{ + pipi_image_t *ret; + pipi_pixels_t *pix; + float *data; + + /* Generate a Bayer dithering pattern. */ + if(!strncmp(name, "bayer", 5)) + { + int i, j, n = atoi(name + 5); + + if(n <= 0 || (n & (n - 1))) /* is n a power of two? */ + return NULL; + + ret = pipi_new(n, n); + pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F); + data = (float *)pix->pixels; + + for(j = 0; j < n; j++) + for(i = 0; i < n; 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 * n + i] = (double)(x + 1) / (n * n + 1); + } + + return ret; + } + + return NULL; +} +