25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

127 satır
4.0 KiB

  1. /*
  2. * gamma libcaca 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 "caca.h"
  20. uint32_t buffer[256 * 4];
  21. int main(int argc, char *argv[])
  22. {
  23. caca_event_t ev;
  24. caca_canvas_t *cv, *cw, *mask;
  25. caca_display_t *dp;
  26. caca_dither_t *left, *right;
  27. float gam;
  28. int x;
  29. cv = caca_create_canvas(0, 0);
  30. if(cv == NULL)
  31. {
  32. printf("Can't created canvas\n");
  33. return -1;
  34. }
  35. dp = caca_create_display(cv);
  36. if(dp == NULL)
  37. {
  38. printf("Can't create display\n");
  39. return -1;
  40. }
  41. cw = caca_create_canvas(caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  42. mask = caca_create_canvas(caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  43. for(x = 0; x < 256; x++)
  44. {
  45. buffer[x] = (x << 16) | (x << 8) | (x<< 0);
  46. buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0);
  47. buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0);
  48. buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
  49. }
  50. left = caca_create_dither(32, 256, 4, 4 * 256,
  51. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  52. right = caca_create_dither(32, 256, 4, 4 * 256,
  53. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  54. gam = caca_get_dither_gamma(right);
  55. caca_set_display_time(dp, 20000);
  56. for(x = 0; ; x++)
  57. {
  58. int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
  59. if(ret)
  60. {
  61. if(caca_get_event_key_ch(&ev) == CACA_KEY_LEFT)
  62. gam /= 1.03;
  63. else if(caca_get_event_key_ch(&ev) == CACA_KEY_RIGHT)
  64. gam *= 1.03;
  65. else if(caca_get_event_key_ch(&ev) == CACA_KEY_DOWN)
  66. gam = 1.0;
  67. else if(caca_get_event_key_ch(&ev) == CACA_KEY_ESCAPE)
  68. break;
  69. }
  70. /* Resize the spare canvas, just in case the main one changed */
  71. caca_set_canvas_size(cw, caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  72. caca_set_canvas_size(mask, caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  73. /* Draw the regular dither on the main canvas */
  74. caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
  75. caca_get_canvas_height(cv), left, buffer);
  76. /* Draw the gamma-modified dither on the spare canvas */
  77. caca_set_dither_gamma(right, gam);
  78. caca_dither_bitmap(cw, 0, 0, caca_get_canvas_width(cw),
  79. caca_get_canvas_height(cw), right, buffer);
  80. /* Draw something on the mask */
  81. caca_set_color_ansi(mask, CACA_LIGHTGRAY, CACA_BLACK);
  82. caca_clear_canvas(mask);
  83. caca_set_color_ansi(mask, CACA_WHITE, CACA_WHITE);
  84. caca_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
  85. * 0.5 * caca_get_canvas_width(mask),
  86. (1.0 + cos(0.05 * (float)x))
  87. * 0.5 * caca_get_canvas_height(mask),
  88. caca_get_canvas_width(mask) / 2,
  89. caca_get_canvas_height(mask) / 2, '#');
  90. /* Blit the spare canvas onto the first one */
  91. caca_blit(cv, 0, 0, cw, mask);
  92. caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
  93. caca_printf(cv, 2, 1,
  94. "gamma=%g - use arrows to change, Esc to quit", gam);
  95. caca_refresh_display(dp);
  96. }
  97. caca_free_dither(left);
  98. caca_free_dither(right);
  99. caca_free_display(dp);
  100. caca_free_canvas(mask);
  101. caca_free_canvas(cw);
  102. caca_free_canvas(cv);
  103. return 0;
  104. }