Spec-Zone .ru
спецификации, руководства, описания, API
001/*
002 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.  Oracle designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Oracle in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
022 * or visit www.oracle.com if you need additional information or have any
023 * questions.
024 */
025
026package javafx.scene.image;
027
028import java.nio.Buffer;
029import java.nio.ByteBuffer;
030import java.nio.IntBuffer;
031import javafx.scene.paint.Color;
032
033/**
034 * This interface defines methods for writing the pixel data of a
035 * {@link WritableImage} or other surface containing writable pixels.
036 */
037public interface PixelWriter {
038    /**
039     * This method returns the {@code PixelFormat} in which the surface
040     * stores its pixels, or a roughly equivalent pixel format from which
041     * it can easily convert pixels for purposes of writing them.
042     * 
043     * @return the {@code PixelFormat} that best describes the underlying
044     *         pixels
045     */
046    public PixelFormat getPixelFormat();
047
048    /**
049     * Stores pixel data for a color into the specified coordinates of the
050     * surface.
051     * The 32-bit integer {@code argb} parameter should contain the 4 color
052     * components in separate 8-bit fields in ARGB order from the most
053     * significant byte to the least significant byte.
054     * 
055     * @param x the X coordinate of the pixel color to write
056     * @param y the Y coordinate of the pixel color to write
057     * @param argb the color information to write, specified in the format
058     *         described by the {@link PixelFormat.Type#INT_ARGB INT_ARGB}
059     *         PixelFormat type.
060     */
061    public void setArgb(int x, int y, int argb);
062
063    /**
064     * Stores pixel data for a {@link Color} into the specified coordinates
065     * of the surface.
066     * 
067     * @param x the X coordinate of the pixel color to write
068     * @param y the Y coordinate of the pixel color to write
069     * @param c the Color to write
070     */
071    public void setColor(int x, int y, Color c);
072
073    /**
074     * Stores pixel data from a buffer into a rectangular region of the
075     * surface.
076     * The format of the pixels in the buffer is defined by the
077     * {@link PixelFormat} object and pixel format conversions will be
078     * performed as needed to store the data into the surface.
079     * The buffer is assumed to be positioned to the location where the
080     * first pixel data to be stored in the surface pixel at location
081     * {@code (x, y)} is located.
082     * Pixel data for a row will be read from adjacent locations within
083     * the buffer packed as tightly as possible for increasing X
084     * coordinates.
085     * Pixel data for adjacent rows will be read offset from each other
086     * by the number of buffer data elements defined by
087     * {@code scanlineStride}.
088     * 
089     * @param x the X coordinate of the rectangular region to write
090     * @param y the Y coordinate of the rectangular region to write
091     * @param w the width of the rectangular region to write
092     * @param h the height of the rectangular region to write
093     * @param pixelformat the {@code PixelFormat} object defining the format
094     *        to read the pixels from the buffer
095     * @param buffer a buffer of a type appropriate for the indicated
096     *        {@code PixelFormat} object
097     * @param scanlineStride the distance between the pixel data for the
098     *        start of one row of data in the buffer to the start of the
099     *        next row of data.
100     */
101    public <T extends Buffer>
102        void setPixels(int x, int y, int w, int h,
103                       PixelFormat<T> pixelformat,
104                       T buffer, int scanlineStride);
105
106    /**
107     * Stores pixel data from a byte array into a rectangular region of the
108     * surface.
109     * The format of the pixels in the buffer is defined by the
110     * {@link PixelFormat} object and pixel format conversions will be
111     * performed as needed to store the data into the surface.
112     * The {@code pixelformat} must be a compatible
113     * {@code PixelFormat<ByteBuffer>} type.
114     * The data for the first pixel at location {@code (x, y)} will be
115     * read from the array index specified by the {@code offset} parameter.
116     * Pixel data for a row will be read from adjacent locations within
117     * the array packed as tightly as possible for increasing X
118     * coordinates.
119     * Pixel data for adjacent rows will be read offset from each other
120     * by the number of byte array elements defined by
121     * {@code scanlineStride}.
122     * 
123     * @param x the X coordinate of the rectangular region to write
124     * @param y the Y coordinate of the rectangular region to write
125     * @param w the width of the rectangular region to write
126     * @param h the height of the rectangular region to write
127     * @param pixelformat the {@code PixelFormat<ByteBuffer>} object
128     *        defining the byte format to read the pixels from buffer
129     * @param buffer a byte array containing the pixel data to store
130     * @param offset the offset into {@code buffer} to read the first
131     *        pixel data
132     * @param scanlineStride the distance between the pixel data for the
133     *        start of one row of data in the buffer to the start of the
134     *        next row of data
135     */
136    public void setPixels(int x, int y, int w, int h,
137                          PixelFormat<ByteBuffer> pixelformat,
138                          byte buffer[], int offset, int scanlineStride);
139
140    /**
141     * Stores pixel data from an int array into a rectangular region of the
142     * surface.
143     * The format of the pixels in the buffer is defined by the
144     * {@link PixelFormat} object and pixel format conversions will be
145     * performed as needed to store the data into the surface.
146     * The {@code pixelformat} must be a compatible
147     * {@code PixelFormat<IntBuffer>} type.
148     * The data for the first pixel at location {@code (x, y)} will be
149     * read from the array index specified by the {@code offset} parameter.
150     * Pixel data for a row will be read from adjacent locations within
151     * the array packed as tightly as possible for increasing X
152     * coordinates.
153     * Pixel data for adjacent rows will be read offset from each other
154     * by the number of int array elements defined by
155     * {@code scanlineStride}.
156     * 
157     * @param x the X coordinate of the rectangular region to write
158     * @param y the Y coordinate of the rectangular region to write
159     * @param w the width of the rectangular region to write
160     * @param h the height of the rectangular region to write
161     * @param pixelformat the {@code PixelFormat<IntBuffer>} object
162     *        defining the int format to read the pixels from buffer
163     * @param buffer an int array to containing the pixel data to store
164     * @param offset the offset into {@code buffer} to read the first
165     *        pixel data
166     * @param scanlineStride the distance between the pixel data for the
167     *        start of one row of data in the buffer to the start of the
168     *        next row of data
169     */
170    public void setPixels(int x, int y, int w, int h,
171                          PixelFormat<IntBuffer> pixelformat,
172                          int buffer[], int offset, int scanlineStride);
173
174    /**
175     * Stores pixel data retrieved from a {@code PixelReader} instance
176     * into a rectangular region of the surface.
177     * The data for the pixel on the surface at {@code (dstx, dsty)}
178     * will be retrieved from the {@code reader} from its location
179     * {@code (srcx, srcy)}.
180     * This method performs an operation which is semantically equivalent to
181     * (though likely much faster than) this pseudo-code:
182     * <pre>
183     *     for (int y = 0; y < h, y++) {
184     *         for (int x = 0; x < w; x++) {
185     *             setArgb(dstx + x, dsty + y,
186     *                     reader.getArgb(srcx + x, srcy + y));
187     *         }
188     *     }
189     * </pre>
190     * 
191     * @param dstx the X coordinate of the rectangular region to write
192     * @param dsty the Y coordinate of the rectangular region to write
193     * @param w the width of the rectangular region to write
194     * @param h the height of the rectangular region to write
195     * @param reader the {@link PixelReader} used to get the pixel data
196     *        to write
197     * @param srcx the X coordinate of the data to read from {@code reader}
198     * @param srcy the Y coordinate of the data to read from {@code reader}
199     */
200    public void setPixels(int dstx, int dsty, int w, int h,
201                          PixelReader reader, int srcx, int srcy);
202}