comparison dwt/internal/image/JPEGSegment.d @ 13:3d9bbe0a83a0

FileFormats
author Frank Benoit <benoit@tionex.de>
date Sun, 06 Jan 2008 22:54:14 +0100
parents
children 8cec8f536af3
comparison
equal deleted inserted replaced
12:0c78fa47d476 13:3d9bbe0a83a0
1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 module dwt.internal.image.JPEGSegment;
12
13 import dwt.internal.image.LEDataOutputStream;
14
15 import tango.core.Exception;
16
17 class JPEGSegment {
18 public byte[] reference;
19
20 this() {
21 }
22
23 public this(byte[] reference) {
24 this.reference = reference;
25 }
26
27 public int signature() {
28 return 0;
29 }
30
31 public bool verify() {
32 return getSegmentMarker() == signature();
33 }
34
35 public int getSegmentMarker() {
36 return ((reference[0] & 0xFF) << 8 | (reference[1] & 0xFF));
37 }
38
39 public void setSegmentMarker(int marker) {
40 reference[0] = cast(byte)((marker & 0xFF00) >> 8);
41 reference[1] = cast(byte)(marker & 0xFF);
42 }
43
44 public int getSegmentLength() {
45 return ((reference[2] & 0xFF) << 8 | (reference[3] & 0xFF));
46 }
47
48 public void setSegmentLength(int length) {
49 reference[2] = cast(byte)((length & 0xFF00) >> 8);
50 reference[3] = cast(byte)(length & 0xFF);
51 }
52
53 public bool writeToStream(LEDataOutputStream byteStream) {
54 try {
55 byteStream.write(reference);
56 return true;
57 } catch (TracedException e) {
58 return false;
59 }
60 }
61 }