Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/internal/image/JPEGQuantizationTable.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | f713da8bc051 |
children |
rev | line source |
---|---|
25 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 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 org.eclipse.swt.internal.image.JPEGQuantizationTable; | |
14 | |
15 import org.eclipse.swt.internal.image.LEDataInputStream; | |
16 import org.eclipse.swt.internal.image.JPEGVariableSizeSegment; | |
17 import org.eclipse.swt.internal.image.JPEGFileFormat; | |
18 | |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
25
diff
changeset
|
19 import java.lang.System; |
25 | 20 |
21 final class JPEGQuantizationTable : JPEGVariableSizeSegment { | |
22 public static byte[] DefaultLuminanceQTable = [ | |
23 cast(byte)255, cast(byte)219, 0, 67, 0, | |
24 16, 11, 10, 16, 24, 40, 51, 61, | |
25 12, 12, 14, 19, 26, 58, 60, 55, | |
26 14, 13, 16, 24, 40, 57, 69, 56, | |
27 14, 17, 22, 29, 51, 87, 80, 62, | |
28 18, 22, 37, 56, 68, 109, 103, 77, | |
29 24, 35, 55, 64, 81, 104, 113, 92, | |
30 49, 64, 78, 87, 103, 121, 120, 101, | |
31 72, 92, 95, 98, 112, 100, 103, 99 | |
32 ]; | |
33 public static byte[] DefaultChrominanceQTable = [ | |
34 cast(byte)255, cast(byte)219, 0, 67, 1, | |
35 17, 18, 24, 47, 99, 99, 99, 99, | |
36 18, 21, 26, 66, 99, 99, 99, 99, | |
37 24, 26, 56, 99, 99, 99, 99, 99, | |
38 47, 66, 99, 99, 99, 99, 99, 99, | |
39 99, 99, 99, 99, 99, 99, 99, 99, | |
40 99, 99, 99, 99, 99, 99, 99, 99, | |
41 99, 99, 99, 99, 99, 99, 99, 99, | |
42 99, 99, 99, 99, 99, 99, 99, 99 | |
43 ]; | |
44 | |
45 public this(byte[] reference) { | |
46 super(reference); | |
47 } | |
48 | |
49 public this(LEDataInputStream byteStream) { | |
50 super(byteStream); | |
51 } | |
52 | |
53 public static JPEGQuantizationTable defaultChrominanceTable() { | |
54 byte[] data = new byte[DefaultChrominanceQTable.length]; | |
55 System.arraycopy(DefaultChrominanceQTable, 0, data, 0, data.length); | |
56 return new JPEGQuantizationTable(data); | |
57 } | |
58 | |
59 public static JPEGQuantizationTable defaultLuminanceTable() { | |
60 byte[] data = new byte[DefaultLuminanceQTable.length]; | |
61 System.arraycopy(DefaultLuminanceQTable, 0, data, 0, data.length); | |
62 return new JPEGQuantizationTable(data); | |
63 } | |
64 | |
65 public int[] getQuantizationTablesKeys() { | |
66 int[] keys = new int[4]; | |
67 int keysIndex = 0; | |
68 int totalLength = getSegmentLength() - 2; | |
69 int ofs = 4; | |
70 while (totalLength > 64) { | |
71 int tq = reference[ofs] & 0xF; | |
72 int pq = (reference[ofs] & 0xFF) >> 4; | |
73 if (pq is 0) { | |
74 ofs += 65; | |
75 totalLength -= 65; | |
76 } else { | |
77 ofs += 129; | |
78 totalLength -= 129; | |
79 } | |
80 if (keysIndex >= keys.length) { | |
81 int[] newKeys = new int[keys.length + 4]; | |
82 System.arraycopy(keys, 0, newKeys, 0, keys.length); | |
83 keys = newKeys; | |
84 } | |
85 keys[keysIndex] = tq; | |
86 keysIndex++; | |
87 } | |
88 int[] newKeys = new int[keysIndex]; | |
89 System.arraycopy(keys, 0, newKeys, 0, keysIndex); | |
90 return newKeys; | |
91 } | |
92 | |
93 public int[][] getQuantizationTablesValues() { | |
94 int[][] values = new int[][](4); | |
95 int valuesIndex = 0; | |
96 int totalLength = getSegmentLength() - 2; | |
97 int ofs = 4; | |
98 while (totalLength > 64) { | |
99 int[] qk = new int[64]; | |
100 int pq = (reference[ofs] & 0xFF) >> 4; | |
101 if (pq is 0) { | |
102 for (int i = 0; i < qk.length; i++) { | |
103 qk[i] = reference[ofs + i + 1] & 0xFF; | |
104 } | |
105 ofs += 65; | |
106 totalLength -= 65; | |
107 } else { | |
108 for (int i = 0; i < qk.length; i++) { | |
109 int idx = (i - 1) * 2 ; | |
110 qk[i] = (reference[ofs + idx + 1] & 0xFF) * 256 + (reference[ofs + idx + 2] & 0xFF); | |
111 } | |
112 ofs += 129; | |
113 totalLength -= 129; | |
114 } | |
115 if (valuesIndex >= values.length) { | |
116 int[][] newValues = new int[][](values.length + 4); | |
117 System.arraycopy(values, 0, newValues, 0, values.length); | |
118 values = newValues; | |
119 } | |
120 values[valuesIndex] = qk; | |
121 valuesIndex++; | |
122 } | |
123 int[][] newValues = new int[][](valuesIndex); | |
124 System.arraycopy(values, 0, newValues, 0, valuesIndex); | |
125 return newValues; | |
126 } | |
127 | |
128 public void scaleBy(int qualityFactor) { | |
129 int qFactor = qualityFactor; | |
130 if (qFactor <= 0) { | |
131 qFactor = 1; | |
132 } | |
133 if (qFactor > 100) { | |
134 qFactor = 100; | |
135 } | |
136 if (qFactor < 50) { | |
137 qFactor = 5000 / qFactor; | |
138 } else { | |
139 qFactor = 200 - (qFactor * 2); | |
140 } | |
141 int totalLength = getSegmentLength() - 2; | |
142 int ofs = 4; | |
143 while (totalLength > 64) { | |
144 // int tq = reference[ofs] & 0xFF; | |
145 int pq = (reference[ofs] & 0xFF) >> 4; | |
146 if (pq is 0) { | |
147 for (int i = ofs + 1; i <= ofs + 64; i++) { | |
148 int temp = ((reference[i] & 0xFF) * qFactor + 50) / 100; | |
149 if (temp <= 0) temp = 1; | |
150 if (temp > 255) temp = 255; | |
151 reference[i] = cast(byte)temp; | |
152 } | |
153 ofs += 65; | |
154 totalLength -= 65; | |
155 } else { | |
156 for (int i = ofs + 1; i <= ofs + 128; i += 2) { | |
157 int temp = (((reference[i] & 0xFF) * 256 + (reference[i + 1] & 0xFF)) * qFactor + 50) / 100; | |
158 if (temp <= 0) temp = 1; | |
159 if (temp > 32767) temp = 32767; | |
160 reference[i] = cast(byte)(temp >> 8); | |
161 reference[i + 1] = cast(byte)(temp & 0xFF); | |
162 } | |
163 ofs += 129; | |
164 totalLength -= 129; | |
165 } | |
166 } | |
167 } | |
168 | |
169 public override int signature() { | |
170 return JPEGFileFormat.DQT; | |
171 } | |
172 } |