Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

130 wiersze
4.1 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;
  33. int x;
  34. cv = cucul_create_canvas(0, 0);
  35. if(cv == NULL)
  36. {
  37. printf("Can't created canvas\n");
  38. return -1;
  39. }
  40. dp = caca_create_display(cv);
  41. if(dp == NULL)
  42. {
  43. printf("Can't create display\n");
  44. return -1;
  45. }
  46. cw = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  47. mask = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  48. for(x = 0; x < 256; x++)
  49. {
  50. buffer[x] = (x << 16) | (x << 8) | (x<< 0);
  51. buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0);
  52. buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0);
  53. buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
  54. }
  55. left = cucul_create_dither(32, 256, 4, 4 * 256,
  56. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  57. right = cucul_create_dither(32, 256, 4, 4 * 256,
  58. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  59. gam = cucul_get_dither_gamma(right);
  60. caca_set_display_time(dp, 20000);
  61. for(x = 0; ; x++)
  62. {
  63. int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
  64. if(ret)
  65. {
  66. if(ev.data.key.ch == CACA_KEY_LEFT)
  67. gam /= 1.03;
  68. else if(ev.data.key.ch == CACA_KEY_RIGHT)
  69. gam *= 1.03;
  70. else if(ev.data.key.ch == CACA_KEY_DOWN)
  71. gam = 1.0;
  72. else if(ev.data.key.ch == CACA_KEY_ESCAPE)
  73. break;
  74. }
  75. /* Resize the spare canvas, just in case the main one changed */
  76. cucul_set_canvas_size(cw, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  77. cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  78. /* Draw the regular dither on the main canvas */
  79. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  80. cucul_get_canvas_height(cv), left, buffer);
  81. /* Draw the gamma-modified dither on the spare canvas */
  82. cucul_set_dither_gamma(right, gam);
  83. cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw),
  84. cucul_get_canvas_height(cw), right, buffer);
  85. /* Draw something on the mask */
  86. cucul_set_color_ansi(mask, CUCUL_LIGHTGRAY, CUCUL_BLACK);
  87. cucul_clear_canvas(mask);
  88. cucul_set_color_ansi(mask, CUCUL_WHITE, CUCUL_WHITE);
  89. cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
  90. * 0.5 * cucul_get_canvas_width(mask),
  91. (1.0 + cos(0.05 * (float)x))
  92. * 0.5 * cucul_get_canvas_height(mask),
  93. cucul_get_canvas_width(mask) / 2,
  94. cucul_get_canvas_height(mask) / 2, '#');
  95. /* Blit the spare canvas onto the first one */
  96. cucul_blit(cv, 0, 0, cw, mask);
  97. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
  98. cucul_printf(cv, 2, 1,
  99. "gamma=%g - use arrows to change, Esc to quit", gam);
  100. caca_refresh_display(dp);
  101. }
  102. cucul_free_dither(left);
  103. cucul_free_dither(right);
  104. caca_free_display(dp);
  105. cucul_free_canvas(cv);
  106. return 0;
  107. }