Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

88 linhas
2.4 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. * jajuni.c: Jarvis-Judice-Ninke dithering functions
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include "pipi.h"
  20. #include "pipi_internals.h"
  21. pipi_image_t *pipi_dither_jajuni(pipi_image_t *img, pipi_scan_t scan)
  22. {
  23. pipi_image_t *dst;
  24. pipi_pixels_t *dstp;
  25. float *dstdata;
  26. int x, y, w, h;
  27. w = img->w;
  28. h = img->h;
  29. dst = pipi_copy(img);
  30. dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
  31. dstdata = (float *)dstp->pixels;
  32. for(y = 0; y < h; y++)
  33. {
  34. int reverse = (y & 1) && (scan == PIPI_SCAN_SERPENTINE);
  35. for(x = 0; x < w; x++)
  36. {
  37. float p, q, e;
  38. int x2 = reverse ? w - 1 - x : x;
  39. int s = reverse ? -1 : 1;
  40. p = dstdata[y * w + x2];
  41. q = p < 0.5 ? 0. : 1.;
  42. dstdata[y * w + x2] = q;
  43. e = (p - q) / 48.;
  44. if(x < w - 1)
  45. dstdata[y * w + x2 + s] += e * 7;
  46. if(x < w - 2)
  47. dstdata[y * w + x2 + s + s] += e * 5;
  48. if(y < h - 1)
  49. {
  50. if(x > 1)
  51. dstdata[(y + 1) * w + x2 - s - s] += e * 3;
  52. if(x > 0)
  53. dstdata[(y + 1) * w + x2 - s] += e * 5;
  54. dstdata[(y + 1) * w + x2] += e * 7;
  55. if(x < w - 1)
  56. dstdata[(y + 1) * w + x2 + s] += e * 5;
  57. if(x < w - 2)
  58. dstdata[(y + 1) * w + x2 + s + s] += e * 3;
  59. }
  60. if(y < h - 2)
  61. {
  62. if(x > 1)
  63. dstdata[(y + 2) * w + x2 - s - s] += e;
  64. if(x > 0)
  65. dstdata[(y + 2) * w + x2 - s] += e * 3;
  66. dstdata[(y + 2) * w + x2] += e * 5;
  67. if(x < w - 1)
  68. dstdata[(y + 2) * w + x2 + s] += e * 3;
  69. if(x < w - 2)
  70. dstdata[(y + 2) * w + x2 + s + s] += e;
  71. }
  72. }
  73. }
  74. return dst;
  75. }