329 * </ul> |
329 * </ul> |
330 */ |
330 */ |
331 public Image(Device device, String filename) { |
331 public Image(Device device, String filename) { |
332 this(device, filename, true); |
332 this(device, filename, true); |
333 } |
333 } |
334 |
334 |
335 private Image(Device device, String filename, boolean securityCheck) { |
335 private Image(Device device, String filename, boolean securityCheck) { |
336 this(device); |
336 this(device); |
337 if (filename == null) { |
337 if (filename == null) { |
338 SWT.error(SWT.ERROR_NULL_ARGUMENT); |
338 SWT.error(SWT.ERROR_NULL_ARGUMENT); |
339 } |
339 } |
340 init(); |
340 init(); |
341 |
341 |
342 if (securityCheck == true) { |
342 if (securityCheck == true) { |
343 // Drop the "file:///" prefix |
343 // Drop the "file:///" prefix |
344 String trimmedFileName = filename.trim(); |
344 String trimmedFileName = filename.trim(); |
345 final String prefix = "file:///"; |
345 final String prefix = "file:///"; |
346 if (trimmedFileName.startsWith(prefix)) { |
346 if (trimmedFileName.startsWith(prefix)) { |
389 } |
389 } |
390 if (isDisposed()) { |
390 if (isDisposed()) { |
391 SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
391 SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
392 } |
392 } |
393 } |
393 } |
394 |
394 |
395 static Image createImageWithoutSecurityCheck(Device device, String filename) { |
395 static Image createImageWithoutSecurityCheck(Device device, String filename) { |
396 return new Image(device, filename, false); |
396 return new Image(device, filename, false); |
397 } |
397 } |
398 |
398 |
399 /* |
399 /* |
400 * Returns the bounds of an image without creating an Image instance. |
400 * Returns the bounds of an image without creating an Image instance. |
401 */ |
401 */ |
402 static Point getImageSize(Device device, String filename) { |
402 static Point getImageSize(Device device, String filename) { |
403 |
403 |
404 if (filename == null) { |
404 if (filename == null) { |
405 SWT.error(SWT.ERROR_NULL_ARGUMENT); |
405 SWT.error(SWT.ERROR_NULL_ARGUMENT); |
406 } |
406 } |
407 |
407 |
408 InputStream is = device.getClass().getResourceAsStream(filename); |
408 InputStream is = device.getClass().getResourceAsStream(filename); |
409 |
409 |
410 if (is == null) { |
410 if (is == null) { |
411 SWT.error(SWT.ERROR_IO); |
411 SWT.error(SWT.ERROR_IO); |
412 } |
412 } |
413 |
413 |
414 return getImageSize(is); |
414 return getImageSize(is); |
415 } |
415 } |
416 |
416 |
417 /* |
417 /* |
418 * Returns the bounds of an image without creating an Image instance. |
418 * Returns the bounds of an image without creating an Image instance. |
419 */ |
419 */ |
420 static Point getImageSize(InputStream stream) { |
420 static Point getImageSize(InputStream stream) { |
421 Point point = null; |
421 Point point = null; |
422 |
422 |
423 try { |
423 try { |
424 point = org.eclipse.swt.internal.qt.graphics.ImageLoader.getImageSize(stream); |
424 point = org.eclipse.swt.internal.qt.graphics.ImageLoader.getImageSize(stream); |
425 } catch (IOException e) { |
425 } catch (IOException e) { |
426 SWT.error(SWT.ERROR_IO); |
426 SWT.error(SWT.ERROR_IO); |
427 } catch (NullPointerException e) { |
427 } catch (NullPointerException e) { |
428 SWT.error(SWT.ERROR_NULL_ARGUMENT); |
428 SWT.error(SWT.ERROR_NULL_ARGUMENT); |
429 } catch (IllegalArgumentException e) { |
429 } catch (IllegalArgumentException e) { |
430 SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
430 SWT.error(SWT.ERROR_INVALID_ARGUMENT); |
431 } |
431 } |
432 |
432 |
433 return point; |
433 return point; |
434 } |
434 } |
435 |
435 |
436 /** |
436 /** |
437 * Disposes of the operating system resources associated with the image. |
437 * Disposes of the operating system resources associated with the image. |
562 init(); |
562 init(); |
563 |
563 |
564 int width = image.width; |
564 int width = image.width; |
565 int height = image.height; |
565 int height = image.height; |
566 PaletteData palette = image.palette; |
566 PaletteData palette = image.palette; |
567 if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) || |
|
568 ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect))) |
|
569 SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH); |
|
570 byte[] buffer = image.data; |
567 byte[] buffer = image.data; |
571 if (image.depth != 32 || image.bytesPerLine != width*4) { |
568 if (image.depth != 32 || image.bytesPerLine != width*4) { |
572 buffer = new byte[width * 4 * height]; |
569 buffer = new byte[width * 4 * height]; |
573 if (palette.isDirect) { |
570 if (palette.isDirect) { |
574 ImageData.blit(ImageData.BLIT_SRC, |
571 ImageData.blit(ImageData.BLIT_SRC, |
695 */ |
692 */ |
696 int getIconHandle() { |
693 int getIconHandle() { |
697 if(isDisposed()) { |
694 if(isDisposed()) { |
698 SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
695 SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); |
699 } |
696 } |
700 if(icon == SWT.NULL) { |
697 // Delete any previous icons if there is one |
701 icon = OS.QIcon_new(cgImage.getNativePixmapHandle()); |
698 // QIcon instances are deleted on Image |
702 } |
699 if( icon != SWT.NULL ){ |
|
700 OS.QIcon_delete(icon); |
|
701 } |
|
702 |
|
703 icon = OS.QIcon_new(cgImage.getNativePixmapHandle()); |
703 return icon; |
704 return icon; |
704 } |
705 } |
705 |
706 |
706 /* |
707 /* |
707 * Returns OS specific image instance. |
708 * Returns OS specific image instance. |
826 if( Device.nullIconHandle == 0 ){ |
827 if( Device.nullIconHandle == 0 ){ |
827 Device.nullIconHandle = OS.QIcon_new(); |
828 Device.nullIconHandle = OS.QIcon_new(); |
828 } |
829 } |
829 return Device.nullIconHandle; |
830 return Device.nullIconHandle; |
830 } |
831 } |
831 |
832 |
832 /** |
833 /** |
833 * Creates new Image instance. |
834 * Creates new Image instance. |
834 * <p> |
835 * <p> |
835 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public |
836 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public |
836 * API for <code>Image</code>. It is marked public only so that it |
837 * API for <code>Image</code>. It is marked public only so that it |