aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAlan Third2019-06-11 20:31:24 +0100
committerAlan Third2019-06-16 20:24:53 +0100
commit11b0e33462fa7ebef142953010e25728543d1be8 (patch)
tree9595b80194dcc0a8ea3bf9c999b8dbe6cca82ba9 /test
parenta1508e8d2db0003fafb53ae51ed1104ba957db6b (diff)
downloademacs-11b0e33462fa7ebef142953010e25728543d1be8.tar.gz
emacs-11b0e33462fa7ebef142953010e25728543d1be8.zip
Document image transforms
* doc/lispref/display.texi (Image Descriptors): Document :crop and update :rotation. * src/image.c: Describe the image transform matrix layout. * test/manual/image-transforms-tests.el: New file.
Diffstat (limited to 'test')
-rw-r--r--test/manual/image-transforms-tests.el176
1 files changed, 176 insertions, 0 deletions
diff --git a/test/manual/image-transforms-tests.el b/test/manual/image-transforms-tests.el
new file mode 100644
index 00000000000..d601b9397e3
--- /dev/null
+++ b/test/manual/image-transforms-tests.el
@@ -0,0 +1,176 @@
1;;; image-transform-tests.el --- Test suite for image transforms.
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; Author: Alan Third <alan@idiocy.org>
6;; Keywords: internal
7;; Human-Keywords: internal
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software: you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation, either version 3 of the License, or
14;; (at your option) any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
23
24;;; Commentary:
25
26;; Type M-x test-transforms RET to generate the test buffer.
27
28;;; Code:
29
30(defun test-rotation ()
31 (let ((up "<svg height='9' width='9'><polygon points='0,8 4,0 8,8'/></svg>")
32 (down "<svg height='9' width='9'><polygon points='0,0 4,8 8,0'/></svg>")
33 (left "<svg height='9' width='9'><polygon points='8,0 0,4 8,8'/></svg>")
34 (right "<svg height='9' width='9'><polygon points='0,0 8,4 0,8'/></svg>"))
35 (insert-header "Test Rotation: rotating an image")
36 (insert-test "0" up up '(:rotation 0))
37 (insert-test "360" up up '(:rotation 360))
38 (insert-test "180" down up '(:rotation 180))
39 (insert-test "-90" left up '(:rotation -90))
40 (insert-test "90" right up '(:rotation 90))
41 (insert-test "90.0" right up '(:rotation 90.0))
42
43 ;; This should log a message and display the unrotated image.
44 (insert-test "45" up up '(:rotation 45)))
45 (insert "\n\n"))
46
47(defun test-cropping ()
48 (let ((image "<svg height='30' width='30'>
49 <rect x='0' y='0' width='10' height='10'/>
50 <rect x='10' y='10' width='10' height='10'
51 style='fill:none;stroke-width:1;stroke:#000'/>
52 <line x1='10' y1='10' x2='20' y2='20' style='stroke:#000'/>
53 <line x1='20' y1='10' x2='10' y2='20' style='stroke:#000'/>
54 <rect x='20' y='20' width='10' height='10'
55 style='fill:none;stroke-width:1;stroke:#000'/>
56 </svg>")
57 (top-left "<svg height='10' width='10'>
58 <rect x='0' y='0' width='10' height='10'/>
59 </svg>")
60 (middle "<svg height='10' width='10'>
61 <rect x='0' y='0' width='10' height='10'
62 style='fill:none;stroke-width:1;stroke:#000'/>
63 <line x1='0' y1='0' x2='10' y2='10' style='stroke:#000'/>
64 <line x1='10' y1='0' x2='0' y2='10' style='stroke:#000'/>
65 </svg>")
66 (bottom-right "<svg height='10' width='10'>
67 <rect x='0' y='0' width='10' height='10'
68 style='fill:none;stroke-width:1;stroke:#000'/>
69 </svg>"))
70 (insert-header "Test Crop: cropping an image")
71 (insert-test "all params" top-left image '(:crop (10 10 0 0)))
72 (insert-test "width/height only" middle image '(:crop (10 10)))
73 (insert-test "negative x y" middle image '(:crop (10 10 -10 -10)))
74 (insert-test "all params" bottom-right image '(:crop (10 10 20 20))))
75 (insert "\n\n"))
76
77(defun test-scaling ()
78 (let ((image "<svg height='10' width='10'>
79 <rect x='0' y='0' width='10' height='10'
80 style='fill:none;stroke-width:1;stroke:#000'/>
81 <line x1='0' y1='0' x2='10' y2='10' style='stroke:#000'/>
82 <line x1='10' y1='0' x2='0' y2='10' style='stroke:#000'/>
83 </svg>")
84 (large "<svg height='20' width='20'>
85 <rect x='0' y='0' width='20' height='20'
86 style='fill:none;stroke-width:2;stroke:#000'/>
87 <line x1='0' y1='0' x2='20' y2='20'
88 style='stroke-width:2;stroke:#000'/>
89 <line x1='20' y1='0' x2='0' y2='20'
90 style='stroke-width:2;stroke:#000'/>
91 </svg>")
92 (small "<svg height='5' width='5'>
93 <rect x='0' y='0' width='4' height='4'
94 style='fill:none;stroke-width:1;stroke:#000'/>
95 <line x1='0' y1='0' x2='4' y2='4' style='stroke:#000'/>
96 <line x1='4' y1='0' x2='0' y2='4' style='stroke:#000'/>
97 </svg>"))
98 (insert-header "Test Scaling: resize an image (pixelization may occur)")
99 (insert-test "1x" image image '(:scale 1))
100 (insert-test "2x" large image '(:scale 2))
101 (insert-test "0.5x" image large '(:scale 0.5))
102 (insert-test ":max-width" image large '(:max-width 10))
103 (insert-test ":max-height" image large '(:max-height 10))
104 (insert-test "width, height" image large '(:width 10 :height 10)))
105 (insert "\n\n"))
106
107(defun test-scaling-rotation ()
108 (let ((image "<svg height='20' width='20'>
109 <rect x='0' y='0' width='20' height='20'
110 style='fill:none;stroke-width:1;stroke:#000'/>
111 <rect x='0' y='0' width='10' height='10'
112 style='fill:#000'/>
113 </svg>")
114 (x2-90 "<svg height='40' width='40'>
115 <rect x='0' y='0' width='40' height='40'
116 style='fill:none;stroke-width:1;stroke:#000'/>
117 <rect x='20' y='0' width='20' height='20'
118 style='fill:#000'/>
119 </svg>")
120 (x2--90 "<svg height='40' width='40'>
121 <rect x='0' y='0' width='40' height='40'
122 style='fill:none;stroke-width:1;stroke:#000'/>
123 <rect x='0' y='20' width='20' height='20'
124 style='fill:#000'/>
125 </svg>")
126 (x0.5-180 "<svg height='10' width='10'>
127 <rect x='0' y='0' width='10' height='10'
128 style='fill:none;stroke-width:1;stroke:#000'/>
129 <rect x='5' y='5' width='5' height='5'
130 style='fill:#000'/>
131 </svg>"))
132 (insert-header "Test Scaling and Rotation: resize and rotate an image (pixelization may occur)")
133 (insert-test "1x, 0 degrees" image image '(:scale 1 :rotation 0))
134 (insert-test "2x, 90 degrees" x2-90 image '(:scale 2 :rotation 90.0))
135 (insert-test "2x, -90 degrees" x2--90 image '(:scale 2 :rotation -90.0))
136 (insert-test "0.5x, 180 degrees" x0.5-180 image '(:scale 0.5 :rotation 180.0)))
137 (insert "\n\n"))
138
139(defun insert-header (description)
140 (insert description)
141 (insert "\n")
142 (indent-to 38)
143 (insert "expected")
144 (indent-to 48)
145 (insert "result")
146 (when (fboundp #'imagemagick-types)
147 (indent-to 58)
148 (insert "ImageMagick"))
149 (insert "\n"))
150
151(defun insert-test (description expected image params)
152 (indent-to 2)
153 (insert description)
154 (indent-to 40)
155 (insert-image (create-image expected 'svg t))
156 (indent-to 50)
157 (insert-image (apply #'create-image image 'svg t params))
158 (when (fboundp #'imagemagick-types)
159 (indent-to 60)
160 (insert-image (apply #'create-image image 'imagemagick t params)))
161 (insert "\n"))
162
163(defun test-transforms ()
164 (interactive)
165 (let ((buf (get-buffer "*Image Transform Test*")))
166 (if buf
167 (kill-buffer buf))
168 (switch-to-buffer (get-buffer-create "*Image Transform Test*"))
169 (erase-buffer)
170 (unless #'imagemagick-types
171 (insert "ImageMagick not detected. ImageMagick tests will be skipped.\n\n"))
172 (test-rotation)
173 (test-cropping)
174 (test-scaling)
175 (test-scaling-rotation)
176 (goto-char (point-min))))