Mercurial > projects > dwt-linux
changeset 6:640e6456a9ff
more ...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 05 Jan 2008 06:23:21 +0100 |
parents | de77855733ca |
children | c40dbdf92a95 |
files | org/eclipse/swt/graphics/ImageData.d org/eclipse/swt/graphics/ImageDataLoader.d org/eclipse/swt/graphics/ImageLoader.d org/eclipse/swt/graphics/ImageLoaderEvent.d org/eclipse/swt/graphics/ImageLoaderListener.d todo.txt |
diffstat | 6 files changed, 556 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/org/eclipse/swt/graphics/ImageData.d Sat Jan 05 05:40:52 2008 +0100 +++ b/org/eclipse/swt/graphics/ImageData.d Sat Jan 05 06:23:21 2008 +0100 @@ -13,6 +13,7 @@ import org.eclipse.swt.graphics.PaletteData; import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.ImageDataLoader; import org.eclipse.swt.SWT; import org.eclipse.swt.internal.CloneableCompatibility; @@ -27,10 +28,6 @@ this( Device, ImageData ){} void dispose(){} } -class ImageDataLoader{ - static ImageData[] load( InputStream ){ return null;} - static ImageData[] load( char[] ){ return null;} -} /** * Instances of this class are device-independent descriptions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/eclipse/swt/graphics/ImageDataLoader.d Sat Jan 05 06:23:21 2008 +0100 @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module org.eclipse.swt.graphics.ImageDataLoader; + +public import org.eclipse.swt.graphics.ImageData; + +import org.eclipse.swt.graphics.ImageLoader; +import tango.io.model.IConduit; + +/** + * Internal class that separates ImageData from ImageLoader + * to allow removal of ImageLoader from the toolkit. + */ +class ImageDataLoader { + + public static ImageData[] load(InputStream stream) { + return (new ImageLoader()).load(stream); + } + + public static ImageData[] load(char[] filename) { + return (new ImageLoader()).load(filename); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/eclipse/swt/graphics/ImageLoader.d Sat Jan 05 06:23:21 2008 +0100 @@ -0,0 +1,329 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module org.eclipse.swt.graphics.ImageLoader; + + +public import org.eclipse.swt.graphics.ImageLoaderListener; +public import org.eclipse.swt.graphics.ImageLoaderEvent; +public import org.eclipse.swt.graphics.ImageData; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.internal.Compatibility; +//import org.eclipse.swt.internal.image.*; + +import tango.core.Exception; +import tango.core.Array; +import tango.io.model.IConduit; + +class FileFormat{ + static ImageData[] load( InputStream, ImageLoader ){ return null; } + static void save( OutputStream, int, ImageLoader ){} +} + +/** + * Instances of this class are used to load images from, + * and save images to, a file or stream. + * <p> + * Currently supported image formats are: + * </p><ul> + * <li>BMP (Windows or OS/2 Bitmap)</li> + * <li>ICO (Windows Icon)</li> + * <li>JPEG</li> + * <li>GIF</li> + * <li>PNG</li> + * <li>TIFF</li> + * </ul> + * <code>ImageLoaders</code> can be used to: + * <ul> + * <li>load/save single images in all formats</li> + * <li>load/save multiple images (GIF/ICO/TIFF)</li> + * <li>load/save animated GIF images</li> + * <li>load interlaced GIF/PNG images</li> + * <li>load progressive JPEG images</li> + * </ul> + */ + +public class ImageLoader { + + /** + * the array of ImageData objects in this ImageLoader. + * This array is read in when the load method is called, + * and it is written out when the save method is called + */ + public ImageData[] data; + + /** + * the width of the logical screen on which the images + * reside, in pixels (this corresponds to the GIF89a + * Logical Screen Width value) + */ + public int logicalScreenWidth; + + /** + * the height of the logical screen on which the images + * reside, in pixels (this corresponds to the GIF89a + * Logical Screen Height value) + */ + public int logicalScreenHeight; + + /** + * the background pixel for the logical screen (this + * corresponds to the GIF89a Background Color Index value). + * The default is -1 which means 'unspecified background' + * + */ + public int backgroundPixel; + + /** + * the number of times to repeat the display of a sequence + * of animated images (this corresponds to the commonly-used + * GIF application extension for "NETSCAPE 2.0 01"). + * The default is 1. A value of 0 means 'display repeatedly' + */ + public int repeatCount; + + /* + * the set of ImageLoader event listeners, created on demand + */ + ImageLoaderListener[] imageLoaderListeners; + +/** + * Construct a new empty ImageLoader. + */ +public this() { + reset(); +} + +/** + * Resets the fields of the ImageLoader, except for the + * <code>imageLoaderListeners</code> field. + */ +void reset() { + data = null; + logicalScreenWidth = 0; + logicalScreenHeight = 0; + backgroundPixel = -1; + repeatCount = 1; +} + +/** + * Loads an array of <code>ImageData</code> objects from the + * specified input stream. Throws an error if either an error + * occurs while loading the images, or if the images are not + * of a supported type. Returns the loaded image data array. + * + * @param stream the input stream to load the images from + * @return an array of <code>ImageData</code> objects loaded from the specified input stream + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_IO - if an IO error occurs while reading from the stream</li> + * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data</li> + * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li> + * </ul> + */ +public ImageData[] load(InputStream stream) { + if (stream is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + reset(); + data = FileFormat.load(stream, this); + return data; +} + +/** + * Loads an array of <code>ImageData</code> objects from the + * file with the specified name. Throws an error if either + * an error occurs while loading the images, or if the images are + * not of a supported type. Returns the loaded image data array. + * + * @param filename the name of the file to load the images from + * @return an array of <code>ImageData</code> objects loaded from the specified file + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the file name is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_IO - if an IO error occurs while reading from the file</li> + * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data</li> + * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li> + * </ul> + */ +public ImageData[] load(char[] filename) { + if (filename is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + InputStream stream = null; + void close(){ + try { + if( stream !is null ) stream.close(); + } catch (IOException e) { + // Ignore error + } + } + try { + stream = Compatibility.newFileInputStream(filename); + scope(exit) close(); + + return load(stream); + } catch (IOException e) { + SWT.error(SWT.ERROR_IO, e); + } + return null; +} + +/** + * Saves the image data in this ImageLoader to the specified stream. + * The format parameter can have one of the following values: + * <dl> + * <dt><code>IMAGE_BMP</code></dt> + * <dd>Windows BMP file format, no compression</dd> + * <dt><code>IMAGE_BMP_RLE</code></dt> + * <dd>Windows BMP file format, RLE compression if appropriate</dd> + * <dt><code>IMAGE_GIF</code></dt> + * <dd>GIF file format</dd> + * <dt><code>IMAGE_ICO</code></dt> + * <dd>Windows ICO file format</dd> + * <dt><code>IMAGE_JPEG</code></dt> + * <dd>JPEG file format</dd> + * <dt><code>IMAGE_PNG</code></dt> + * <dd>PNG file format</dd> + * </dl> + * + * @param stream the output stream to write the images to + * @param format the format to write the images in + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_IO - if an IO error occurs while writing to the stream</li> + * <li>ERROR_INVALID_IMAGE - if the image data contains invalid data</li> + * <li>ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format</li> + * </ul> + */ +public void save(OutputStream stream, int format) { + if (stream is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + FileFormat.save(stream, format, this); +} + +/** + * Saves the image data in this ImageLoader to a file with the specified name. + * The format parameter can have one of the following values: + * <dl> + * <dt><code>IMAGE_BMP</code></dt> + * <dd>Windows BMP file format, no compression</dd> + * <dt><code>IMAGE_BMP_RLE</code></dt> + * <dd>Windows BMP file format, RLE compression if appropriate</dd> + * <dt><code>IMAGE_GIF</code></dt> + * <dd>GIF file format</dd> + * <dt><code>IMAGE_ICO</code></dt> + * <dd>Windows ICO file format</dd> + * <dt><code>IMAGE_JPEG</code></dt> + * <dd>JPEG file format</dd> + * <dt><code>IMAGE_PNG</code></dt> + * <dd>PNG file format</dd> + * </dl> + * + * @param filename the name of the file to write the images to + * @param format the format to write the images in + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the file name is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_IO - if an IO error occurs while writing to the file</li> + * <li>ERROR_INVALID_IMAGE - if the image data contains invalid data</li> + * <li>ERROR_UNSUPPORTED_FORMAT - if the image data cannot be saved to the requested format</li> + * </ul> + */ +public void save(char[] filename, int format) { + if (filename is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + OutputStream stream = null; + try { + stream = Compatibility.newFileOutputStream(filename); + } catch (IOException e) { + SWT.error(SWT.ERROR_IO, e); + } + save(stream, format); + try { + stream.close(); + } catch (IOException e) { + } +} + +/** + * Adds the listener to the collection of listeners who will be + * notified when image data is either partially or completely loaded. + * <p> + * An ImageLoaderListener should be added before invoking + * one of the receiver's load methods. The listener's + * <code>imageDataLoaded</code> method is called when image + * data has been partially loaded, as is supported by interlaced + * GIF/PNG or progressive JPEG images. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * + * @see ImageLoaderListener + * @see ImageLoaderEvent + */ +public void addImageLoaderListener(ImageLoaderListener listener) { + if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + imageLoaderListeners ~= listener; +} + +/** + * Removes the listener from the collection of listeners who will be + * notified when image data is either partially or completely loaded. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * + * @see #addImageLoaderListener(ImageLoaderListener) + */ +public void removeImageLoaderListener(ImageLoaderListener listener) { + if (listener is null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if (imageLoaderListeners.length == 0 ) return; + tango.core.Array.remove( imageLoaderListeners, listener, delegate bool(ImageLoaderListener l1, ImageLoaderListener l2 ){ return l1 is l2; }); +} + +/** + * Returns <code>true</code> if the receiver has image loader + * listeners, and <code>false</code> otherwise. + * + * @return <code>true</code> if there are <code>ImageLoaderListener</code>s, and <code>false</code> otherwise + * + * @see #addImageLoaderListener(ImageLoaderListener) + * @see #removeImageLoaderListener(ImageLoaderListener) + */ +public bool hasListeners() { + return imageLoaderListeners.length > 0; +} + +/** + * Notifies all image loader listeners that an image loader event + * has occurred. Pass the specified event object to each listener. + * + * @param event the <code>ImageLoaderEvent</code> to send to each <code>ImageLoaderListener</code> + */ +public void notifyListeners(ImageLoaderEvent event) { + if (!hasListeners()) return; + foreach( listener; imageLoaderListeners ){ + listener.imageDataLoaded(event); + } +} + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/eclipse/swt/graphics/ImageLoaderEvent.d Sat Jan 05 06:23:21 2008 +0100 @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module org.eclipse.swt.graphics.ImageLoaderEvent; + + +public import org.eclipse.swt.internal.SWTEventObject; +public import org.eclipse.swt.graphics.ImageLoader; +public import org.eclipse.swt.graphics.ImageData; + +import tango.text.convert.Format; + +/** + * Instances of this class are sent as a result of the incremental + * loading of image data. + * <p> + * <b>Notes:</b> + * </p><ul> + * <li>The number of events which will be sent when loading images + * is not constant. It varies by image type, and for JPEG images it + * varies from image to image.</li> + * <li>For image sources which contain multiple images, the + * <code>endOfImage</code> flag in the event will be set to true + * after each individual image is loaded.</li> + * </ul> + * + * @see ImageLoader + * @see ImageLoaderListener + */ + +public class ImageLoaderEvent : SWTEventObject { + + /** + * if the <code>endOfImage</code> flag is false, then this is a + * partially complete copy of the current <code>ImageData</code>, + * otherwise this is a completely loaded <code>ImageData</code> + */ + public ImageData imageData; + + /** + * the zero-based count of image data increments -- this is + * equivalent to the number of events that have been generated + * while loading a particular image + */ + public int incrementCount; + + /** + * If this flag is true, then the current image data has been + * completely loaded, otherwise the image data is only partially + * loaded, and further ImageLoader events will occur unless an + * exception is thrown + */ + public bool endOfImage; + + //static final long serialVersionUID = 3257284738325558065L; + +/** + * Constructs a new instance of this class given the event source and + * the values to store in its fields. + * + * @param source the ImageLoader that was loading when the event occurred + * @param imageData the image data for the event + * @param incrementCount the image data increment for the event + * @param endOfImage the end of image flag for the event + */ +public this(ImageLoader source, ImageData imageData, int incrementCount, bool endOfImage) { + super(source); + this.imageData = imageData; + this.incrementCount = incrementCount; + this.endOfImage = endOfImage; +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the event + */ +public char[] toString () { + return Format( "ImageLoaderEvent {source={} imageData={} incrementCount={} endOfImage={}}", source, imageData, incrementCount, endOfImage); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ +} + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org/eclipse/swt/graphics/ImageLoaderListener.d Sat Jan 05 06:23:21 2008 +0100 @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module org.eclipse.swt.graphics.ImageLoaderListener; + + +public import org.eclipse.swt.graphics.ImageLoaderEvent; +public import org.eclipse.swt.internal.SWTEventListener; + +/** + * Classes which implement this interface provide methods + * that deal with the incremental loading of image data. + * <p> + * After creating an instance of a class that implements + * this interface it can be added to an image loader using the + * <code>addImageLoaderListener</code> method and removed using + * the <code>removeImageLoaderListener</code> method. When + * image data is either partially or completely loaded, this + * method will be invoked. + * </p> + * + * @see ImageLoader + * @see ImageLoaderEvent + */ + +public interface ImageLoaderListener : SWTEventListener { + +/** + * Sent when image data is either partially or completely loaded. + * <p> + * The timing of when this method is called varies depending on + * the format of the image being loaded. + * </p> + * + * @param e an event containing information about the image loading operation + */ +public void imageDataLoaded(ImageLoaderEvent e); + +}
--- a/todo.txt Sat Jan 05 05:40:52 2008 +0100 +++ b/todo.txt Sat Jan 05 06:23:21 2008 +0100 @@ -1,7 +1,24 @@ +next target is internal/images/FileFormat + dep: LEDataOutputStream + dep: LEDataInputStream SWT // left: getMessage -> Compatibility:ResourceBundle SWTError // OK SWTException // OK +internal/BidiUtil // OK (stub: GC, Runnable ) +internal/Callback // ?? hopefully not needed +internal/CloneableCompatibility // OK (java.lang.Cloneable) +internal/C // OK not needed +internal/Compatibility // left: ResourceBundle, interrupt() +internal/Converter // left: gtk function prototypes +internal/Library // OK (loading of lib not needed) +internal/Lock // OK +internal/LONG // OK +internal/Platform // OK +internal/SerializableCompatibility // OK (java.io.Serializable) +internal/SWTEventListener // OK (java.util.EventListener) +internal/SWTEventObject // OK (java.util.EventObject) + graphics/Color graphics/Cursor graphics/Device @@ -14,13 +31,13 @@ graphics/GCData graphics/GlyphMetrics graphics/Image -graphics/ImageData -graphics/ImageDataLoader -graphics/ImageLoader -graphics/ImageLoaderEvent -graphics/ImageLoaderListener +graphics/ImageData // OK (GC, Device, Image) +graphics/ImageDataLoader // OK +graphics/ImageLoader // OK (FileFormat) +graphics/ImageLoaderEvent // OK +graphics/ImageLoaderListener // OK graphics/LineAttributes // OK -graphics/PaletteData +graphics/PaletteData // OK graphics/Path graphics/PathData // OK graphics/Pattern @@ -105,20 +122,6 @@ -internal/BidiUtil // OK (stub: GC, Runnable ) -internal/Callback // ?? hopefully not needed -internal/CloneableCompatibility // OK (java.lang.Cloneable) -internal/C // OK not needed -internal/Compatibility // left: ResourceBundle, interrupt() -internal/Converter // left: gtk function prototypes -internal/Library // OK (loading of lib not needed) -internal/Lock // OK -internal/LONG // OK -internal/Platform // OK -internal/SerializableCompatibility // OK (java.io.Serializable) -internal/SWTEventListener // OK (java.util.EventListener) -internal/SWTEventObject // OK (java.util.EventObject) - internal/gnome/GnomeVFSMimeApplication internal/gnome/GNOME internal/cde/CDE @@ -142,50 +145,50 @@ internal/cairo/Cairo internal/cairo/cairo_text_extents_t internal/cairo/cairo_font_extents_t -internal/image/WinBMPFileFormat -internal/image/TIFFFileFormat +internal/image/FileFormat +internal/image/GIFFileFormat +internal/image/JPEGAppn +internal/image/JPEGArithmeticConditioningTable internal/image/JPEGComment -internal/image/PngPlteChunk +internal/image/JPEGDecoder +internal/image/JPEGEndOfImage +internal/image/JPEGFileFormat +internal/image/JPEGFixedSizeSegment +internal/image/JPEGFrameHeader +internal/image/JPEGHuffmanTable +internal/image/JPEGQuantizationTable +internal/image/JPEGRestartInterval internal/image/JPEGScanHeader +internal/image/JPEGSegment +internal/image/JPEGStartOfImage +internal/image/JPEGVariableSizeSegment +internal/image/LEDataInputStream +internal/image/LEDataOutputStream +internal/image/LZWCodec +internal/image/LZWNode internal/image/OS2BMPFileFormat -internal/image/PngIhdrChunk -internal/image/JPEGEndOfImage -internal/image/LEDataOutputStream -internal/image/PngHuffmanTables +internal/image/PngChunk +internal/image/PngChunkReader +internal/image/PngDecodingDataStream internal/image/PngDeflater +internal/image/PngEncoder +internal/image/PNGFileFormat +internal/image/PngFileReadState +internal/image/PngHuffmanTable +internal/image/PngHuffmanTables internal/image/PngIdatChunk -internal/image/JPEGDecoder -internal/image/JPEGRestartInterval -internal/image/LZWNode -internal/image/JPEGVariableSizeSegment -internal/image/TIFFRandomFileAccess -internal/image/PNGFileFormat -internal/image/JPEGSegment -internal/image/PngLzBlockReader -internal/image/FileFormat +internal/image/PngIendChunk +internal/image/PngIhdrChunk internal/image/PngInputStream -internal/image/PngChunkReader +internal/image/PngLzBlockReader +internal/image/PngPlteChunk +internal/image/PngTrnsChunk internal/image/TIFFDirectory -internal/image/PngEncoder -internal/image/PngIendChunk -internal/image/JPEGFileFormat -internal/image/PngDecodingDataStream -internal/image/PngChunk -internal/image/JPEGStartOfImage -internal/image/JPEGHuffmanTable -internal/image/JPEGAppn -internal/image/JPEGQuantizationTable +internal/image/TIFFFileFormat internal/image/TIFFModifiedHuffmanCodec -internal/image/LEDataInputStream -internal/image/GIFFileFormat -internal/image/LZWCodec -internal/image/PngTrnsChunk -internal/image/PngHuffmanTable +internal/image/TIFFRandomFileAccess +internal/image/WinBMPFileFormat internal/image/WinICOFileFormat -internal/image/JPEGArithmeticConditioningTable -internal/image/JPEGFixedSizeSegment -internal/image/PngFileReadState -internal/image/JPEGFrameHeader internal/gtk/GdkEventCrossing internal/gtk/XAnyEvent internal/gtk/OS