No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

119 líneas
3.9 KiB

  1. /*
  2. * gamma libcucul gamma test program
  3. * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This program 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. #include "config.h"
  15. #include "common.h"
  16. #if !defined(__KERNEL__)
  17. # if defined(HAVE_INTTYPES_H)
  18. # include <inttypes.h>
  19. # endif
  20. # include <stdio.h>
  21. # include <math.h>
  22. #endif
  23. #include "cucul.h"
  24. #include "caca.h"
  25. uint32_t buffer[256 * 4];
  26. int main(int argc, char *argv[])
  27. {
  28. caca_event_t ev;
  29. cucul_canvas_t *cv, *cw, *mask;
  30. caca_display_t *dp;
  31. cucul_dither_t *left, *right;
  32. float gam = 1.0;
  33. int x;
  34. cv = cucul_create_canvas(0, 0);
  35. dp = caca_create_display(cv);
  36. cw = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  37. mask = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  38. for(x = 0; x < 256; x++)
  39. {
  40. buffer[x] = (x << 16) | (x << 8) | (x<< 0);
  41. buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0);
  42. buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0);
  43. buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
  44. }
  45. left = cucul_create_dither(32, 256, 4, 4 * 256,
  46. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  47. right = cucul_create_dither(32, 256, 4, 4 * 256,
  48. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  49. caca_set_display_time(dp, 20000);
  50. for(x = 0; ; x++)
  51. {
  52. int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
  53. if(ret)
  54. {
  55. if(ev.data.key.ch == CACA_KEY_LEFT)
  56. gam /= 1.03;
  57. else if(ev.data.key.ch == CACA_KEY_RIGHT)
  58. gam *= 1.03;
  59. else if(ev.data.key.ch == CACA_KEY_DOWN)
  60. gam = 1.0;
  61. else if(ev.data.key.ch == CACA_KEY_ESCAPE)
  62. break;
  63. }
  64. /* Resize the spare canvas, just in case the main one changed */
  65. cucul_set_canvas_size(cw, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  66. cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  67. /* Draw the regular dither on the main canvas */
  68. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  69. cucul_get_canvas_height(cv), left, buffer);
  70. /* Draw the gamma-modified dither on the spare canvas */
  71. cucul_set_dither_gamma(right, gam);
  72. cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw),
  73. cucul_get_canvas_height(cw), right, buffer);
  74. /* Draw something on the mask */
  75. cucul_set_color_ansi(mask, CUCUL_LIGHTGRAY, CUCUL_BLACK);
  76. cucul_clear_canvas(mask);
  77. cucul_set_color_ansi(mask, CUCUL_WHITE, CUCUL_WHITE);
  78. cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
  79. * 0.5 * cucul_get_canvas_width(mask),
  80. (1.0 + cos(0.05 * (float)x))
  81. * 0.5 * cucul_get_canvas_height(mask),
  82. cucul_get_canvas_width(mask) / 2,
  83. cucul_get_canvas_height(mask) / 2, '#');
  84. /* Blit the spare canvas onto the first one */
  85. cucul_blit(cv, 0, 0, cw, mask);
  86. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
  87. cucul_printf(cv, 2, 1,
  88. "gamma=%g - use arrows to change, Esc to quit", gam);
  89. caca_refresh_display(dp);
  90. }
  91. cucul_free_dither(left);
  92. cucul_free_dither(right);
  93. caca_free_display(dp);
  94. cucul_free_canvas(cv);
  95. return 0;
  96. }