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.

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. #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. cucul_t *qq, *gg, *mask;
  31. caca_t *kk;
  32. struct cucul_bitmap *left, *right;
  33. float gam = 1.0;
  34. int x;
  35. qq = cucul_init(0, 0);
  36. kk = caca_attach(qq);
  37. gg = cucul_init(cucul_get_width(qq), cucul_get_height(qq));
  38. mask = cucul_init(cucul_get_width(qq), cucul_get_height(qq));
  39. for(x = 0; x < 256; x++)
  40. {
  41. buffer[x] = (x << 16) | (x << 8) | (x<< 0);
  42. buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0);
  43. buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0);
  44. buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
  45. }
  46. left = cucul_create_bitmap(32, 256, 4, 4 * 256,
  47. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  48. right = cucul_create_bitmap(32, 256, 4, 4 * 256,
  49. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  50. caca_set_delay(kk, 20000);
  51. for(x = 0; ; x++)
  52. {
  53. int ev = caca_get_event(kk, CACA_EVENT_KEY_PRESS);
  54. if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_LEFT))
  55. gam /= 1.03;
  56. else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_RIGHT))
  57. gam *= 1.03;
  58. else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_DOWN))
  59. gam = 1.0;
  60. else if(ev == (CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE))
  61. break;
  62. /* Resize the spare canvas, just in case the main one changed */
  63. cucul_set_size(gg, cucul_get_width(qq), cucul_get_height(qq));
  64. cucul_set_size(mask, cucul_get_width(qq), cucul_get_height(qq));
  65. /* Draw the regular bitmap on the main canvas */
  66. cucul_draw_bitmap(qq, 0, 0,
  67. cucul_get_width(qq) - 1, cucul_get_height(qq) - 1,
  68. left, buffer);
  69. /* Draw the gamma-modified bitmap on the spare canvas */
  70. cucul_set_bitmap_gamma(right, gam);
  71. cucul_draw_bitmap(gg, 0, 0,
  72. cucul_get_width(gg) - 1, cucul_get_height(gg) - 1,
  73. right, buffer);
  74. /* Draw something on the mask */
  75. cucul_clear(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_width(mask),
  79. (1.0 + cos(0.05 * (float)x))
  80. * 0.5 * cucul_get_height(mask),
  81. cucul_get_width(mask) / 2,
  82. cucul_get_height(mask) / 2, '#');
  83. /* Blit the spare canvas onto the first one */
  84. cucul_blit(qq, 0, 0, gg, mask);
  85. cucul_set_color(qq, CUCUL_COLOR_WHITE, CUCUL_COLOR_BLUE);
  86. cucul_printf(qq, 2, 1,
  87. "gamma=%g - use arrows to change, Esc to quit", gam);
  88. caca_display(kk);
  89. }
  90. cucul_free_bitmap(left);
  91. cucul_free_bitmap(right);
  92. caca_detach(kk);
  93. cucul_end(qq);
  94. return 0;
  95. }