|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /*
- * 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.
- */
-
- /*
- * stock.c: stock images
- */
-
- #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_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;
- }
-
|