Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

18 роки тому
18 роки тому
18 роки тому
18 роки тому
18 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. 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. caca_set_display_time(dp, 20000);
  60. for(x = 0; ; x++)
  61. {
  62. int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
  63. if(ret)
  64. {
  65. if(ev.data.key.ch == CACA_KEY_LEFT)
  66. gam /= 1.03;
  67. else if(ev.data.key.ch == CACA_KEY_RIGHT)
  68. gam *= 1.03;
  69. else if(ev.data.key.ch == CACA_KEY_DOWN)
  70. gam = 1.0;
  71. else if(ev.data.key.ch == CACA_KEY_ESCAPE)
  72. break;
  73. }
  74. /* Resize the spare canvas, just in case the main one changed */
  75. cucul_set_canvas_size(cw, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  76. cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  77. /* Draw the regular dither on the main canvas */
  78. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  79. cucul_get_canvas_height(cv), left, buffer);
  80. /* Draw the gamma-modified dither on the spare canvas */
  81. cucul_set_dither_gamma(right, gam);
  82. cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw),
  83. cucul_get_canvas_height(cw), right, buffer);
  84. /* Draw something on the mask */
  85. cucul_set_color_ansi(mask, CUCUL_LIGHTGRAY, CUCUL_BLACK);
  86. cucul_clear_canvas(mask);
  87. cucul_set_color_ansi(mask, CUCUL_WHITE, CUCUL_WHITE);
  88. cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
  89. * 0.5 * cucul_get_canvas_width(mask),
  90. (1.0 + cos(0.05 * (float)x))
  91. * 0.5 * cucul_get_canvas_height(mask),
  92. cucul_get_canvas_width(mask) / 2,
  93. cucul_get_canvas_height(mask) / 2, '#');
  94. /* Blit the spare canvas onto the first one */
  95. cucul_blit(cv, 0, 0, cw, mask);
  96. cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
  97. cucul_printf(cv, 2, 1,
  98. "gamma=%g - use arrows to change, Esc to quit", gam);
  99. caca_refresh_display(dp);
  100. }
  101. cucul_free_dither(left);
  102. cucul_free_dither(right);
  103. caca_free_display(dp);
  104. cucul_free_canvas(cv);
  105. return 0;
  106. }