Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * dither.c: dithering functions
  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. void pipi_dither_24to16(pipi_image_t *img)
  24. {
  25. /* XXX: disabled because this is not the right place... see pixels.c instead */
  26. #if 0
  27. int *error, *nexterror;
  28. uint32_t *p32;
  29. int x, y;
  30. error = malloc(sizeof(int) * 3 * (img->width + 2));
  31. nexterror = malloc(sizeof(int) * 3 * (img->width + 2));
  32. p32 = (uint32_t *)img->pixels;
  33. memset(error, 0, sizeof(int) * 3 * (img->width + 2));
  34. for(y = 0; y < img->height; y++)
  35. {
  36. int er = 0, eg = 0, eb = 0;
  37. memset(nexterror, 0, sizeof(int) * 3 * (img->width + 2));
  38. for(x = 0; x < img->width; x++)
  39. {
  40. int r, g, b, r2, g2, b2;
  41. r = p32[y * img->width + x] & 0xff;
  42. g = (p32[y * img->width + x] >> 8) & 0xff;
  43. b = (p32[y * img->width + x] >> 16) & 0xff;
  44. r += er + error[x * 3 + 3];
  45. g += eg + error[x * 3 + 4];
  46. b += eb + error[x * 3 + 5];
  47. r2 = r / 8 * 8; g2 = g / 4 * 4; b2 = b / 8 * 8;
  48. if(r2 < 0) r2 = 0; if(r2 > 0xf8) r2 = 0xf8;
  49. if(g2 < 0) g2 = 0; if(g2 > 0xfc) g2 = 0xfc;
  50. if(b2 < 0) b2 = 0; if(b2 > 0xf8) b2 = 0xf8;
  51. /* hack */
  52. if(r2 == 0x88 && g2 == 0x88 && b2 == 0x88) g2 = 0x84;
  53. /* hack */
  54. p32[y * img->width + x] = (b2 << 16) | (g2 << 8) | r2;
  55. er = r - (r2 / 8 * 255 / 31);
  56. eg = g - (g2 / 4 * 255 / 63);
  57. eb = b - (b2 / 8 * 255 / 31);
  58. nexterror[x * 3 + 0] += er * 3 / 8;
  59. nexterror[x * 3 + 1] += eg * 3 / 8;
  60. nexterror[x * 3 + 2] += eb * 3 / 8;
  61. nexterror[x * 3 + 3] += er * 5 / 8;
  62. nexterror[x * 3 + 4] += eg * 5 / 8;
  63. nexterror[x * 3 + 5] += eb * 5 / 8;
  64. nexterror[x * 3 + 6] += er * 1 / 8;
  65. nexterror[x * 3 + 7] += eg * 1 / 8;
  66. nexterror[x * 3 + 8] += eb * 1 / 8;
  67. er -= er * 3 / 8 + er * 7 / 8 + er * 1 / 8;
  68. eg -= eg * 3 / 8 + eg * 7 / 8 + eg * 1 / 8;
  69. eb -= eb * 3 / 8 + eb * 7 / 8 + eb * 1 / 8;
  70. }
  71. memcpy(error, nexterror, sizeof(int) * 3 * (img->width + 2));
  72. }
  73. free(error);
  74. free(nexterror);
  75. #endif
  76. }