Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

103 righe
3.1 KiB

  1. /*
  2. * libee ASCII-Art library
  3. * Copyright (c) 2002, 2003 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include "config.h"
  23. #ifdef HAVE_INTTYPES_H
  24. # include <inttypes.h>
  25. #else
  26. typedef unsigned char uint8_t;
  27. #endif
  28. #include <stdlib.h>
  29. #include "ee.h"
  30. #include "ee_internals.h"
  31. #include <stdio.h>
  32. void ee_blit(int x1, int y1, int x2, int y2, void *pixels, int w, int h)
  33. {
  34. char foo[] = { ' ', '.', ':', ';', '=', '$', '%', '@', '#', '8', 'W' };
  35. int x, y, pitch;
  36. if(x1 > x2)
  37. {
  38. int tmp = x2; x2 = x1; x1 = tmp;
  39. }
  40. if(y1 > y2)
  41. {
  42. int tmp = y2; y2 = y1; y1 = tmp;
  43. }
  44. pitch = (3 * w + 3) / 4 * 4;
  45. for(y = y1 > 0 ? y1 : 0; y <= y2 && y <= ee_get_height(); y++)
  46. for(x = x1 > 0 ? x1 : 0; x <= x2 && x <= ee_get_width(); x++)
  47. {
  48. int fromx = w * (x - x1) / (x2 - x1 + 1);
  49. int fromy = h * (y - y1) / (y2 - y1 + 1);
  50. int r = ((unsigned char *)pixels)[3 * fromx + pitch * fromy];
  51. int g = ((unsigned char *)pixels)[3 * fromx + 1 + pitch * fromy];
  52. int b = ((unsigned char *)pixels)[3 * fromx + 2 + pitch * fromy];
  53. if(r == g && g == b)
  54. {
  55. ee_set_color(EE_LIGHTGRAY);
  56. }
  57. else
  58. {
  59. static int foo_colors[6] = {EE_LIGHTRED, EE_YELLOW, EE_LIGHTGREEN, EE_LIGHTCYAN, EE_LIGHTBLUE, EE_LIGHTMAGENTA};
  60. float min = r, max = r, delta, hue, sat;
  61. if(min > g) min = g; if(max < g) max = g;
  62. if(min > b) min = b; if(max < b) max = b;
  63. delta = max - min;
  64. sat = max / delta;
  65. if(delta > 20)
  66. {
  67. if( r == max )
  68. hue = (g - b) / delta; // between yellow & magenta
  69. else if( g == max )
  70. hue = 2 + (b - r) / delta; // between cyan & yellow
  71. else
  72. hue = 4 + (r - g) / delta; // between magenta & cyan
  73. hue *= 60; // degrees
  74. if( hue < 0 )
  75. hue += 360;
  76. ee_set_color(foo_colors[(int)(hue + 30) / 60]);
  77. }
  78. else
  79. {
  80. ee_set_color(EE_LIGHTGRAY);
  81. }
  82. }
  83. ee_putchar(x, y, foo[(r + g + b) / 3 / 25]);
  84. }
  85. }