1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# HG changeset patch
# User bae
# Date 1369130199 -14400
# Tue May 21 13:56:39 2013 +0400
# Node ID d55d40616754cd93aa396719ddfd81bae584d4f0
# Parent 5405d79569f76d1285fd3c840489477a81bd9eff
8014102: Improve image conversion
Reviewed-by: prr
diff -r 5405d79569f7 -r d55d40616754 src/share/native/sun/awt/medialib/awt_ImagingLib.c
--- jdk/src/share/native/sun/awt/medialib/awt_ImagingLib.c Fri May 17 16:47:51 2013 +0400
+++ jdk/src/share/native/sun/awt/medialib/awt_ImagingLib.c Tue May 21 13:56:39 2013 +0400
@@ -1986,21 +1986,25 @@
return 0;
}
+#define NUM_LINES 10
+
static int
cvtCustomToDefault(JNIEnv *env, BufImageS_t *imageP, int component,
unsigned char *dataP) {
- ColorModelS_t *cmP = &imageP->cmodel;
- RasterS_t *rasterP = &imageP->raster;
+ const RasterS_t *rasterP = &imageP->raster;
+ const int w = rasterP->width;
+ const int h = rasterP->height;
+
int y;
- jobject jpixels = NULL;
+ jintArray jpixels = NULL;
jint *pixels;
unsigned char *dP = dataP;
-#define NUM_LINES 10
- int numLines = NUM_LINES;
+ int numLines = h > NUM_LINES ? NUM_LINES : h;
+
/* it is safe to calculate the scan length, because width has been verified
* on creation of the mlib image
*/
- int scanLength = rasterP->width * 4;
+ const int scanLength = w * 4;
int nbytes = 0;
if (!SAFE_TO_MULT(numLines, scanLength)) {
@@ -2009,71 +2013,99 @@
nbytes = numLines * scanLength;
- for (y=0; y < rasterP->height; y+=numLines) {
- /* getData, one scanline at a time */
- if (y+numLines > rasterP->height) {
- numLines = rasterP->height - y;
- nbytes = numLines * scanLength;
- }
- jpixels = (*env)->CallObjectMethod(env, imageP->jimage,
- g_BImgGetRGBMID, 0, y,
- rasterP->width, numLines,
- jpixels,0, rasterP->width);
- if (jpixels == NULL) {
- JNU_ThrowInternalError(env, "Can't retrieve pixels.");
- return -1;
- }
-
- pixels = (*env)->GetPrimitiveArrayCritical(env, jpixels, NULL);
- memcpy(dP, pixels, nbytes);
- dP += nbytes;
- (*env)->ReleasePrimitiveArrayCritical(env, jpixels, pixels,
- JNI_ABORT);
- }
- return 0;
-}
-
-static int
-cvtDefaultToCustom(JNIEnv *env, BufImageS_t *imageP, int component,
- unsigned char *dataP) {
- ColorModelS_t *cmP = &imageP->cmodel;
- RasterS_t *rasterP = &imageP->raster;
- int y;
- jint *pixels;
- unsigned char *dP = dataP;
-#define NUM_LINES 10
- int numLines = NUM_LINES;
- int nbytes = rasterP->width*4*NUM_LINES;
- jintArray jpixels;
-
jpixels = (*env)->NewIntArray(env, nbytes);
if (JNU_IsNull(env, jpixels)) {
JNU_ThrowOutOfMemoryError(env, "Out of Memory");
return -1;
}
- for (y=0; y < rasterP->height; y+=NUM_LINES) {
- if (y+numLines > rasterP->height) {
- numLines = rasterP->height - y;
- nbytes = rasterP->width*4*numLines;
+ for (y = 0; y < h; y += numLines) {
+ if (y + numLines > h) {
+ numLines = h - y;
+ nbytes = numLines * scanLength;
}
+
+ (*env)->CallObjectMethod(env, imageP->jimage,
+ g_BImgGetRGBMID, 0, y,
+ w, numLines,
+ jpixels, 0, w);
+ if ((*env)->ExceptionOccurred(env)) {
+ (*env)->DeleteLocalRef(env, jpixels);
+ return -1;
+ }
+
pixels = (*env)->GetPrimitiveArrayCritical(env, jpixels, NULL);
if (pixels == NULL) {
- /* JNI error */
+ (*env)->DeleteLocalRef(env, jpixels);
return -1;
}
+ memcpy(dP, pixels, nbytes);
+ dP += nbytes;
+
+ (*env)->ReleasePrimitiveArrayCritical(env, jpixels, pixels,
+ JNI_ABORT);
+ }
+
+ /* Need to release the array */
+ (*env)->DeleteLocalRef(env, jpixels);
+
+ return 0;
+}
+
+static int
+cvtDefaultToCustom(JNIEnv *env, BufImageS_t *imageP, int component,
+ unsigned char *dataP) {
+ const RasterS_t *rasterP = &imageP->raster;
+ const int w = rasterP->width;
+ const int h = rasterP->height;
+
+ int y;
+ jintArray jpixels = NULL;
+ jint *pixels;
+ unsigned char *dP = dataP;
+ int numLines = h > NUM_LINES ? NUM_LINES : h;
+
+ /* it is safe to calculate the scan length, because width has been verified
+ * on creation of the mlib image
+ */
+ const int scanLength = w * 4;
+
+ int nbytes = 0;
+ if (!SAFE_TO_MULT(numLines, scanLength)) {
+ return -1;
+ }
+
+ nbytes = numLines * scanLength;
+
+ jpixels = (*env)->NewIntArray(env, nbytes);
+ if (JNU_IsNull(env, jpixels)) {
+ JNU_ThrowOutOfMemoryError(env, "Out of Memory");
+ return -1;
+ }
+
+ for (y = 0; y < h; y += numLines) {
+ if (y + numLines > h) {
+ numLines = h - y;
+ nbytes = numLines * scanLength;
+ }
+
+ pixels = (*env)->GetPrimitiveArrayCritical(env, jpixels, NULL);
+ if (pixels == NULL) {
+ (*env)->DeleteLocalRef(env, jpixels);
+ return -1;
+ }
+
memcpy(pixels, dP, nbytes);
dP += nbytes;
(*env)->ReleasePrimitiveArrayCritical(env, jpixels, pixels, 0);
- /* setData, one scanline at a time */
- /* Fix 4223648, 4184283 */
(*env)->CallVoidMethod(env, imageP->jimage, g_BImgSetRGBMID, 0, y,
- rasterP->width, numLines, jpixels, 0,
- rasterP->width);
+ w, numLines, jpixels,
+ 0, w);
if ((*env)->ExceptionOccurred(env)) {
+ (*env)->DeleteLocalRef(env, jpixels);
return -1;
}
}
|