comparison dwt/internal/image/JPEGSegment.d @ 34:5123b17c98ef

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