| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2145,17 +2145,32 @@ public int get(int x, int y) { | |||
| 2145 | 2145 | ||
| 2146 | 2146 | ||
| 2147 | 2147 | @Override | |
| 2148 | - public PImage getImpl(int x, int y, int w, int h) { | ||
| 2149 | - PImage output = new PImage(w, h); | ||
| 2150 | - output.parent = parent; | ||
| 2151 | - | ||
| 2152 | - // oops, the last parameter is the scan size of the *target* buffer | ||
| 2148 | + // public PImage getImpl(int x, int y, int w, int h) { | ||
| 2149 | + protected void getImpl(int sourceX, int sourceY, | ||
| 2150 | + int sourceWidth, int sourceHeight, | ||
| 2151 | + PImage target, int targetX, int targetY) { | ||
| 2152 | + // last parameter to getRGB() is the scan size of the *target* buffer | ||
| 2153 | 2153 | //((BufferedImage) image).getRGB(x, y, w, h, output.pixels, 0, w); | |
| 2154 | - WritableRaster raster = ((BufferedImage) (primarySurface ? offscreen : image)).getRaster(); | ||
| 2155 | - // WritableRaster raster = image.getRaster(); | ||
| 2156 | - raster.getDataElements(x, y, w, h, output.pixels); | ||
| 2154 | + WritableRaster raster = | ||
| 2155 | + ((BufferedImage) (primarySurface ? offscreen : image)).getRaster(); | ||
| 2157 | 2156 | ||
| 2158 | - return output; | ||
| 2157 | + if (sourceWidth == target.width && sourceHeight == target.height) { | ||
| 2158 | + raster.getDataElements(sourceX, sourceY, sourceWidth, sourceHeight, target.pixels); | ||
| 2159 | + | ||
| 2160 | + } else { | ||
| 2161 | + // TODO optimize, incredibly inefficient to reallocate this much memory | ||
| 2162 | + int[] temp = new int[sourceWidth * sourceHeight]; | ||
| 2163 | + raster.getDataElements(sourceX, sourceY, sourceWidth, sourceHeight, temp); | ||
| 2164 | + | ||
| 2165 | + // Copy the temporary output pixels over to the outgoing image | ||
| 2166 | + int sourceOffset = 0; | ||
| 2167 | + int targetOffset = targetY*target.width + targetX; | ||
| 2168 | + for (int y = 0; y < sourceHeight; y++) { | ||
| 2169 | + System.arraycopy(temp, sourceOffset, target.pixels, targetOffset, sourceWidth); | ||
| 2170 | + sourceOffset += sourceWidth; | ||
| 2171 | + targetOffset += target.width; | ||
| 2172 | + } | ||
| 2173 | + } | ||
| 2159 | 2174 | } | |
| 2160 | 2175 | ||
| 2161 | 2176 | ||
@@ -2176,17 +2191,27 @@ public void set(int x, int y, int argb) { | |||
| 2176 | 2191 | } | |
| 2177 | 2192 | ||
| 2178 | 2193 | ||
| 2194 | + | ||
| 2195 | + // protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh, | ||
| 2196 | + // PImage src) { | ||
| 2179 | 2197 | @Override | |
| 2180 | - protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh, | ||
| 2181 | - PImage src) { | ||
| 2182 | - WritableRaster raster = ((BufferedImage) (primarySurface ? offscreen : image)).getRaster(); | ||
| 2183 | - // WritableRaster raster = image.getRaster(); | ||
| 2184 | - if ((sx == 0) && (sy == 0) && (sw == src.width) && (sh == src.height)) { | ||
| 2185 | - raster.setDataElements(dx, dy, src.width, src.height, src.pixels); | ||
| 2198 | + protected void setImpl(PImage sourceImage, | ||
| 2199 | + int sourceX, int sourceY, | ||
| 2200 | + int sourceWidth, int sourceHeight, | ||
| 2201 | + int targetX, int targetY) { | ||
| 2202 | + WritableRaster raster = | ||
| 2203 | + ((BufferedImage) (primarySurface ? offscreen : image)).getRaster(); | ||
| 2204 | + | ||
| 2205 | + if ((sourceX == 0) && (sourceY == 0) && | ||
| 2206 | + (sourceWidth == sourceImage.width) && | ||
| 2207 | + (sourceHeight == sourceImage.height)) { | ||
| 2208 | + raster.setDataElements(targetX, targetY, | ||
| 2209 | + sourceImage.width, sourceImage.height, | ||
| 2210 | + sourceImage.pixels); | ||
| 2186 | 2211 | } else { | |
| 2187 | - // TODO Optimize, incredibly inefficient to reallocate this much memory | ||
| 2188 | - PImage temp = src.get(sx, sy, sw, sh); | ||
| 2189 | - raster.setDataElements(dx, dy, temp.width, temp.height, temp.pixels); | ||
| 2212 | + // TODO optimize, incredibly inefficient to reallocate this much memory | ||
| 2213 | + PImage temp = sourceImage.get(sourceX, sourceY, sourceWidth, sourceHeight); | ||
| 2214 | + raster.setDataElements(targetX, targetY, temp.width, temp.height, temp.pixels); | ||
| 2190 | 2215 | } | |
| 2191 | 2216 | } | |
| 2192 | 2217 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -767,12 +767,17 @@ public int get(int x, int y) { | |||
| 767 | 767 | * @param h height of pixel rectangle to get | |
| 768 | 768 | */ | |
| 769 | 769 | public PImage get(int x, int y, int w, int h) { | |
| 770 | + int targetX = 0; | ||
| 771 | + int targetY = 0; | ||
| 772 | + | ||
| 770 | 773 | if (x < 0) { | |
| 771 | 774 | w += x; // clip off the left edge | |
| 775 | + targetX = -x; | ||
| 772 | 776 | x = 0; | |
| 773 | 777 | } | |
| 774 | 778 | if (y < 0) { | |
| 775 | 779 | h += y; // clip off some of the height | |
| 780 | + targetY = -y; | ||
| 776 | 781 | y = 0; | |
| 777 | 782 | } | |
| 778 | 783 | ||
@@ -786,7 +791,10 @@ public PImage get(int x, int y, int w, int h) { | |||
| 786 | 791 | h = 0; | |
| 787 | 792 | } | |
| 788 | 793 | ||
| 789 | - return getImpl(x, y, w, h); | ||
| 794 | + PImage target = new PImage(w, h, format); | ||
| 795 | + target.parent = parent; | ||
| 796 | + getImpl(x, y, w, h, target, targetX, targetY); | ||
| 797 | + return target; | ||
| 790 | 798 | } | |
| 791 | 799 | ||
| 792 | 800 | ||
@@ -796,18 +804,16 @@ public PImage get(int x, int y, int w, int h) { | |||
| 796 | 804 | * are guaranteed to be inside the image space, so the implementation can | |
| 797 | 805 | * use the fastest possible pixel copying method. | |
| 798 | 806 | */ | |
| 799 | - protected PImage getImpl(int x, int y, int w, int h) { | ||
| 800 | - PImage newbie = new PImage(w, h, format); | ||
| 801 | - newbie.parent = parent; | ||
| 802 | - | ||
| 803 | - int index = y*width + x; | ||
| 804 | - int index2 = 0; | ||
| 805 | - for (int row = y; row < y+h; row++) { | ||
| 806 | - System.arraycopy(pixels, index, newbie.pixels, index2, w); | ||
| 807 | - index += width; | ||
| 808 | - index2 += w; | ||
| 807 | + protected void getImpl(int sourceX, int sourceY, | ||
| 808 | + int sourceWidth, int sourceHeight, | ||
| 809 | + PImage target, int targetX, int targetY) { | ||
| 810 | + int sourceIndex = sourceY*width + sourceX; | ||
| 811 | + int targetIndex = targetY*target.width + targetX; | ||
| 812 | + for (int row = sourceY; row < sourceY+sourceHeight; row++) { | ||
| 813 | + System.arraycopy(pixels, sourceIndex, target.pixels, targetIndex, sourceWidth); | ||
| 814 | + sourceIndex += width; | ||
| 815 | + targetIndex += target.width; | ||
| 809 | 816 | } | |
| 810 | - return newbie; | ||
| 811 | 817 | } | |
| 812 | 818 | ||
| 813 | 819 | ||
@@ -897,25 +903,27 @@ public void set(int x, int y, PImage img) { | |||
| 897 | 903 | // this could be nonexistant | |
| 898 | 904 | if ((sw <= 0) || (sh <= 0)) return; | |
| 899 | 905 | ||
| 900 | - setImpl(x, y, sx, sy, sw, sh, img); | ||
| 906 | + setImpl(img, sx, sy, sw, sh, x, y); | ||
| 901 | 907 | } | |
| 902 | 908 | ||
| 903 | 909 | ||
| 904 | 910 | /** | |
| 905 | 911 | * Internal function to actually handle setting a block of pixels that | |
| 906 | 912 | * has already been properly cropped from the image to a valid region. | |
| 907 | 913 | */ | |
| 908 | - protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh, | ||
| 909 | - PImage img) { | ||
| 910 | - int srcOffset = sy * img.width + sx; | ||
| 911 | - int dstOffset = dy * width + dx; | ||
| 912 | - | ||
| 913 | - for (int y = sy; y < sy + sh; y++) { | ||
| 914 | - System.arraycopy(img.pixels, srcOffset, pixels, dstOffset, sw); | ||
| 915 | - srcOffset += img.width; | ||
| 916 | - dstOffset += width; | ||
| 914 | + protected void setImpl(PImage sourceImage, | ||
| 915 | + int sourceX, int sourceY, | ||
| 916 | + int sourceWidth, int sourceHeight, | ||
| 917 | + int targetX, int targetY) { | ||
| 918 | + int sourceOffset = sourceY * sourceImage.width + sourceX; | ||
| 919 | + int targetOffset = targetY * width + targetX; | ||
| 920 | + | ||
| 921 | + for (int y = sourceY; y < sourceY + sourceHeight; y++) { | ||
| 922 | + System.arraycopy(sourceImage.pixels, sourceOffset, pixels, targetOffset, sourceWidth); | ||
| 923 | + sourceOffset += sourceImage.width; | ||
| 924 | + targetOffset += width; | ||
| 917 | 925 | } | |
| 918 | - updatePixelsImpl(sx, sy, sw, sh); | ||
| 926 | + updatePixelsImpl(sourceX, sourceY, sourceWidth, sourceHeight); | ||
| 919 | 927 | } | |
| 920 | 928 | ||
| 921 | 929 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5239,10 +5239,13 @@ public int get(int x, int y) { | |||
| 5239 | 5239 | ||
| 5240 | 5240 | ||
| 5241 | 5241 | @Override | |
| 5242 | - protected PImage getImpl(int x, int y, int w, int h) { | ||
| 5242 | + protected void getImpl(int sourceX, int sourceY, | ||
| 5243 | + int sourceWidth, int sourceHeight, | ||
| 5244 | + PImage target, int targetX, int targetY) { | ||
| 5243 | 5245 | loadPixels(); | |
| 5244 | 5246 | setgetPixels = true; | |
| 5245 | - return super.getImpl(x, y, w, h); | ||
| 5247 | + super.getImpl(sourceX, sourceY, sourceWidth, sourceHeight, | ||
| 5248 | + target, targetX, targetY); | ||
| 5246 | 5249 | } | |
| 5247 | 5250 | ||
| 5248 | 5251 | ||
@@ -5255,11 +5258,14 @@ public void set(int x, int y, int argb) { | |||
| 5255 | 5258 | ||
| 5256 | 5259 | ||
| 5257 | 5260 | @Override | |
| 5258 | - protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh, | ||
| 5259 | - PImage src) { | ||
| 5261 | + protected void setImpl(PImage sourceImage, | ||
| 5262 | + int sourceX, int sourceY, | ||
| 5263 | + int sourceWidth, int sourceHeight, | ||
| 5264 | + int targetX, int targetY) { | ||
| 5260 | 5265 | loadPixels(); | |
| 5261 | 5266 | setgetPixels = true; | |
| 5262 | - super.setImpl(dx, dy, sx, sy, sw, sh, src); | ||
| 5267 | + super.setImpl(sourceImage, sourceX, sourceY, sourceWidth, sourceHeight, | ||
| 5268 | + targetX, targetY); | ||
| 5263 | 5269 | } | |
| 5264 | 5270 | ||
| 5265 | 5271 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments