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 | |
package wjhk.jupload2.filedata.helper; |
27 | |
|
28 | |
import java.awt.Image; |
29 | |
import java.awt.geom.AffineTransform; |
30 | |
import java.awt.image.AffineTransformOp; |
31 | |
import java.awt.image.BufferedImage; |
32 | |
import java.awt.image.ImageObserver; |
33 | |
|
34 | |
import wjhk.jupload2.exception.JUploadException; |
35 | |
import wjhk.jupload2.exception.JUploadIOException; |
36 | |
import wjhk.jupload2.filedata.DefaultFileData; |
37 | |
import wjhk.jupload2.filedata.PictureFileData; |
38 | |
import wjhk.jupload2.policies.PictureUploadPolicy; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public class ImageHelper implements ImageObserver { |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 10 | private Boolean hasToTransformPicture = null; |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
private PictureFileData pictureFileData; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
private int quarterRotation; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
private int maxWidth; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private int maxHeight; |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 10 | private int nbPixelsTotal = -1; |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | 10 | private int nbPixelsRead = 0; |
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | 10 | private int scaledNonRotatedWidth = -1; |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | 10 | private int scaledNonRotatedHeight = -1; |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | 10 | private int progressBarBaseValue = 0; |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | 10 | private double scale = 1; |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | 10 | private int scaledRotatedWidth = -1; |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | 10 | private int scaledRotatedHeight = -1; |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
PictureUploadPolicy uploadPolicy; |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
public ImageHelper(PictureUploadPolicy uploadPolicy, PictureFileData pictureFileData, int targetMaxWidth, |
151 | 10 | int targetMaxHeight, int quarterRotation) throws JUploadIOException { |
152 | 10 | this.uploadPolicy = uploadPolicy; |
153 | 10 | this.pictureFileData = pictureFileData; |
154 | 10 | this.maxWidth = targetMaxWidth; |
155 | 10 | this.maxHeight = targetMaxHeight; |
156 | 10 | this.quarterRotation = quarterRotation; |
157 | |
|
158 | |
|
159 | |
|
160 | 10 | initScale(); |
161 | 10 | } |
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
private void initScale() throws JUploadIOException { |
168 | 10 | double theta = Math.toRadians(90 * this.quarterRotation); |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | 10 | int nonScaledRotatedWidth = this.pictureFileData.getOriginalWidth(); |
174 | 10 | int nonScaledRotatedHeight = this.pictureFileData.getOriginalHeight(); |
175 | 10 | if (this.quarterRotation % 2 != 0) { |
176 | |
|
177 | |
|
178 | 3 | nonScaledRotatedWidth = this.pictureFileData.getOriginalHeight(); |
179 | 3 | nonScaledRotatedHeight = this.pictureFileData.getOriginalWidth(); |
180 | |
} |
181 | |
|
182 | |
|
183 | 10 | double scaleWidth = ((this.maxWidth < 0) ? 1 : ((double) this.maxWidth) / nonScaledRotatedWidth); |
184 | 10 | double scaleHeight = ((this.maxHeight < 0) ? 1 : ((double) this.maxHeight) / nonScaledRotatedHeight); |
185 | 10 | this.scale = Math.min(scaleWidth, scaleHeight); |
186 | 10 | if (this.scale < 1) { |
187 | |
|
188 | |
|
189 | 4 | if ((this.maxWidth > 0 && this.maxWidth < (int) (this.scale * Math.cos(theta) * nonScaledRotatedWidth)) |
190 | 4 | || (this.maxHeight > 0 && this.maxHeight < (int) (this.scale * Math.cos(theta) * nonScaledRotatedHeight))) { |
191 | 0 | scaleWidth = ((this.maxWidth < 0) ? 1 : ((double) this.maxWidth - 1) / (nonScaledRotatedWidth)); |
192 | 0 | scaleHeight = ((this.maxHeight < 0) ? 1 : ((double) this.maxHeight - 1) / (nonScaledRotatedHeight)); |
193 | 0 | this.scale = Math.min(scaleWidth, scaleHeight); |
194 | |
} |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | 10 | this.scaledRotatedWidth = nonScaledRotatedWidth; |
200 | 10 | this.scaledRotatedHeight = nonScaledRotatedHeight; |
201 | |
|
202 | |
|
203 | |
|
204 | 10 | if (this.scale < 1) { |
205 | 4 | this.scaledRotatedWidth *= this.scale; |
206 | 4 | this.scaledRotatedHeight *= this.scale; |
207 | 4 | this.uploadPolicy.displayDebug("Resizing factor (scale): " + this.scale, 30); |
208 | |
} else { |
209 | 6 | this.uploadPolicy.displayDebug("Resizing factor (scale): no resizing (calculated scale was " + this.scale |
210 | |
+ ")", 30); |
211 | |
} |
212 | |
|
213 | |
|
214 | |
|
215 | 10 | if (this.scaledRotatedWidth > this.maxWidth) { |
216 | 0 | this.uploadPolicy.displayDebug("Correcting rounded width: " + this.scaledRotatedWidth + " to " |
217 | |
+ this.maxWidth, 50); |
218 | 0 | this.scaledRotatedWidth = this.maxWidth; |
219 | |
} |
220 | 10 | if (this.scaledRotatedHeight > this.maxHeight) { |
221 | 0 | this.uploadPolicy.displayDebug("Correcting rounded height: " + this.scaledRotatedHeight + " to " |
222 | |
+ this.maxHeight, 50); |
223 | 0 | this.scaledRotatedHeight = this.maxHeight; |
224 | |
} |
225 | |
|
226 | |
|
227 | 10 | if (this.quarterRotation % 2 == 0) { |
228 | 7 | this.scaledNonRotatedWidth = this.scaledRotatedWidth; |
229 | 7 | this.scaledNonRotatedHeight = this.scaledRotatedHeight; |
230 | |
} else { |
231 | 3 | this.scaledNonRotatedWidth = this.scaledRotatedHeight; |
232 | 3 | this.scaledNonRotatedHeight = this.scaledRotatedWidth; |
233 | |
} |
234 | 10 | } |
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
public boolean hasToTransformPicture() throws JUploadException { |
244 | |
|
245 | |
|
246 | 8 | if (DefaultFileData.getExtension(this.pictureFileData.getFileName()).equalsIgnoreCase("gif")) { |
247 | |
|
248 | |
|
249 | 0 | ImageReaderWriterHelper irwh = new ImageReaderWriterHelper(this.uploadPolicy, this.pictureFileData); |
250 | 0 | int nbImages = irwh.getNumImages(true); |
251 | 0 | irwh.dispose(); |
252 | 0 | irwh = null; |
253 | 0 | if (nbImages > 1) { |
254 | |
|
255 | 0 | this.hasToTransformPicture = Boolean.FALSE; |
256 | 0 | this.uploadPolicy |
257 | 0 | .displayWarn("No transformation for gif picture file, that contain several pictures. (see JUpload documentation for details)"); |
258 | |
} |
259 | |
} |
260 | |
|
261 | |
|
262 | 8 | if (this.hasToTransformPicture == null) { |
263 | |
|
264 | |
|
265 | 8 | if (this.hasToTransformPicture == null && !(this.uploadPolicy).getPictureTransmitMetadata()) { |
266 | 0 | this.hasToTransformPicture = Boolean.TRUE; |
267 | 0 | this.uploadPolicy.displayDebug(this.pictureFileData.getFileName() |
268 | |
+ " : hasToTransformPicture=true (pictureTransmitMetadata is false)", 80); |
269 | |
} |
270 | |
|
271 | 8 | if (this.hasToTransformPicture == null && this.quarterRotation != 0) { |
272 | 3 | this.uploadPolicy.displayDebug(this.pictureFileData.getFileName() |
273 | |
+ " : hasToTransformPicture = true (quarterRotation != 0)", 10); |
274 | 3 | this.hasToTransformPicture = Boolean.TRUE; |
275 | |
} |
276 | |
|
277 | |
|
278 | 16 | String targetFormat = this.uploadPolicy.getImageFileConversionInfo().getTargetFormatOrNull( |
279 | 8 | this.pictureFileData.getFileExtension()); |
280 | 8 | if (this.hasToTransformPicture == null && targetFormat != null) { |
281 | 0 | this.uploadPolicy.displayDebug(this.pictureFileData.getFileName() |
282 | |
+ " : hasToTransformPicture = true (targetPictureFormat)", 10); |
283 | 0 | this.hasToTransformPicture = Boolean.TRUE; |
284 | |
} |
285 | |
|
286 | |
|
287 | 8 | if (this.hasToTransformPicture == null && this.scale < 1) { |
288 | 2 | this.uploadPolicy.displayDebug(this.pictureFileData.getFileName() |
289 | |
+ " : hasToTransformPicture = true (scale < 1)", 10); |
290 | 2 | this.hasToTransformPicture = Boolean.TRUE; |
291 | |
} |
292 | |
|
293 | |
|
294 | |
|
295 | 8 | if (this.hasToTransformPicture == null) { |
296 | 3 | this.uploadPolicy.displayDebug(this.pictureFileData.getFileName() + " : hasToTransformPicture = false", |
297 | |
10); |
298 | 3 | this.hasToTransformPicture = Boolean.FALSE; |
299 | 3 | this.uploadPolicy.displayDebug(this.pictureFileData.getFileName() + " : hasToTransformPicture = false", |
300 | |
10); |
301 | |
} |
302 | |
} |
303 | |
|
304 | 8 | return this.hasToTransformPicture.booleanValue(); |
305 | |
} |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
public BufferedImage getBufferedImage(boolean highquality, BufferedImage sourceBufferedImage) |
326 | |
throws JUploadException { |
327 | 7 | long msGetBufferedImage = System.currentTimeMillis(); |
328 | 7 | double theta = Math.toRadians(90 * this.quarterRotation); |
329 | |
|
330 | 7 | BufferedImage returnedBufferedImage = null; |
331 | |
|
332 | 7 | this.uploadPolicy.displayDebug("getBufferedImage: start", 10); |
333 | |
|
334 | |
try { |
335 | 7 | AffineTransform transform = new AffineTransform(); |
336 | |
|
337 | 7 | if (this.quarterRotation != 0) { |
338 | 3 | double translationX = 0, translationY = 0; |
339 | 3 | this.uploadPolicy.displayDebug("getBufferedImage: quarter: " + this.quarterRotation, 50); |
340 | |
|
341 | |
|
342 | |
|
343 | 3 | switch (this.quarterRotation) { |
344 | |
case 1: |
345 | 3 | translationX = 0; |
346 | 3 | translationY = -this.scaledRotatedWidth; |
347 | 3 | break; |
348 | |
case 2: |
349 | 0 | translationX = -this.scaledRotatedWidth; |
350 | 0 | translationY = -this.scaledRotatedHeight; |
351 | 0 | break; |
352 | |
case 3: |
353 | 0 | translationX = -this.scaledRotatedHeight; |
354 | 0 | translationY = 0; |
355 | 0 | break; |
356 | |
default: |
357 | 0 | this.uploadPolicy.displayWarn("Invalid quarterRotation : " + this.quarterRotation); |
358 | 0 | this.quarterRotation = 0; |
359 | 0 | theta = 0; |
360 | |
} |
361 | 3 | transform.rotate(theta); |
362 | 3 | transform.translate(translationX, translationY); |
363 | |
} |
364 | |
|
365 | |
|
366 | 7 | if (this.scale < 1) { |
367 | 4 | if (highquality) { |
368 | 2 | this.uploadPolicy |
369 | 2 | .displayDebug("getBufferedImage: Resizing picture(using high quality picture)", 30); |
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | 2 | Image img = sourceBufferedImage.getScaledInstance(this.scaledNonRotatedWidth, |
375 | |
this.scaledNonRotatedHeight, Image.SCALE_AREA_AVERAGING); |
376 | |
|
377 | |
|
378 | 2 | int localImageType = sourceBufferedImage.getType(); |
379 | 2 | if (localImageType == BufferedImage.TYPE_CUSTOM) { |
380 | 0 | localImageType = BufferedImage.TYPE_INT_BGR; |
381 | |
} |
382 | |
|
383 | 2 | BufferedImage tempBufferedImage = new BufferedImage(this.scaledNonRotatedWidth, |
384 | |
this.scaledNonRotatedHeight, localImageType); |
385 | |
|
386 | |
|
387 | |
|
388 | 2 | this.nbPixelsTotal = this.scaledNonRotatedWidth * this.scaledNonRotatedHeight; |
389 | 2 | this.nbPixelsRead = 0; |
390 | |
|
391 | |
|
392 | 2 | this.uploadPolicy.displayDebug("getBufferedImage: Before drawImage", 50); |
393 | 2 | tempBufferedImage.getGraphics().drawImage(img, 0, 0, this); |
394 | 2 | this.uploadPolicy.displayDebug("getBufferedImage: After drawImage", 50); |
395 | |
|
396 | 2 | tempBufferedImage.flush(); |
397 | |
|
398 | 2 | img.flush(); |
399 | 2 | img = null; |
400 | 2 | PictureFileData.freeMemory("ImageHelper.getBufferedImage()", this.uploadPolicy); |
401 | |
|
402 | |
|
403 | |
|
404 | 2 | sourceBufferedImage = tempBufferedImage; |
405 | 2 | tempBufferedImage = null; |
406 | 2 | } else { |
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | 2 | this.uploadPolicy.displayDebug( |
412 | |
"getBufferedImage: Resizing picture(using standard quality picture)", 50); |
413 | 2 | transform.scale(this.scale, this.scale); |
414 | |
} |
415 | |
} |
416 | |
|
417 | 7 | if (transform.isIdentity()) { |
418 | 2 | returnedBufferedImage = sourceBufferedImage; |
419 | |
} else { |
420 | 5 | AffineTransformOp affineTransformOp = null; |
421 | |
|
422 | 5 | affineTransformOp = new AffineTransformOp(transform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); |
423 | 5 | returnedBufferedImage = affineTransformOp.createCompatibleDestImage(sourceBufferedImage, null); |
424 | |
|
425 | |
|
426 | |
|
427 | 10 | this.uploadPolicy.displayDebug("getBufferedImage: returnedBufferedImage.getColorModel(): " |
428 | 5 | + sourceBufferedImage.getColorModel().toString(), 50); |
429 | 10 | this.uploadPolicy.displayDebug("getBufferedImage: returnedBufferedImage.getColorModel(): " |
430 | 5 | + sourceBufferedImage.getColorModel().toString(), 50); |
431 | 5 | affineTransformOp.filter(sourceBufferedImage, returnedBufferedImage); |
432 | 5 | affineTransformOp = null; |
433 | |
|
434 | 5 | returnedBufferedImage.flush(); |
435 | |
} |
436 | 0 | } catch (Exception e) { |
437 | 0 | throw new JUploadException(e.getClass().getName() + " (" + this.getClass().getName() |
438 | 0 | + ".getBufferedImage()) : " + e.getMessage()); |
439 | 7 | } |
440 | |
|
441 | 7 | if (returnedBufferedImage != null && this.uploadPolicy.getDebugLevel() >= 50) { |
442 | 7 | this.uploadPolicy.displayDebug("getBufferedImage: " + returnedBufferedImage, 50); |
443 | 7 | this.uploadPolicy.displayDebug("getBufferedImage: MinX=" + returnedBufferedImage.getMinX(), 50); |
444 | 7 | this.uploadPolicy.displayDebug("getBufferedImage: MinY=" + returnedBufferedImage.getMinY(), 50); |
445 | |
} |
446 | |
|
447 | 7 | this.uploadPolicy.displayDebug("getBufferedImage: was " + (System.currentTimeMillis() - msGetBufferedImage) |
448 | |
+ " ms long", 50); |
449 | 7 | PictureFileData.freeMemory("ImageHelper.getBufferedImage()", this.uploadPolicy); |
450 | 7 | return returnedBufferedImage; |
451 | |
} |
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
BufferedImage getBufferedImage2(boolean highquality, BufferedImage sourceBufferedImage) throws JUploadException { |
462 | 0 | long msGetBufferedImage = System.currentTimeMillis(); |
463 | 0 | BufferedImage dest = null; |
464 | |
|
465 | |
|
466 | 0 | this.uploadPolicy.displayDebug("getBufferedImage: quarter: " + this.quarterRotation, 50); |
467 | |
|
468 | |
|
469 | |
@SuppressWarnings("unused") |
470 | |
int maxWidthBeforeRotation, maxHeigthBeforeRotation, widthBeforeRotation, heigthBeforeRotation, widthAfterRotation, heigthAfterRotation; |
471 | |
@SuppressWarnings("unused") |
472 | 0 | double theta = Math.toRadians(90 * this.quarterRotation); |
473 | 0 | switch (this.quarterRotation) { |
474 | |
case 0: |
475 | |
case 2: |
476 | 0 | maxWidthBeforeRotation = this.uploadPolicy.getMaxWidth(); |
477 | 0 | maxHeigthBeforeRotation = this.uploadPolicy.getMaxHeight(); |
478 | 0 | widthBeforeRotation = sourceBufferedImage.getWidth(); |
479 | 0 | heigthBeforeRotation = sourceBufferedImage.getHeight(); |
480 | 0 | widthAfterRotation = sourceBufferedImage.getWidth(); |
481 | 0 | heigthAfterRotation = sourceBufferedImage.getHeight(); |
482 | 0 | break; |
483 | |
case 1: |
484 | |
case 3: |
485 | 0 | maxWidthBeforeRotation = this.uploadPolicy.getMaxHeight(); |
486 | 0 | maxHeigthBeforeRotation = this.uploadPolicy.getMaxWidth(); |
487 | 0 | widthBeforeRotation = sourceBufferedImage.getHeight(); |
488 | 0 | heigthBeforeRotation = sourceBufferedImage.getWidth(); |
489 | 0 | widthAfterRotation = sourceBufferedImage.getHeight(); |
490 | 0 | heigthAfterRotation = sourceBufferedImage.getWidth(); |
491 | 0 | break; |
492 | |
default: |
493 | 0 | throw new JUploadException("Invalid quarter rotation: <" + this.quarterRotation + ">"); |
494 | |
} |
495 | 0 | double scaleWidthBeforeRotation = widthBeforeRotation / maxWidthBeforeRotation; |
496 | 0 | double scaleHeigthBeforeRotation = heigthBeforeRotation / maxHeigthBeforeRotation; |
497 | 0 | double scale = Math.min(scaleWidthBeforeRotation, scaleHeigthBeforeRotation); |
498 | |
|
499 | |
|
500 | |
@SuppressWarnings("unused") |
501 | 0 | Image scaledPicture = sourceBufferedImage; |
502 | 0 | if (scale < 1) { |
503 | |
int targetWidthBeforeRotation, targetHeigthBeforeRotation; |
504 | 0 | if (scaleWidthBeforeRotation < scaleHeigthBeforeRotation) { |
505 | |
|
506 | 0 | targetWidthBeforeRotation = maxWidthBeforeRotation; |
507 | 0 | targetHeigthBeforeRotation = (int) (heigthBeforeRotation * scale); |
508 | |
} else { |
509 | |
|
510 | 0 | targetHeigthBeforeRotation = maxHeigthBeforeRotation; |
511 | 0 | targetWidthBeforeRotation = (int) (widthBeforeRotation * scale); |
512 | |
} |
513 | 0 | int scale_xxx = highquality ? Image.SCALE_SMOOTH : Image.SCALE_FAST; |
514 | 0 | scaledPicture = sourceBufferedImage.getScaledInstance(targetWidthBeforeRotation, |
515 | |
targetHeigthBeforeRotation, scale_xxx); |
516 | |
} |
517 | |
|
518 | |
|
519 | 0 | if (this.quarterRotation != 0) { |
520 | |
@SuppressWarnings("unused") |
521 | |
AffineTransform rotationTransform; |
522 | 0 | switch (this.quarterRotation) { |
523 | |
case 0: |
524 | |
case 2: |
525 | 0 | maxWidthBeforeRotation = this.uploadPolicy.getMaxWidth(); |
526 | 0 | maxHeigthBeforeRotation = this.uploadPolicy.getMaxHeight(); |
527 | 0 | widthBeforeRotation = sourceBufferedImage.getWidth(); |
528 | 0 | heigthBeforeRotation = sourceBufferedImage.getHeight(); |
529 | 0 | widthAfterRotation = sourceBufferedImage.getWidth(); |
530 | 0 | heigthAfterRotation = sourceBufferedImage.getHeight(); |
531 | 0 | break; |
532 | |
case 1: |
533 | |
case 3: |
534 | 0 | maxWidthBeforeRotation = this.uploadPolicy.getMaxHeight(); |
535 | 0 | maxHeigthBeforeRotation = this.uploadPolicy.getMaxWidth(); |
536 | 0 | widthBeforeRotation = sourceBufferedImage.getHeight(); |
537 | 0 | heigthBeforeRotation = sourceBufferedImage.getWidth(); |
538 | 0 | widthAfterRotation = sourceBufferedImage.getHeight(); |
539 | 0 | heigthAfterRotation = sourceBufferedImage.getWidth(); |
540 | 0 | break; |
541 | |
default: |
542 | 0 | throw new JUploadException("Invalid quarter rotation: <" + this.quarterRotation + ">"); |
543 | |
} |
544 | |
|
545 | |
|
546 | |
|
547 | |
|
548 | |
|
549 | 0 | this.uploadPolicy.displayDebug("getBufferedImage: was " + (System.currentTimeMillis() - msGetBufferedImage) |
550 | |
+ " ms long", 50); |
551 | |
} |
552 | 0 | return dest; |
553 | |
} |
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | |
|
561 | |
|
562 | |
|
563 | |
|
564 | |
|
565 | |
|
566 | |
|
567 | |
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { |
568 | 33 | if ((infoflags & ImageObserver.WIDTH) == ImageObserver.WIDTH) { |
569 | 2 | this.progressBarBaseValue = this.uploadPolicy.getContext().getUploadPanel().getPreparationProgressBar() |
570 | 2 | .getValue(); |
571 | 2 | this.uploadPolicy.displayDebug(" imageUpdate (start of), progressBar geValue: " |
572 | |
+ this.progressBarBaseValue, 50); |
573 | 2 | int max = this.uploadPolicy.getContext().getUploadPanel().getPreparationProgressBar().getMaximum(); |
574 | 2 | this.uploadPolicy.displayDebug(" imageUpdate (start of), progressBar maximum: " + max, 50); |
575 | 2 | } else if ((infoflags & ImageObserver.SOMEBITS) == ImageObserver.SOMEBITS) { |
576 | 23 | this.nbPixelsRead += width * height; |
577 | 23 | int percentage = (int) ((long) this.nbPixelsRead * 100 / this.nbPixelsTotal); |
578 | 23 | this.uploadPolicy.getContext().getUploadPanel().getPreparationProgressBar() |
579 | 23 | .setValue(this.progressBarBaseValue + percentage); |
580 | |
|
581 | |
|
582 | |
|
583 | |
|
584 | |
|
585 | 23 | this.uploadPolicy.getContext().getUploadPanel().getPreparationProgressBar().repaint(); |
586 | 23 | } else if ((infoflags & ImageObserver.ALLBITS) == ImageObserver.ALLBITS) { |
587 | 2 | this.uploadPolicy.displayDebug(" imageUpdate, total number of pixels: " + this.nbPixelsRead + " read", 50); |
588 | |
} |
589 | |
|
590 | |
|
591 | 33 | return true; |
592 | |
} |
593 | |
} |