Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / potrace / TestRasterPotrace.java @ 22816

History | View | Annotate | Download (2.94 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.potrace;
20

    
21
import org.gvsig.jpotrace.Potrace;
22
import org.gvsig.jpotrace.PotraceException;
23
import org.gvsig.raster.buffer.BufferFactory;
24
import org.gvsig.raster.buffer.RasterBuffer;
25
import org.gvsig.raster.dataset.NotSupportedExtensionException;
26
import org.gvsig.raster.dataset.RasterDataset;
27
import org.gvsig.raster.dataset.io.RasterDriverException;
28
/**
29
 * 
30
 * @version 05/08/2008
31
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
32
 */
33
public class TestRasterPotrace {
34
        private String baseDir = "./test-images/";
35
//        private String path1 = baseDir + "wheel.bmp";
36
        private String path1 = baseDir + "letters.bmp";
37

    
38
        private RasterDataset f1 = null;
39
        
40
        public TestRasterPotrace() {
41
                try {
42
                        f1 = RasterDataset.open(null, path1);
43
                        BufferFactory ds = new BufferFactory(f1);
44
                        ds.setAllDrawableBands();
45
                        ds.setAreaOfInterest();
46
                        RasterBuffer buf = (RasterBuffer) ds.getRasterBuf();
47

    
48
                        int dy = (buf.getWidth() + 64 - 1) / 64;
49

    
50
                        long[] bufferBits = new long[buf.getHeight() * dy];
51

    
52
                        for (int i = 0; i < bufferBits.length; i++)
53
                                bufferBits[i] = 0;
54
                        
55
                        int bit = 0;
56
                        int pos = 0;
57
//                        for (int j = 0; j < buf.getWidth(); j++) {
58
                        for (int i = 0; i < buf.getHeight(); i++) {
59
                                pos = (buf.getHeight() - i - 1) * dy;
60
                                bit = 0;
61
//                        for (int i = 0; i < buf.getHeight(); i++) {
62
                                for (int j = 0; j < buf.getWidth(); j++) {
63
                                        byte data = buf.getElemByte(i, j, 0);
64

    
65
                                        if (data == 0) {
66
                                                bufferBits[pos] += (1 << (63-bit));
67
//                                                if (bit < 32)
68
//                                                        bufferBits[pos] += (1 << (63-bit+32));
69
//                                                else
70
//                                                        bufferBits[pos] += (1 << j);
71
                                        }
72
                                        
73
                                        bit++;
74
                                        if (bit >= 64) {
75
                                                bit = 0;
76
                                                pos++;
77
                                        }
78
                                }
79
                        }
80

    
81
                        // binario
82
                        
83
                        Potrace.vectorizeBufferRaster(bufferBits, buf.getWidth(), buf.getHeight(), "C:\\TEMP\\nacho.eps");
84
                } catch (NotSupportedExtensionException e) {
85
                        e.printStackTrace();
86
                } catch (RasterDriverException e) {
87
                        e.printStackTrace();
88
                } catch (InterruptedException e) {
89
                        e.printStackTrace();
90
                } catch (PotraceException e) {
91
                        e.printStackTrace();
92
                }
93
        }
94

    
95
        public static void main(String[] args){
96
                new TestRasterPotrace();
97
        }
98
}