選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

125 行
4.0 KiB

  1. /*
  2. * gamma libcaca gamma test program
  3. * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
  4. * All Rights Reserved
  5. *
  6. * This program is free software. It comes without any warranty, to
  7. * the extent permitted by applicable law. You can redistribute it
  8. * and/or modify it under the terms of the Do What The Fuck You Want
  9. * To Public License, Version 2, as published by Sam Hocevar. See
  10. * http://sam.zoy.org/wtfpl/COPYING for more details.
  11. */
  12. #include "config.h"
  13. #if !defined(__KERNEL__)
  14. # include <stdio.h>
  15. # include <math.h>
  16. #endif
  17. #include "caca.h"
  18. uint32_t buffer[256 * 4];
  19. int main(int argc, char *argv[])
  20. {
  21. caca_event_t ev;
  22. caca_canvas_t *cv, *cw, *mask;
  23. caca_display_t *dp;
  24. caca_dither_t *left, *right;
  25. float gam;
  26. int x;
  27. cv = caca_create_canvas(0, 0);
  28. if(cv == NULL)
  29. {
  30. printf("Can't created canvas\n");
  31. return -1;
  32. }
  33. dp = caca_create_display(cv);
  34. if(dp == NULL)
  35. {
  36. printf("Can't create display\n");
  37. return -1;
  38. }
  39. cw = caca_create_canvas(caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  40. mask = caca_create_canvas(caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  41. for(x = 0; x < 256; x++)
  42. {
  43. buffer[x] = (x << 16) | (x << 8) | (x<< 0);
  44. buffer[x + 256] = (0xff << 16) | (x << 8) | (0x00 << 0);
  45. buffer[x + 512] = (0x00 << 16) | (0xff << 8) | (x << 0);
  46. buffer[x + 768] = (x << 16) | (0x00 << 8) | (0xff << 0);
  47. }
  48. left = caca_create_dither(32, 256, 4, 4 * 256,
  49. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  50. right = caca_create_dither(32, 256, 4, 4 * 256,
  51. 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);
  52. gam = caca_get_dither_gamma(right);
  53. caca_set_display_time(dp, 20000);
  54. for(x = 0; ; x++)
  55. {
  56. int ret = caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0);
  57. if(ret)
  58. {
  59. if(caca_get_event_key_ch(&ev) == CACA_KEY_LEFT)
  60. gam /= 1.03;
  61. else if(caca_get_event_key_ch(&ev) == CACA_KEY_RIGHT)
  62. gam *= 1.03;
  63. else if(caca_get_event_key_ch(&ev) == CACA_KEY_DOWN)
  64. gam = 1.0;
  65. else if(caca_get_event_key_ch(&ev) == CACA_KEY_ESCAPE)
  66. break;
  67. }
  68. /* Resize the spare canvas, just in case the main one changed */
  69. caca_set_canvas_size(cw, caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  70. caca_set_canvas_size(mask, caca_get_canvas_width(cv), caca_get_canvas_height(cv));
  71. /* Draw the regular dither on the main canvas */
  72. caca_dither_bitmap(cv, 0, 0, caca_get_canvas_width(cv),
  73. caca_get_canvas_height(cv), left, buffer);
  74. /* Draw the gamma-modified dither on the spare canvas */
  75. caca_set_dither_gamma(right, gam);
  76. caca_dither_bitmap(cw, 0, 0, caca_get_canvas_width(cw),
  77. caca_get_canvas_height(cw), right, buffer);
  78. /* Draw something on the mask */
  79. caca_set_color_ansi(mask, CACA_LIGHTGRAY, CACA_BLACK);
  80. caca_clear_canvas(mask);
  81. caca_set_color_ansi(mask, CACA_WHITE, CACA_WHITE);
  82. caca_fill_ellipse(mask, (1.0 + sin(0.05 * (float)x))
  83. * 0.5 * caca_get_canvas_width(mask),
  84. (1.0 + cos(0.05 * (float)x))
  85. * 0.5 * caca_get_canvas_height(mask),
  86. caca_get_canvas_width(mask) / 2,
  87. caca_get_canvas_height(mask) / 2, '#');
  88. /* Blit the spare canvas onto the first one */
  89. caca_blit(cv, 0, 0, cw, mask);
  90. caca_set_color_ansi(cv, CACA_WHITE, CACA_BLUE);
  91. caca_printf(cv, 2, 1,
  92. "gamma=%g - use arrows to change, Esc to quit", gam);
  93. caca_refresh_display(dp);
  94. }
  95. caca_free_dither(left);
  96. caca_free_dither(right);
  97. caca_free_display(dp);
  98. caca_free_canvas(mask);
  99. caca_free_canvas(cw);
  100. caca_free_canvas(cv);
  101. return 0;
  102. }