Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

202 рядки
5.2 KiB

  1. /*
  2. * libpipi Pathetic image processing interface 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 <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "pipi.h"
  22. #include "pipi_internals.h"
  23. pipi_image_t *pipi_load_stock(char const *name)
  24. {
  25. pipi_image_t *ret;
  26. pipi_pixels_t *pix;
  27. /* Generate a Bayer dithering pattern. */
  28. if(!strncmp(name, "bayer:", 6))
  29. {
  30. int w, h = 0;
  31. w = atoi(name + 6);
  32. name = strchr(name + 6, 'x');
  33. if(name)
  34. h = atoi(name + 1);
  35. if(!h)
  36. h = w;
  37. return pipi_render_bayer(w, h);
  38. }
  39. /* Generate a clustered dithering pattern. */
  40. if(!strncmp(name, "halftone:", 9))
  41. {
  42. int w, h = 0;
  43. w = atoi(name + 9);
  44. name = strchr(name + 9, 'x');
  45. if(name)
  46. h = atoi(name + 1);
  47. if(!h)
  48. h = w;
  49. return pipi_render_halftone(w, h);
  50. }
  51. /* Generate an error diffusion matrix. */
  52. if(!strncmp(name, "ediff:", 6))
  53. {
  54. float const *ker;
  55. int w, h;
  56. if(!strcmp(name + 6, "fs"))
  57. {
  58. static float const myker[] =
  59. {
  60. 0., 1., 7./16,
  61. 3./16, 5./16, 1./16,
  62. };
  63. ker = myker; w = 3; h = 2;
  64. }
  65. else if(!strcmp(name + 6, "jajuni"))
  66. {
  67. static float const myker[] =
  68. {
  69. 0., 0., 1., 7./48, 5./48,
  70. 3./48, 5./48, 7./48, 5./48, 3./48,
  71. 1./48, 3./48, 5./48, 3./48, 1./48,
  72. };
  73. ker = myker; w = 5; h = 3;
  74. }
  75. else if(!strcmp(name + 6, "atkinson"))
  76. {
  77. static float const myker[] =
  78. {
  79. 0., 1., 1./8, 1./8,
  80. 1./8, 1./8, 1./8, 0.,
  81. 0., 1./8, 0., 0.,
  82. };
  83. ker = myker; w = 4; h = 3;
  84. }
  85. else if(!strcmp(name + 6, "fan"))
  86. {
  87. static float const myker[] =
  88. {
  89. 0., 0., 1., 7./16,
  90. 1./16, 3./16, 5./16, 0.,
  91. };
  92. ker = myker; w = 4; h = 2;
  93. }
  94. else if(!strcmp(name + 6, "shiaufan"))
  95. {
  96. static float const myker[] =
  97. {
  98. 0., 0., 1., 1./2,
  99. 1./8, 1./8, 1./4, 0.,
  100. };
  101. ker = myker; w = 4; h = 2;
  102. }
  103. else if(!strcmp(name + 6, "shiaufan2"))
  104. {
  105. static float const myker[] =
  106. {
  107. 0., 0., 0., 1., 1./2,
  108. 1./16, 1./16, 1./8, 1./4, 0.,
  109. };
  110. ker = myker; w = 5; h = 2;
  111. }
  112. else if(!strcmp(name + 6, "stucki"))
  113. {
  114. static float const myker[] =
  115. {
  116. 0., 0., 1., 8./42, 4./42,
  117. 2./42, 4./42, 8./42, 4./42, 2./42,
  118. 1./42, 2./42, 4./42, 2./42, 1./42,
  119. };
  120. ker = myker; w = 5; h = 3;
  121. }
  122. else if(!strcmp(name + 6, "burkes"))
  123. {
  124. static float const myker[] =
  125. {
  126. 0., 0., 1., 4./16, 2./16,
  127. 1./16, 2./16, 4./16, 2./16, 1./16,
  128. };
  129. ker = myker; w = 5; h = 2;
  130. }
  131. else if(!strcmp(name + 6, "sierra"))
  132. {
  133. static float const myker[] =
  134. {
  135. 0., 0., 1., 5./32, 3./32,
  136. 2./32, 4./32, 5./32, 4./32, 2./32,
  137. 0., 2./32, 3./32, 2./32, 0.,
  138. };
  139. ker = myker; w = 5; h = 3;
  140. }
  141. else if(!strcmp(name + 6, "sierra2"))
  142. {
  143. static float const myker[] =
  144. {
  145. 0., 0., 1., 4./16, 3./16,
  146. 1./16, 2./16, 3./16, 2./16, 1./16,
  147. };
  148. ker = myker; w = 5; h = 2;
  149. }
  150. else if(!strcmp(name + 6, "lite"))
  151. {
  152. static float const myker[] =
  153. {
  154. 0., 1., 1./2,
  155. 1./4, 1./4, 0.,
  156. };
  157. ker = myker; w = 3; h = 2;
  158. }
  159. else
  160. return NULL;
  161. ret = pipi_new(w, h);
  162. pix = pipi_get_pixels(ret, PIPI_PIXELS_Y_F32);
  163. memcpy(pix->pixels, ker, w * h * sizeof(float));
  164. return ret;
  165. }
  166. /* Generate a completely random image. */
  167. if(!strncmp(name, "random:", 7))
  168. {
  169. int w, h = 0;
  170. w = atoi(name + 7);
  171. name = strchr(name + 7, 'x');
  172. if(name)
  173. h = atoi(name + 1);
  174. if(!h)
  175. h = w;
  176. if(w <= 0 || h <= 0)
  177. return NULL;
  178. return pipi_render_random(w, h);
  179. }
  180. return NULL;
  181. }