From 3014994c61fe0ccec2c04f3ffbceccc766579254 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 11 Aug 2008 20:02:10 +0000 Subject: [PATCH] * codec.c: support for stock images in pipi_load(). * stock.c: start working on stock image generation; for instance: pipi pipi:bayer64 -o image.png will generate a 64x64 Bayer dithering pattern and save it to image.png. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2695 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/Makefile.am | 1 + pipi/codec.c | 12 ++++++--- pipi/pipi.h | 3 ++- pipi/stock.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 pipi/stock.c 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; +} +