You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

187 lines
4.9 KiB

  1. /*
  2. * libpipi Proper image processing implementation library
  3. * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * stock.c: stock images
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "pipi.h"
  23. #include "pipi_internals.h"
  24. pipi_image_t *pipi_load_stock(char const *name)
  25. {
  26. pipi_image_t *ret;
  27. pipi_pixels_t *pix;
  28. float *data;
  29. /* Generate a Bayer dithering pattern. */
  30. if(!strncmp(name, "bayer:", 6))
  31. {
  32. int w, h;
  33. w = atoi(name + 6);
  34. name = strchr(name + 6, 'x');
  35. if(!name)
  36. return NULL;
  37. h = atoi(name + 1);
  38. return pipi_render_bayer(w, h);
  39. }
  40. /* Generate an error diffusion matrix. */
  41. if(!strncmp(name, "ediff:", 6))
  42. {
  43. float const *ker;
  44. int w, h;
  45. if(!strcmp(name + 6, "fs"))
  46. {
  47. static float const myker[] =
  48. {
  49. 0., 1., 7./16,
  50. 3./16, 5./16, 1./16,
  51. };
  52. ker = myker; w = 3; h = 2;
  53. }
  54. else if(!strcmp(name + 6, "jajuni"))
  55. {
  56. static float const myker[] =
  57. {
  58. 0., 0., 1., 7./48, 5./48,
  59. 3./48, 5./48, 7./48, 5./48, 3./48,
  60. 1./48, 3./48, 5./48, 3./48, 1./48,
  61. };
  62. ker = myker; w = 5; h = 3;
  63. }
  64. else if(!strcmp(name + 6, "atkinson"))
  65. {
  66. static float const myker[] =
  67. {
  68. 0., 1., 1./8, 1./8,
  69. 1./8, 1./8, 1./8, 0.,
  70. 0., 1./8, 0., 0.,
  71. };
  72. ker = myker; w = 4; h = 3;
  73. }
  74. else if(!strcmp(name + 6, "fan"))
  75. {
  76. static float const myker[] =
  77. {
  78. 0., 0., 1., 7./16,
  79. 1./16, 3./16, 5./16, 0.,
  80. };
  81. ker = myker; w = 4; h = 2;
  82. }
  83. else if(!strcmp(name + 6, "shiaufan"))
  84. {
  85. static float const myker[] =
  86. {
  87. 0., 0., 1., 1./2,
  88. 1./8, 1./8, 1./4, 0.,
  89. };
  90. ker = myker; w = 4; h = 2;
  91. }
  92. else if(!strcmp(name + 6, "shiaufan2"))
  93. {
  94. static float const myker[] =
  95. {
  96. 0., 0., 0., 1., 1./2,
  97. 1./16, 1./16, 1./8, 1./4, 0.,
  98. };
  99. ker = myker; w = 5; h = 2;
  100. }
  101. else if(!strcmp(name + 6, "stucki"))
  102. {
  103. static float const myker[] =
  104. {
  105. 0., 0., 1., 8./42, 4./42,
  106. 2./42, 4./42, 8./42, 4./42, 2./42,
  107. 1./42, 2./42, 4./42, 2./42, 1./42,
  108. };
  109. ker = myker; w = 5; h = 3;
  110. }
  111. else if(!strcmp(name + 6, "burkes"))
  112. {
  113. static float const myker[] =
  114. {
  115. 0., 0., 1., 4./16, 2./16,
  116. 1./16, 2./16, 4./16, 2./16, 1./16,
  117. };
  118. ker = myker; w = 5; h = 2;
  119. }
  120. else if(!strcmp(name + 6, "sierra"))
  121. {
  122. static float const myker[] =
  123. {
  124. 0., 0., 1., 5./32, 3./32,
  125. 2./32, 4./32, 5./32, 4./32, 2./32,
  126. 0., 2./32, 3./32, 2./32, 0.,
  127. };
  128. ker = myker; w = 5; h = 3;
  129. }
  130. else if(!strcmp(name + 6, "sierra2"))
  131. {
  132. static float const myker[] =
  133. {
  134. 0., 0., 1., 4./16, 3./16,
  135. 1./16, 2./16, 3./16, 2./16, 1./16,
  136. };
  137. ker = myker; w = 5; h = 2;
  138. }
  139. else if(!strcmp(name + 6, "lite"))
  140. {
  141. static float const myker[] =
  142. {
  143. 0., 1., 1./2,
  144. 1./4, 1./4, 0.,
  145. };
  146. ker = myker; w = 3; h = 2;
  147. }
  148. else
  149. return NULL;
  150. ret = pipi_new(w, h);
  151. pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F);
  152. memcpy(pix->pixels, ker, w * h * sizeof(float));
  153. return ret;
  154. }
  155. /* Generate a completely random image. */
  156. if(!strncmp(name, "random:", 7))
  157. {
  158. int w, h;
  159. w = atoi(name + 7);
  160. name = strchr(name + 7, 'x');
  161. if(!name)
  162. return NULL;
  163. h = atoi(name + 1);
  164. if(w <= 0 || h <= 0)
  165. return NULL;
  166. return pipi_render_random(w, h);
  167. }
  168. return NULL;
  169. }