Statistics
| Revision:

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

History | View | Annotate | Download (3.5 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 fileIn = baseDir + "wheel.bmp";
36
//        private String fileOut = "/tmp/wheel.eps";
37
        private String fileIn = baseDir + "letters.bmp";
38
        private String fileOut = "/tmp/letters.eps";
39

    
40
        private RasterDataset f1 = null;
41
        
42
        private long activaBit(long value, int pos) {
43
                value = (value | ((long)1 << pos));
44
                return value;
45
        }
46
        
47
        public TestRasterPotrace() {
48
                try {
49
                        f1 = RasterDataset.open(null, fileIn);
50
                        BufferFactory ds = new BufferFactory(f1);
51
                        ds.setAllDrawableBands();
52
                        ds.setAreaOfInterest();
53
                        RasterBuffer buf = (RasterBuffer) ds.getRasterBuf();
54

    
55
                        int dy = (buf.getWidth() + 64 - 1) / 64;
56

    
57
                        long[] bufferBits = new long[buf.getHeight() * dy];
58

    
59
                        for (int i = 0; i < bufferBits.length; i++)
60
                                bufferBits[i] = 0;
61
                        
62
                        int bit = 0;
63
                        int pos = 0;
64
                        for (int i = 0; i < buf.getHeight(); i++) {
65
                                pos = (buf.getHeight() - i - 1) * dy;
66
                                bit = 0;
67
                                for (int j = 0; j < buf.getWidth(); j++) {
68
                                        byte data = buf.getElemByte(i, j, 0);
69

    
70
                                        if (data == 0) {
71
                                                if (bit < 32)
72
                                                        bufferBits[pos] = activaBit(bufferBits[pos], 31 - bit);
73
                                                else
74
                                                        bufferBits[pos] = activaBit(bufferBits[pos], Math.abs(bit-95));
75
                                        }
76
                                        
77
                                        bit++;
78
                                        if (bit >= 64) {
79
                                                bit = 0;
80
                                                pos++;
81
                                        }
82
                                }
83
                        }
84
                        
85
                        for (int i = 0; i < bufferBits.length; i++) {
86
                                if ((i % dy) == 0)
87
                                        System.out.println("");
88
                                for (int j=31; j>=0; j--) {
89
                                        if ((bufferBits[i] & ((long) 1 << j)) == 0)
90
                                                System.out.print('1');
91
                                        else
92
                                                System.out.print('0');
93
                                }
94
                                for (int j=63; j>=32; j--) {
95
                                        if ((bufferBits[i] & ((long) 1 << j)) == 0)
96
                                                System.out.print('1');
97
                                        else
98
                                                System.out.print('0');
99
                                }
100
                        }
101
                        
102
                        System.out.println("");
103
                        System.out.println(bufferBits.length);
104
                        
105
                        Potrace.vectorizeBufferRaster(bufferBits, buf.getWidth(), buf.getHeight(), fileOut);
106
                } catch (NotSupportedExtensionException e) {
107
                        e.printStackTrace();
108
                } catch (RasterDriverException e) {
109
                        e.printStackTrace();
110
                } catch (InterruptedException e) {
111
                        e.printStackTrace();
112
                } catch (PotraceException e) {
113
                        e.printStackTrace();
114
                }
115
        }
116

    
117
        public static void main(String[] args){
118
                new TestRasterPotrace();
119
        }
120
}