1 package de.desy.video.sw;
2
3 import java.util.Date;
4 //import java.lang.Float;
5 import de.desy.tine.types.*;
6 import de.desy.tine.types.IMAGE.*;
7
8
9 /**
10 * <code>CVideoHeader3</code> implements reference caching of a Video System v3 (VSv3) data array
11 * known as TINE IMAGE datatype for usage with the rest of Video System v3 Java code.<br>
12 * It contains useful helper functions to decode certain properties of VSv3 header into
13 * human-readable format.<br>
14 * <br>
15 * <b>Note:</b>This class is only a very basic construct and might be substantially changed
16 * in future. It fits its purpose currently but will not win a price for meaningful class
17 * design!
18 *
19 * @author <a href="mailto:stefan.weisse@desy.de">Stefan Weisse</a>
20 * @version $Id: Templates.xml,v 1.10 2008/06/20 17:40:13 sweisse Exp $
21 *
22 */
23
24 public final class CVideoHeader3 {
25
26 /** referenced frameHeader of private TINE IMAGE */
27 public FrameHeader frameHeader = null;
28 /** referenced sourceHeader of private TINE IMAGE */
29 public SourceHeader sourceHeader = null;
30
31 /** size in bytes of a VSv3 header on transport level */
32 public static final int HDRSIZE=188;
33 /** maximum size in bytes of a VSv3 image (without header) */
34 public static final int TRANSPORT_LENGTH_V3 = 1024*1024*6;
35
36 /** first magic id for VSv3 'VSV3' */
37 public static final long CF_IMAGE_MAGIC_01 = 0x33565356; // VSV3
38
39 /** cameraPortId is put to if no camera port is set there */
40 public static final long CF_IMAGE_NO_CAMERA_PORT_ID = 0;
41
42 /** second magic id for VSv3 '2008' */
43 // SW! removed October 1, 2008, because magic02 is not so important
44 // to have, but a cameraPortId is much more important
45 // public static final long CF_IMAGE_MAGIC_02 = 0x38303032; // 2008
46
47 /** initial IMAGE version */
48 public static final int CF_IMAGE_INITIAL_VERSION = 0x1;
49 /** current IMAGE version */
50 public static final int CF_IMAGE_VERSION = CF_IMAGE_INITIAL_VERSION;
51 /** maximum IMAGE version */
52 public static final int CF_IMAGE_MAX_VERSION = CF_IMAGE_INITIAL_VERSION;
53
54 /** video format id of 'Grayscale format'*/
55 public static final long CF_IMAGE_FORMAT_GRAY = 0;
56 /** video format id of 'RGB (24bpp r-g-b) format' */
57 public static final long CF_IMAGE_FORMAT_RGB = 1;
58 /** video format id of 'RGB (32bpp a-r-g-b) format' */
59 public static final long CF_IMAGE_FORMAT_RGBA = 2;
60 /** video format id of 'RGB (16bpp 0-5r-5g-5b) format' */
61 public static final long CF_IMAGE_FORMAT_RGB15 = 3;
62 /** video format id of 'RGB (16bpp 5r-6g-5b)) format' */
63 public static final long CF_IMAGE_FORMAT_RGB16 = 4;
64 /** video format id of 'JPEG file' */
65 public static final long CF_IMAGE_FORMAT_JPEG = 5;
66 /** video format id of 'TIFF file'*/
67 public static final long CF_IMAGE_FORMAT_TIFF = 6;
68 /** video format id of 'YUV411 format'*/
69 public static final long CF_IMAGE_FORMAT_YUV411 = 7;
70 /** video format id of 'YUV422 format'*/
71 public static final long CF_IMAGE_FORMAT_YUV422 = 8;
72 /** video format id of 'YUV444 format'*/
73 public static final long CF_IMAGE_FORMAT_YUV444 = 9;
74 /** video format id of 'HuffYUV' (compressed grayscale) */
75 public static final long CF_IMAGE_FORMAT_HUFFYUV = 10;
76 /** video format id of 'Windows BMP file' */
77 public static final long CF_IMAGE_FORMAT_BMP = 11;
78 /** video format id of 'Bayer pattern' */
79 public static final long CF_IMAGE_FORMAT_BAYER = 12;
80
81 /** first format for range checking */
82 public static final long CF_IMAGE_FORMAT_FIRST = CF_IMAGE_FORMAT_GRAY;
83 /** last format for range checking */
84 public static final long CF_IMAGE_FORMAT_LAST = CF_IMAGE_FORMAT_BAYER;
85
86 /**
87 * if set, appended video data is ordered little endian
88 * (on video format types where this is applicable)
89 * */
90 public static final long CF_IMAGE_FLAG_LITTLE_ENDIAN_BYTE_ORDER = 0x1;
91 /** if set, original image data (first digital image data) can
92 * be restored out of the appended image bits
93 * */
94 public static final long CF_IMAGE_FLAG_IMAGE_LOSSLESS = 0x2;
95 /** if set, image was flipped around horizontal axis on its way */
96 public static final long CF_IMAGE_FLAG_HORIZONTAL_FLIP_180 = 0x4;
97 /** if set, image was flipped around vertical axis on its way */
98 public static final long CF_IMAGE_FLAG_VERTICAL_FLIP_180 = 0x8;
99
100 /** referenced TINE IMAGE */
101 private IMAGE m_intHdr = null; // image header from TINE
102
103
104 /**
105 * default constructor, creates barebone initialized member variables
106 *
107 *
108 */
109 public CVideoHeader3()
110 {
111 m_intHdr = new IMAGE();
112
113 frameHeader = m_intHdr.getFrameHeader();
114 sourceHeader = m_intHdr.getSourceHeader();
115
116 init();
117 }
118
119 /**
120 * The new instance of the class will be a reference to the passed image data.
121 *
122 * @param img image data to wrap inside this class
123 */
124 public CVideoHeader3( IMAGE img )
125 {
126 m_intHdr = img;
127 sourceHeader = img.getSourceHeader();
128 frameHeader = img.getFrameHeader();
129 }
130
131 /**
132 * returns the image reference currently cached in class.
133 *
134 * @return image reference currently cached in class
135 */
136 public IMAGE getImage() {
137 return m_intHdr;
138 }
139
140 /**
141 * decodes flags integer into human readable string format
142 *
143 * @return string representation of the passed aFlags (frameHeader.imageFlags)
144 */
145 public static final String flagsToString(long aFlags)
146 {
147 int flags = (int) aFlags;
148
149 String retString = "";
150
151 if ((flags&CF_IMAGE_FLAG_LITTLE_ENDIAN_BYTE_ORDER) != 0)
152 retString += "LITTLEENDIAN";
153 else
154 retString += "BIGENDIAN";
155
156 if ((flags&CF_IMAGE_FLAG_IMAGE_LOSSLESS) != 0)
157 retString += " LOSSLESS";
158 else
159 retString += " LOSSY";
160
161 if ((flags&CF_IMAGE_FLAG_HORIZONTAL_FLIP_180) != 0)
162 retString += " HORIZONTAL_FLIP_180";
163
164 if ((flags&CF_IMAGE_FLAG_VERTICAL_FLIP_180) != 0)
165 retString += " VERTICAL_FLIP_180";
166
167 return retString;
168 }
169
170 /**
171 * decodes timestamp of video frame into java Date class
172 *
173 * @return date representation of sourceHeader.timestamp(Seconds+Microseconds)
174 */
175 public final Date getTimestampAsDate()
176 {
177 long l_timestamp = (sourceHeader.timestampSeconds*1000L)+(sourceHeader.timestampMicroseconds/1000L);
178
179 return new Date(l_timestamp);
180 }
181
182 /**
183 * decodes video format integer (e.g. frameHeader.sourceFormat, frameHeader.imageFormat)
184 * into human readable string format
185 *
186 * @return string representation of the passed aFormat
187 */
188 public static final String formatToString(long aformat)
189 {
190 switch( ((int) aformat) )
191 {
192 case ((int)CF_IMAGE_FORMAT_GRAY):
193 return("IMAGE_FORMAT_GRAY");
194
195 case ((int)CF_IMAGE_FORMAT_RGB):
196 return("IMAGE_FORMAT_RGB");
197
198 case ((int)CF_IMAGE_FORMAT_RGBA):
199 return("IMAGE_FORMAT_RGBA");
200
201 case ((int)CF_IMAGE_FORMAT_RGB15):
202 return("IMAGE_FORMAT_RGB15");
203
204 case ((int)CF_IMAGE_FORMAT_RGB16):
205 return("IMAGE_FORMAT_RGB16");
206
207 case ((int)CF_IMAGE_FORMAT_JPEG):
208 return("IMAGE_FORMAT_JPEG");
209
210 case ((int)CF_IMAGE_FORMAT_TIFF):
211 return("IMAGE_FORMAT_TIFF");
212
213 case ((int)CF_IMAGE_FORMAT_YUV411):
214 return("IMAGE_FORMAT_YUV411");
215
216 case ((int)CF_IMAGE_FORMAT_YUV422):
217 return("IMAGE_FORMAT_YUV422");
218
219 case ((int)CF_IMAGE_FORMAT_YUV444):
220 return("IMAGE_FORMAT_YUV444");
221
222 case ((int)CF_IMAGE_FORMAT_HUFFYUV):
223 return("IMAGE_FORMAT_HUFFYUV");
224
225 case ((int)CF_IMAGE_FORMAT_BMP):
226 return("IMAGE_FORMAT_BMP");
227
228 case ((int)CF_IMAGE_FORMAT_BAYER):
229 return("IMAGE_FORMAT_BAYER");
230
231 default:
232 return("Unknown!");
233 }
234 }
235
236 /**
237 * in order to get the real width of the image bits appended this function must be used.
238 * In case if the area of interest is set, one can not directly look at sourceWidth
239 * because aoiWidth depict the height of the appended image in such case
240 *
241 * @return the width in pixels of the appended image data bits
242 */
243 public int getAppendedWidth()
244 {
245 if (frameHeader.aoiWidth != -1)
246 return frameHeader.aoiWidth;
247 else
248 return frameHeader.sourceWidth;
249 }
250
251 /**
252 * in order to get the real height of the image bits appended this function must be used.
253 * In case if the area of interest is set, one can not directly look at sourceHeight
254 * because aoiHeight depict the height of the appended image in such case
255 *
256 * @return the height in pixels of the appended image data bits
257 */
258 public int getAppendedHeight()
259 {
260 if (frameHeader.aoiHeight != -1)
261 return frameHeader.aoiHeight;
262 else
263 return frameHeader.sourceHeight;
264 }
265
266 /*
267 * preinitialize, used in default constructor
268 */
269 private void init()
270 {
271 sourceHeader.versionTag = CF_IMAGE_VERSION;
272 sourceHeader.totalLength = HDRSIZE;
273 /*
274 timestamp = null;
275 name_of_cameraport="";
276
277 calc_appended_width=-1;
278 calc_appended_height=-1;
279
280 imH_width = -1;
281 imH_height = -1;
282 imH_aoi_width = -1;
283 imH_aoi_height = -1;
284 imH_x_start = 0;
285 imH_y_start = 0;
286 imH_bypp = -1;
287 imH_ebitpp = -1;
288 imH_vbin = -1;
289 imH_hbin = -1;
290 imH_source_format = CF_IMAGE_FORMAT_GRAY;
291 imH_image_format = CF_IMAGE_FORMAT_GRAY;
292
293 imH_framenumber = -1;
294 imH_eventnumber = -1;
295
296 imH_scale_x = -1.0;
297 imH_scale_y = -1.0;
298 imH_image_rotation = 0.0;
299 imH_fspare2 = -1.0;
300 imH_fspare3 = -1.0;
301 imH_fspare4 = -1.0;
302
303 imH_image_flags = 0; // big endian byte order
304 imH_ispare2 = -1;
305 imH_ispare3 = -1;
306 imH_ispare4 = -1;
307 imH_length = 0;
308 */
309 }
310 }
311