25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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