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 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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; you can redistribute it and/or
  9. * modify it under the terms of the Do What The Fuck You Want To
  10. * Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. #include "config.h"
  14. #include "common.h"
  15. #if defined(HAVE_INTTYPES_H)
  16. # include <inttypes.h>
  17. #endif
  18. #if !defined(__KERNEL__)
  19. # include <stdio.h>
  20. # include <math.h>
  21. #endif
  22. #include "cucul.h"
  23. #include "caca.h"
  24. uint32_t buffer[256 * 4];
  25. int main(void)
  26. {
  27. caca_event_t ev;
  28. cucul_canvas_t *cv, *cw, *mask;
  29. caca_display_t *dp;
  30. cucul_dither_t *left, *right;
  31. float gam = 1.0;
  32. int x;
  33. cv = cucul_create_canvas(0, 0);
  34. dp = caca_create_display(cv);
  35. cw = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  36. mask = cucul_create_canvas(cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  37. for(x = 0; x < 256; x++)
  38. {
  39. buffer[x] = (x << 16) | (x << 8) | (x<< 0);
  40. buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0);
  41. buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0);
  42. buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
  43. }
  44. left = cucul_create_dither(32, 256, 4, 4 * 256,
  45. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  46. right = cucul_create_dither(32, 256, 4, 4 * 256,
  47. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  48. caca_set_display_time(dp, 20000);
  49. for(x = 0; ; x++)
  50. {
  51. int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
  52. if(ret)
  53. {
  54. if(ev.data.key.ch == CACA_KEY_LEFT)
  55. gam /= 1.03;
  56. else if(ev.data.key.ch == CACA_KEY_RIGHT)
  57. gam *= 1.03;
  58. else if(ev.data.key.ch == CACA_KEY_DOWN)
  59. gam = 1.0;
  60. else if(ev.data.key.ch == CACA_KEY_ESCAPE)
  61. break;
  62. }
  63. /* Resize the spare canvas, just in case the main one changed */
  64. cucul_set_canvas_size(cw, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  65. cucul_set_canvas_size(mask, cucul_get_canvas_width(cv), cucul_get_canvas_height(cv));
  66. /* Draw the regular dither on the main canvas */
  67. cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
  68. cucul_get_canvas_height(cv), left, buffer);
  69. /* Draw the gamma-modified dither on the spare canvas */
  70. cucul_set_dither_gamma(right, gam);
  71. cucul_dither_bitmap(cw, 0, 0, cucul_get_canvas_width(cw),
  72. cucul_get_canvas_height(cw), right, buffer);
  73. /* Draw something on the mask */
  74. cucul_set_color(cv, CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_BLACK);
  75. cucul_clear_canvas(mask);
  76. cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE);
  77. cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
  78. * 0.5 * cucul_get_canvas_width(mask),
  79. (1.0 + cos(0.05 * (float)x))
  80. * 0.5 * cucul_get_canvas_height(mask),
  81. cucul_get_canvas_width(mask) / 2,
  82. cucul_get_canvas_height(mask) / 2, "#");
  83. /* Blit the spare canvas onto the first one */
  84. cucul_blit(cv, 0, 0, cw, mask);
  85. cucul_set_color(cv, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  86. cucul_printf(cv, 2, 1,
  87. "gamma=%g - use arrows to change, Esc to quit", gam);
  88. caca_refresh_display(dp);
  89. }
  90. cucul_free_dither(left);
  91. cucul_free_dither(right);
  92. caca_free_display(dp);
  93. cucul_free_canvas(cv);
  94. return 0;
  95. }