1 | package wcst.transaction.tools;
|
---|
2 |
|
---|
3 | //~--- non-JDK imports --------------------------------------------------------
|
---|
4 |
|
---|
5 | import org.odmg.*;
|
---|
6 |
|
---|
7 | import rasj.*;
|
---|
8 |
|
---|
9 | import wcst.transaction.executeTransaction.ShowImage;
|
---|
10 |
|
---|
11 | //~--- JDK imports ------------------------------------------------------------
|
---|
12 |
|
---|
13 | import java.awt.Graphics;
|
---|
14 |
|
---|
15 | import java.awt.image.BufferedImage;
|
---|
16 |
|
---|
17 | import java.io.IOException;
|
---|
18 |
|
---|
19 | import java.net.URL;
|
---|
20 |
|
---|
21 | import javax.imageio.ImageIO;
|
---|
22 |
|
---|
23 | import javax.swing.JFrame;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * @author Andrei Aiordachioaie
|
---|
27 | */
|
---|
28 | public class TestRasdamanBug
|
---|
29 | {
|
---|
30 | private static RasdamanUtils myUtils;
|
---|
31 |
|
---|
32 | public static void main(String[] args)
|
---|
33 | throws ODMGException, RasResultIsNoIntervalException, IOException, Exception
|
---|
34 | {
|
---|
35 | try
|
---|
36 | {
|
---|
37 | myUtils.commitAndClose();
|
---|
38 | myUtils = new RasdamanUtils("http://kahlua.eecs.jacobs-university.de" + ":7001",
|
---|
39 | "RASBASE");
|
---|
40 |
|
---|
41 | myUtils.init();
|
---|
42 |
|
---|
43 | insertImageFromInternet(
|
---|
44 | "andreiFlickr1", "http://farm4.static.flickr.com/3347/3500129555_137c537e75_m.jpg");
|
---|
45 |
|
---|
46 | updateImageFromInternet("andreiFlickr1", "http://localhost/peta/car.jpeg");
|
---|
47 | }
|
---|
48 | catch (Exception e)
|
---|
49 | {
|
---|
50 | e.printStackTrace();
|
---|
51 | myUtils.abortAndClose();
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | private static void insertImageFromInternet(String identifier, String href)
|
---|
56 | {
|
---|
57 | try
|
---|
58 | {
|
---|
59 | // Step 1: fetch the image from Internet
|
---|
60 | URL url = new URL(href);
|
---|
61 | BufferedImage img0 = ImageIO.read(url);
|
---|
62 | BufferedImage img = convertImageToGray(img0);
|
---|
63 |
|
---|
64 | // Display image for check
|
---|
65 | displayImage(identifier, img);
|
---|
66 |
|
---|
67 | // Step 2: Insert image into rasdaman
|
---|
68 | myUtils.insertGrayImageAsArray(identifier, img);
|
---|
69 | }
|
---|
70 | catch (Exception e)
|
---|
71 | {
|
---|
72 | System.err.println("Error: " + e.getMessage());
|
---|
73 | e.printStackTrace();
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | public static BufferedImage convertImageToGray(BufferedImage img)
|
---|
78 | {
|
---|
79 | BufferedImage image = new BufferedImage(img.getWidth(), img.getHeight(),
|
---|
80 | BufferedImage.TYPE_BYTE_GRAY);
|
---|
81 | Graphics g = image.getGraphics();
|
---|
82 |
|
---|
83 | g.drawImage(img, 0, 0, null);
|
---|
84 | g.dispose();
|
---|
85 |
|
---|
86 | return image;
|
---|
87 | }
|
---|
88 |
|
---|
89 | private static void updateImageFromInternet(String identifier, String href)
|
---|
90 | {
|
---|
91 | try
|
---|
92 | {
|
---|
93 | // Step 1: fetch the image from Internet
|
---|
94 | URL url = new URL(href);
|
---|
95 | BufferedImage img0 = ImageIO.read(url);
|
---|
96 | BufferedImage img = myUtils.convertImageToGray(img0);
|
---|
97 |
|
---|
98 | // Display image for check
|
---|
99 | displayImage(identifier, img);
|
---|
100 |
|
---|
101 | // Step 2: Update image into rasdaman
|
---|
102 | myUtils.updateGrayImageWithArray(identifier, img, 0, 0, img.getWidth(),
|
---|
103 | img.getHeight());
|
---|
104 | }
|
---|
105 | catch (Exception e)
|
---|
106 | {
|
---|
107 | System.err.println("Error: " + e.getMessage());
|
---|
108 | e.printStackTrace();
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | public static void displayImage(String name, BufferedImage img)
|
---|
113 | {
|
---|
114 | JFrame f = new JFrame("Image " + name);
|
---|
115 |
|
---|
116 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
117 | f.getContentPane().add(new ShowImage(img));
|
---|
118 | f.setSize(img.getWidth() + 50, img.getHeight() + 50);
|
---|
119 | f.setVisible(true);
|
---|
120 | }
|
---|
121 | }
|
---|