Mercurial > projects > dwt-win
annotate dwt/internal/image/JPEGFrameHeader.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | 9a64a7781bab |
children |
rev | line source |
---|---|
31
92c102dd64a3
Added all widgets modules as dummy. Most modules of accessible are equal to the linux version, except Accessible.
Frank Benoit <benoit@tionex.de>
parents:
2
diff
changeset
|
1 /******************************************************************************* |
2
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
2 * Copyright (c) 2000, 2005 IBM Corporation and others. |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
7 * |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
8 * Contributors: |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
10 * Port to the D programming language: |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
11 * Frank Benoit <benoit@tionex.de> |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
12 *******************************************************************************/ |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
13 module dwt.internal.image.JPEGFrameHeader; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
14 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
15 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
16 import dwt.DWT; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
17 import dwt.internal.image.JPEGVariableSizeSegment; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
18 import dwt.internal.image.JPEGFileFormat; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
19 import dwt.internal.image.LEDataInputStream; |
213 | 20 import dwt.dwthelper.utils; |
2
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
21 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
22 final class JPEGFrameHeader : JPEGVariableSizeSegment { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
23 int maxVFactor; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
24 int maxHFactor; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
25 public int[] componentIdentifiers; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
26 public int[][] componentParameters; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
27 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
28 public this(byte[] reference) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
29 super(reference); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
30 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
31 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
32 public this(LEDataInputStream byteStream) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
33 super(byteStream); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
34 initializeComponentParameters(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
35 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
36 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
37 public int getSamplePrecision() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
38 return reference[4] & 0xFF; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
39 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
40 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
41 public int getNumberOfLines() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
42 return (reference[5] & 0xFF) << 8 | (reference[6] & 0xFF); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
43 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
44 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
45 public int getSamplesPerLine() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
46 return (reference[7] & 0xFF) << 8 | (reference[8] & 0xFF); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
47 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
48 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
49 public int getNumberOfImageComponents() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
50 return reference[9] & 0xFF; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
51 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
52 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
53 public void setSamplePrecision(int precision) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
54 reference[4] = cast(byte)(precision & 0xFF); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
55 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
56 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
57 public void setNumberOfLines(int anInteger) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
58 reference[5] = cast(byte)((anInteger & 0xFF00) >> 8); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
59 reference[6] = cast(byte)(anInteger & 0xFF); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
60 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
61 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
62 public void setSamplesPerLine(int samples) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
63 reference[7] = cast(byte)((samples & 0xFF00) >> 8); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
64 reference[8] = cast(byte)(samples & 0xFF); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
65 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
66 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
67 public void setNumberOfImageComponents(int anInteger) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
68 reference[9] = cast(byte)(anInteger & 0xFF); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
69 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
70 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
71 public int getMaxHFactor() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
72 return maxHFactor; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
73 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
74 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
75 public int getMaxVFactor() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
76 return maxVFactor; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
77 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
78 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
79 public void setMaxHFactor(int anInteger) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
80 maxHFactor = anInteger; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
81 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
82 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
83 public void setMaxVFactor(int anInteger) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
84 maxVFactor = anInteger; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
85 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
86 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
87 /* Used when decoding. */ |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
88 void initializeComponentParameters() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
89 int nf = getNumberOfImageComponents(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
90 componentIdentifiers = new int[nf]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
91 int[][] compSpecParams; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
92 int hmax = 1; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
93 int vmax = 1; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
94 for (int i = 0; i < nf; i++) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
95 int ofs = i * 3 + 10; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
96 int ci = reference[ofs] & 0xFF; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
97 componentIdentifiers[i] = ci; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
98 int hi = (reference[ofs + 1] & 0xFF) >> 4; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
99 int vi = reference[ofs + 1] & 0xF; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
100 int tqi = reference[ofs + 2] & 0xFF; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
101 if (hi > hmax) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
102 hmax = hi; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
103 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
104 if (vi > vmax) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
105 vmax = vi; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
106 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
107 int[] compParam = new int[5]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
108 compParam[0] = tqi; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
109 compParam[1] = hi; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
110 compParam[2] = vi; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
111 if (compSpecParams.length <= ci) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
112 int[][] newParams = new int[][](ci + 1); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
113 System.arraycopy(compSpecParams, 0, newParams, 0, compSpecParams.length); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
114 compSpecParams = newParams; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
115 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
116 compSpecParams[ci] = compParam; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
117 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
118 int x = getSamplesPerLine(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
119 int y = getNumberOfLines(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
120 int[] multiples = [ 8, 16, 24, 32 ]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
121 for (int i = 0; i < nf; i++) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
122 int[] compParam = compSpecParams[componentIdentifiers[i]]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
123 int hi = compParam[1]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
124 int vi = compParam[2]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
125 int compWidth = (x * hi + hmax - 1) / hmax; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
126 int compHeight = (y * vi + vmax - 1) / vmax; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
127 int dsWidth = roundUpToMultiple(compWidth, multiples[hi - 1]); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
128 int dsHeight = roundUpToMultiple(compHeight, multiples[vi - 1]); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
129 compParam[3] = dsWidth; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
130 compParam[4] = dsHeight; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
131 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
132 setMaxHFactor(hmax); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
133 setMaxVFactor(vmax); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
134 componentParameters = compSpecParams; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
135 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
136 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
137 /* Used when encoding. */ |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
138 public void initializeContents() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
139 int nf = getNumberOfImageComponents(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
140 if (nf is 0 || nf !is componentParameters.length) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
141 DWT.error(DWT.ERROR_INVALID_IMAGE); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
142 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
143 int hmax = 0; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
144 int vmax = 0; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
145 int[][] compSpecParams = componentParameters; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
146 for (int i = 0; i < nf; i++) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
147 int ofs = i * 3 + 10; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
148 int[] compParam = compSpecParams[componentIdentifiers[i]]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
149 int hi = compParam[1]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
150 int vi = compParam[2]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
151 if (hi * vi > 4) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
152 DWT.error(DWT.ERROR_INVALID_IMAGE); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
153 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
154 reference[ofs] = cast(byte)(i + 1); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
155 reference[ofs + 1] = cast(byte)(hi * 16 + vi); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
156 reference[ofs + 2] = cast(byte)(compParam[0]); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
157 if (hi > hmax) hmax = hi; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
158 if (vi > vmax) vmax = vi; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
159 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
160 int x = getSamplesPerLine(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
161 int y = getNumberOfLines(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
162 int[] multiples = [8, 16, 24, 32]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
163 for (int i = 0; i < nf; i++) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
164 int[] compParam = compSpecParams[componentIdentifiers[i]]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
165 int hi = compParam[1]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
166 int vi = compParam[2]; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
167 int compWidth = (x * hi + hmax - 1) / hmax; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
168 int compHeight = (y * vi + vmax - 1) / vmax; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
169 int dsWidth = roundUpToMultiple(compWidth, multiples[hi - 1]); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
170 int dsHeight = roundUpToMultiple(compHeight, multiples[vi - 1]); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
171 compParam[3] = dsWidth; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
172 compParam[4] = dsHeight; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
173 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
174 setMaxHFactor(hmax); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
175 setMaxVFactor(vmax); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
176 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
177 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
178 int roundUpToMultiple(int anInteger, int mInteger) { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
179 int a = anInteger + mInteger - 1; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
180 return a - (a % mInteger); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
181 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
182 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
183 /* |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
184 * Verify the information contained in the receiver is correct. |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
185 * Answer true if the header contains a valid marker. Otherwise, |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
186 * answer false. Valid Start Of Frame markers are: |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
187 * SOF_0 - Baseline DCT, Huffman coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
188 * SOF_1 - Extended sequential DCT, Huffman coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
189 * SOF_2 - Progressive DCT, Huffman coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
190 * SOF_3 - Lossless (sequential), Huffman coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
191 * SOF_5 - Differential sequential, Huffman coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
192 * SOF_6 - Differential progressive, Huffman coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
193 * SOF_7 - Differential lossless, Huffman coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
194 * SOF_9 - Extended sequential DCT, arithmetic coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
195 * SOF_10 - Progressive DCT, arithmetic coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
196 * SOF_11 - Lossless (sequential), arithmetic coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
197 * SOF_13 - Differential sequential, arithmetic coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
198 * SOF_14 - Differential progressive, arithmetic coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
199 * SOF_15 - Differential lossless, arithmetic coding |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
200 */ |
213 | 201 public override bool verify() { |
2
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
202 int marker = getSegmentMarker(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
203 return (marker >= JPEGFileFormat.SOF0 && marker <= JPEGFileFormat.SOF3) || |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
204 (marker >= JPEGFileFormat.SOF5 && marker <= JPEGFileFormat.SOF7) || |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
205 (marker >= JPEGFileFormat.SOF9 && marker <= JPEGFileFormat.SOF11) || |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
206 (marker >= JPEGFileFormat.SOF13 && marker <= JPEGFileFormat.SOF15); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
207 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
208 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
209 public bool isProgressive() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
210 int marker = getSegmentMarker(); |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
211 return marker is JPEGFileFormat.SOF2 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
212 || marker is JPEGFileFormat.SOF6 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
213 || marker is JPEGFileFormat.SOF10 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
214 || marker is JPEGFileFormat.SOF14; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
215 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
216 |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
217 public bool isArithmeticCoding() { |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
218 return getSegmentMarker() >= JPEGFileFormat.SOF9; |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
219 } |
57151e2793a2
More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
220 } |