aliasing.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2010 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * Author: Chris Wilson <chris@chris-wilson.co.uk>
  25. */
  26. #include "cairo-test.h"
  27. /* A fun little test to explore color fringing in various experimental
  28. * subpixel rasterisation techniques.
  29. */
  30. #define WIDTH 60
  31. #define HEIGHT 40
  32. static const struct color {
  33. double red, green, blue;
  34. } color[] = {
  35. { 1, 1, 1 },
  36. { 0, 0, 0 },
  37. { 1, 0, 0 },
  38. { 0, 1, 0 },
  39. { 0, 0, 1 },
  40. { 1, 1, 0 },
  41. { 0, 1, 1 },
  42. { 1, 0, 1 },
  43. { .5, .5, .5 },
  44. };
  45. #define NUM_COLORS ARRAY_LENGTH (color)
  46. static void
  47. object (cairo_t *cr, const struct color *fg, const struct color *bg)
  48. {
  49. cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue);
  50. cairo_rectangle (cr, 0, 0, WIDTH, HEIGHT);
  51. cairo_fill (cr);
  52. cairo_set_source_rgb (cr, fg->red, fg->green, fg->blue);
  53. cairo_save (cr);
  54. cairo_scale (cr, WIDTH, HEIGHT);
  55. cairo_arc (cr, .5, .5, .5 - 4. / MAX (WIDTH, HEIGHT), 0, 2 * M_PI);
  56. cairo_fill (cr);
  57. cairo_arc (cr, .5, .5, .5 - 2. / MAX (WIDTH, HEIGHT), 0, 2 * M_PI);
  58. cairo_restore (cr);
  59. cairo_set_line_width (cr, 1.);
  60. cairo_stroke (cr);
  61. cairo_set_source_rgb (cr, bg->red, bg->green, bg->blue);
  62. cairo_set_line_width (cr, 4.);
  63. cairo_move_to (cr, 4, HEIGHT-4);
  64. cairo_line_to (cr, WIDTH-12, 4);
  65. cairo_move_to (cr, 12, HEIGHT-4);
  66. cairo_line_to (cr, WIDTH-4, 4);
  67. cairo_stroke (cr);
  68. }
  69. static cairo_test_status_t
  70. draw (cairo_t *cr, int width, int height)
  71. {
  72. unsigned int i, j;
  73. for (i = 0; i < NUM_COLORS; i++) {
  74. for (j = 0; j < NUM_COLORS; j++) {
  75. cairo_save (cr);
  76. cairo_translate (cr, i * WIDTH, j * HEIGHT);
  77. object (cr, &color[i], &color[j]);
  78. cairo_restore (cr);
  79. }
  80. }
  81. return CAIRO_TEST_SUCCESS;
  82. }
  83. CAIRO_TEST (aliasing,
  84. "Check for subpixel aliasing and color fringing",
  85. "rasterisation", /* keywords */
  86. "target=raster", /* requirements */
  87. NUM_COLORS * WIDTH, NUM_COLORS * HEIGHT,
  88. NULL, draw)