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

18 роки тому
18 роки тому
18 роки тому
18 роки тому
18 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #if defined(HAVE_INTTYPES_H)
  15. # include <inttypes.h>
  16. #else
  17. typedef unsigned char uint8_t;
  18. typedef unsigned short uint16_t;
  19. typedef unsigned int uint32_t;
  20. #endif
  21. #if !defined(__KERNEL__)
  22. # include <stdio.h>
  23. # include <math.h>
  24. #endif
  25. #include "cucul.h"
  26. #include "caca.h"
  27. uint32_t buffer[256 * 4];
  28. int main(void)
  29. {
  30. caca_event_t ev;
  31. cucul_t *qq, *gg, *mask;
  32. caca_t *kk;
  33. cucul_dither_t *left, *right;
  34. float gam = 1.0;
  35. int x;
  36. qq = cucul_create(0, 0);
  37. kk = caca_attach(qq);
  38. gg = cucul_create(cucul_get_width(qq), cucul_get_height(qq));
  39. mask = cucul_create(cucul_get_width(qq), cucul_get_height(qq));
  40. for(x = 0; x < 256; x++)
  41. {
  42. buffer[x] = (x << 16) | (x << 8) | (x<< 0);
  43. buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0);
  44. buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0);
  45. buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
  46. }
  47. left = cucul_create_dither(32, 256, 4, 4 * 256,
  48. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  49. right = cucul_create_dither(32, 256, 4, 4 * 256,
  50. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  51. caca_set_delay(kk, 20000);
  52. for(x = 0; ; x++)
  53. {
  54. int ret = caca_get_event(kk, CACA_EVENT_KEY_PRESS, &ev, 0);
  55. if(ret)
  56. {
  57. if(ev.data.key.c == CACA_KEY_LEFT)
  58. gam /= 1.03;
  59. else if(ev.data.key.c == CACA_KEY_RIGHT)
  60. gam *= 1.03;
  61. else if(ev.data.key.c == CACA_KEY_DOWN)
  62. gam = 1.0;
  63. else if(ev.data.key.c == CACA_KEY_ESCAPE)
  64. break;
  65. }
  66. /* Resize the spare canvas, just in case the main one changed */
  67. cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq));
  68. cucul_set_size(mask, cucul_get_width(qq), cucul_get_height(qq));
  69. /* Draw the regular dither on the main canvas */
  70. cucul_dither_bitmap(qq, 0, 0,
  71. cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
  72. left, buffer);
  73. /* Draw the gamma-modified dither on the spare canvas */
  74. cucul_set_dither_gamma(right, gam);
  75. cucul_dither_bitmap(gg, 0, 0,
  76. cucul_get_width(gg) - 1, cucul_get_height(gg) - 1,
  77. right, buffer);
  78. /* Draw something on the mask */
  79. cucul_clear(mask);
  80. cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE);
  81. cucul_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
  82. * 0.5 * cucul_get_width(mask),
  83. (1.0 + cos(0.05 * (float)x))
  84. * 0.5 * cucul_get_height(mask),
  85. cucul_get_width(mask) / 2,
  86. cucul_get_height(mask) / 2, "#");
  87. /* Blit the spare canvas onto the first one */
  88. cucul_blit(qq, 0, 0, gg, mask);
  89. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  90. cucul_printf(qq, 2, 1,
  91. "gamma=%g - use arrows to change, Esc to quit", gam);
  92. caca_display(kk);
  93. }
  94. cucul_free_dither(left);
  95. cucul_free_dither(right);
  96. caca_detach(kk);
  97. cucul_free(qq);
  98. return 0;
  99. }