2 * Copyright (C) 2010 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * These authors would like to acknowledge the Spanish Ministry of Industry,
19 * Tourism and Trade, for the support in the project TSI020301-2008-2
20 * "PIRAmIDE: Personalizable Interactions with Resources on AmI-enabled
21 * Mobile Dynamic Environments", led by Treelogic
22 * ( http://www.treelogic.com/ ):
24 * http://www.piramidepse.com/
27 package com.google.zxing.oned.rss.expanded;
29 import java.awt.image.BufferedImage;
31 import java.io.IOException;
32 import java.util.Vector;
34 import javax.imageio.ImageIO;
36 import com.google.zxing.BinaryBitmap;
37 import com.google.zxing.NotFoundException;
38 import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
39 import com.google.zxing.common.BitArray;
40 import com.google.zxing.common.GlobalHistogramBinarizer;
41 import org.junit.Assert;
42 import org.junit.Test;
45 * @author Pablo Orduña, University of Deusto (pablo.orduna@deusto.es)
46 * @author Eduardo Castillejo, University of Deusto (eduardo.castillejo@deusto.es)
48 public final class RSSExpandedImage2binaryTestCase extends Assert {
51 public void testDecodeRow2binary_1() throws Exception {
52 // (11)100224(17)110224(3102)000100
53 String path = "test/data/blackbox/rssexpanded-1/1.jpg";
54 String expected = " ...X...X .X....X. .XX...X. X..X...X ...XX.X. ..X.X... ..X.X..X ...X..X. X.X....X .X....X. .....X.. X...X...";
56 assertCorrectImage2binary(path, expected);
60 public void testDecodeRow2binary_2() throws Exception {
61 // (01)90012345678908(3103)001750
62 String path = "test/data/blackbox/rssexpanded-1/2.jpg";
63 String expected = " ..X..... ......X. .XXX.X.X .X...XX. XXXXX.XX XX.X.... .XX.XX.X .XX.";
65 assertCorrectImage2binary(path, expected);
70 public void testDecodeRow2binary_3() throws Exception {
72 String path = "test/data/blackbox/rssexpanded-1/3.jpg";
73 String expected = " .......X ..XX..X. X.X....X .......X ....";
75 assertCorrectImage2binary(path, expected);
79 public void testDecodeRow2binary_4() throws Exception {
80 // (01)98898765432106(3202)012345(15)991231
81 String path = "test/data/blackbox/rssexpanded-1/4.jpg";
82 String expected = " ..XXXX.X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX..XX XX.X.XXX X..XX..X .X.XXXXX XXXX";
84 assertCorrectImage2binary(path, expected);
88 public void testDecodeRow2binary_5() throws Exception {
89 // (01)90614141000015(3202)000150
90 String path = "test/data/blackbox/rssexpanded-1/5.jpg";
91 String expected = " ..X.X... .XXXX.X. XX..XXXX ....XX.. X....... ....X... ....X..X .XX.";
93 assertCorrectImage2binary(path, expected);
97 public void testDecodeRow2binary_10() throws Exception {
98 // (01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456(423)0123456789012
99 String path = "test/data/blackbox/rssexpanded-1/10.png";
100 String expected = " .X.XX..X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX...X XX.X.... X.X.X.X. X.X..X.X .X....X. XX...X.. ...XX.X. .XXXXXX. .X..XX.. X.X.X... .X...... XXXX.... XX.XX... XXXXX.X. ...XXXXX .....X.X ...X.... X.XXX..X X.X.X... XX.XX..X .X..X..X .X.X.X.X X.XX...X .XX.XXX. XXX.X.XX ..X.";
102 assertCorrectImage2binary(path, expected);
106 public void testDecodeRow2binary_11() throws Exception {
107 // (01)98898765432106(15)991231(3103)001750(10)12A(422)123(21)123456
108 String expected = " .X.XX..X XX.XXXX. .XXX.XX. XX..X... .XXXXX.. XX.X..X. ..XX...X XX.X.... X.X.X.X. X.X..X.X .X....X. XX...X.. ...XX.X. .XXXXXX. .X..XX.. X.X.X... .X...... XXXX.... XX.XX... XXXXX.X. ...XXXXX .....X.X ...X.... X.XXX..X X.X.X... ....";
109 String path = "test/data/blackbox/rssexpanded-1/11.png";
111 assertCorrectImage2binary(path, expected);
115 public void testDecodeRow2binary_12() throws Exception {
116 // (01)98898765432106(3103)001750
118 String expected = " ..X..XX. XXXX..XX X.XX.XX. .X....XX XXX..XX. X..X.... .XX.XX.X .XX.";
119 String path = "test/data/blackbox/rssexpanded-1/12.jpg";
121 assertCorrectImage2binary(path, expected);
125 public void testDecodeRow2binary_13() throws Exception {
126 // (01)90012345678908(3922)795
128 String expected = " ..XX..X. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. X.X.XXXX .X..X..X ......X.";
129 String path = "test/data/blackbox/rssexpanded-1/13.png";
131 assertCorrectImage2binary(path, expected);
135 public void testDecodeRow2binary_14() throws Exception {
136 // (01)90012345678908(3932)0401234
138 String expected = " ..XX.X.. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. X.....X. X.....X. X.X.X.XX .X...... X...";
139 String path = "test/data/blackbox/rssexpanded-1/14.png";
141 assertCorrectImage2binary(path, expected);
145 public void testDecodeRow2binary_15() throws Exception {
146 // (01)90012345678908(3102)001750(11)100312
148 String expected = " ..XXX... ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
149 String path = "test/data/blackbox/rssexpanded-1/15.jpg";
151 assertCorrectImage2binary(path, expected);
155 public void testDecodeRow2binary_16() throws Exception {
156 // (01)90012345678908(3202)001750(11)100312
158 String expected = " ..XXX..X ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
159 String path = "test/data/blackbox/rssexpanded-1/16.jpg";
161 assertCorrectImage2binary(path, expected);
165 public void testDecodeRow2binary_17() throws Exception {
166 // (01)90012345678908(3102)001750(13)100312
168 String expected = " ..XXX.X. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
169 String path = "test/data/blackbox/rssexpanded-1/17.jpg";
171 assertCorrectImage2binary(path, expected);
175 public void testDecodeRow2binary_18() throws Exception {
176 // (01)90012345678908(3202)001750(13)100312
178 String expected = " ..XXX.XX ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
179 String path = "test/data/blackbox/rssexpanded-1/18.jpg";
181 assertCorrectImage2binary(path, expected);
185 public void testDecodeRow2binary_19() throws Exception {
186 // (01)90012345678908(3102)001750(15)100312
188 String expected = " ..XXXX.. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
189 String path = "test/data/blackbox/rssexpanded-1/19.jpg";
191 assertCorrectImage2binary(path, expected);
195 public void testDecodeRow2binary_20() throws Exception {
196 // (01)90012345678908(3202)001750(15)100312
198 String expected = " ..XXXX.X ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
199 String path = "test/data/blackbox/rssexpanded-1/20.jpg";
201 assertCorrectImage2binary(path, expected);
205 public void testDecodeRow2binary_21() throws Exception {
206 // (01)90012345678908(3102)001750(17)100312
208 String expected = " ..XXXXX. ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
209 String path = "test/data/blackbox/rssexpanded-1/21.jpg";
211 assertCorrectImage2binary(path, expected);
215 public void testDecodeRow2binary_22() throws Exception {
216 // (01)90012345678908(3202)001750(17)100312
218 String expected = " ..XXXXXX ........ .X..XXX. X.X.X... XX.XXXXX .XXXX.X. ..XX...X .X.....X .XX..... XXXX.X.. XX..";
219 String path = "test/data/blackbox/rssexpanded-1/22.jpg";
221 assertCorrectImage2binary(path, expected);
224 private static void assertCorrectImage2binary(String path, String expected) throws IOException, NotFoundException {
225 RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
227 BufferedImage image = ImageIO.read(new File(path));
228 BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
229 int rowNumber = binaryMap.getHeight() / 2;
230 BitArray row = binaryMap.getBlackRow(rowNumber, null);
232 Vector<ExpandedPair> pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
233 BitArray binary = BitArrayBuilder.buildBitArray(pairs);
234 assertEquals(expected, binary.toString());