root/dwt/internal/image/JPEGSegment.d

Revision 57:41dbc4d9faab, 1.8 kB (checked in by Frank Benoit <benoit@tionex.de>, 1 year ago)

Update to tango trunk -r3152. Thanks DavidLeon? for the adjustment of TracedException? to Exception and creating the patch.

Line 
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  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module dwt.internal.image.JPEGSegment;
14
15 import dwt.internal.image.LEDataOutputStream;
16
17 import tango.core.Exception;
18
19 class JPEGSegment {
20     public byte[] reference;
21
22     this() {
23     }
24
25     public this(byte[] reference) {
26         this.reference = reference;
27     }
28
29     public int signature() {
30         return 0;
31     }
32
33     public bool verify() {
34         return getSegmentMarker() is signature();
35     }
36
37     public int getSegmentMarker() {
38         return ((reference[0] & 0xFF) << 8 | (reference[1] & 0xFF));
39     }
40
41     public void setSegmentMarker(int marker) {
42         reference[0] = cast(byte)((marker & 0xFF00) >> 8);
43         reference[1] = cast(byte)(marker & 0xFF);
44     }
45
46     public int getSegmentLength() {
47         return ((reference[2] & 0xFF) << 8 | (reference[3] & 0xFF));
48     }
49
50     public void setSegmentLength(int length) {
51         reference[2] = cast(byte)((length & 0xFF00) >> 8);
52         reference[3] = cast(byte)(length & 0xFF);
53     }
54
55     public bool writeToStream(LEDataOutputStream byteStream) {
56         try {
57             byteStream.write(reference);
58             return true;
59         } catch (Exception e) {
60             return false;
61         }
62     }
63 }
Note: See TracBrowser for help on using the browser.