You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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