| 256 | | if (sourceBuffer.getDataType() == DataBuffer.TYPE_INT && targetBuffer.getDataType() == DataBuffer.TYPE_INT) { |
| | 263 | if (sourceBuffer.getDataType() == DataBuffer.TYPE_BYTE && targetBuffer.getDataType() == DataBuffer.TYPE_BYTE) { |
| | 264 | byte[] sourceImageBuffer = ((DataBufferByte) sourceImage.getRaster().getDataBuffer()).getData(); |
| | 265 | byte[] targetImageBuffer = ((DataBufferByte) targetImage.getRaster().getDataBuffer()).getData(); |
| | 266 | final boolean sourceHasAlphaChannel = sourceImage.getAlphaRaster() != null; |
| | 267 | final boolean targetHasAlphaChannel = targetImage.getAlphaRaster() != null; |
| | 268 | if (sourceHasAlphaChannel && targetHasAlphaChannel) { |
| | 269 | final int pixelLength = 4; |
| | 270 | IntStream.range(visibleRect.y, visibleRect.y + visibleRect.height).parallel() |
| | 271 | .forEach(y -> IntStream.range(visibleRect.x, visibleRect.x + visibleRect.width).forEach(x -> { |
| | 272 | final Point2D.Double p = mapPoint(x, y); |
| | 273 | int tx = ((int) (p.x * (sourceImage.getWidth() - 1))); |
| | 274 | int ty = ((int) (p.y * (sourceImage.getHeight() - 1))); |
| | 275 | int sourceOffset = (ty * sourceImage.getWidth() + tx) * pixelLength; |
| | 276 | int targetOffset = (y * targetImage.getWidth() + x) * pixelLength; |
| | 277 | byte a = sourceImageBuffer[sourceOffset]; |
| | 278 | byte b = sourceImageBuffer[sourceOffset + 1]; |
| | 279 | byte g = sourceImageBuffer[sourceOffset + 2]; |
| | 280 | byte r = sourceImageBuffer[sourceOffset + 3]; |
| | 281 | targetImageBuffer[targetOffset] = a; |
| | 282 | targetImageBuffer[targetOffset + 1] = b; |
| | 283 | targetImageBuffer[targetOffset + 2] = g; |
| | 284 | targetImageBuffer[targetOffset + 3] = r; |
| | 285 | })); |
| | 286 | } else if (sourceHasAlphaChannel) { |
| | 287 | final int sourcePixelLength = 4; |
| | 288 | final int targetPixelLength = 3; |
| | 289 | IntStream.range(visibleRect.y, visibleRect.y + visibleRect.height).parallel() |
| | 290 | .forEach(y -> IntStream.range(visibleRect.x, visibleRect.x + visibleRect.width).forEach(x -> { |
| | 291 | final Point2D.Double p = mapPoint(x, y); |
| | 292 | int tx = ((int) (p.x * (sourceImage.getWidth() - 1))); |
| | 293 | int ty = ((int) (p.y * (sourceImage.getHeight() - 1))); |
| | 294 | int sourceOffset = (ty * sourceImage.getWidth() + tx) * sourcePixelLength; |
| | 295 | int targetOffset = (y * targetImage.getWidth() + x) * targetPixelLength; |
| | 296 | //byte a = sourceImageBuffer[sourceOffset]; |
| | 297 | byte b = sourceImageBuffer[sourceOffset + 1]; |
| | 298 | byte g = sourceImageBuffer[sourceOffset + 2]; |
| | 299 | byte r = sourceImageBuffer[sourceOffset + 3]; |
| | 300 | targetImageBuffer[targetOffset] = b; |
| | 301 | targetImageBuffer[targetOffset + 1] = g; |
| | 302 | targetImageBuffer[targetOffset + 2] = r; |
| | 303 | |
| | 304 | })); |
| | 305 | } else if (targetHasAlphaChannel) { |
| | 306 | final int sourcePixelLength = 3; |
| | 307 | final int targetPixelLength = 4; |
| | 308 | IntStream.range(visibleRect.y, visibleRect.y + visibleRect.height).parallel() |
| | 309 | .forEach(y -> IntStream.range(visibleRect.x, visibleRect.x + visibleRect.width).forEach(x -> { |
| | 310 | final Point2D.Double p = mapPoint(x, y); |
| | 311 | int tx = ((int) (p.x * (sourceImage.getWidth() - 1))); |
| | 312 | int ty = ((int) (p.y * (sourceImage.getHeight() - 1))); |
| | 313 | int sourceOffset = (ty * sourceImage.getWidth() + tx) * sourcePixelLength; |
| | 314 | int targetOffset = (y * targetImage.getWidth() + x) * targetPixelLength; |
| | 315 | byte a = (byte) 255; |
| | 316 | byte b = sourceImageBuffer[sourceOffset]; |
| | 317 | byte g = sourceImageBuffer[sourceOffset + 1]; |
| | 318 | byte r = sourceImageBuffer[sourceOffset + 2]; |
| | 319 | targetImageBuffer[targetOffset] = a; |
| | 320 | targetImageBuffer[targetOffset + 1] = b; |
| | 321 | targetImageBuffer[targetOffset + 2] = g; |
| | 322 | targetImageBuffer[targetOffset + 3] = r; |
| | 323 | |
| | 324 | })); |
| | 325 | } else { |
| | 326 | final int pixelLength = 3; |
| | 327 | IntStream.range(visibleRect.y, visibleRect.y + visibleRect.height).parallel() |
| | 328 | .forEach(y -> IntStream.range(visibleRect.x, visibleRect.x + visibleRect.width).forEach(x -> { |
| | 329 | final Point2D.Double p = mapPoint(x, y); |
| | 330 | int tx = ((int) (p.x * (sourceImage.getWidth() - 1))); |
| | 331 | int ty = ((int) (p.y * (sourceImage.getHeight() - 1))); |
| | 332 | int sourceOffset = (ty * sourceImage.getWidth() + tx) * pixelLength; |
| | 333 | int targetOffset = (y * targetImage.getWidth() + x) * pixelLength; |
| | 334 | byte b = sourceImageBuffer[sourceOffset]; |
| | 335 | byte g = sourceImageBuffer[sourceOffset + 1]; |
| | 336 | byte r = sourceImageBuffer[sourceOffset + 2]; |
| | 337 | targetImageBuffer[targetOffset] = b; |
| | 338 | targetImageBuffer[targetOffset + 1] = g; |
| | 339 | targetImageBuffer[targetOffset + 2] = r; |
| | 340 | })); |
| | 341 | } |
| | 342 | } else if (sourceBuffer.getDataType() == DataBuffer.TYPE_INT |
| | 343 | && targetBuffer.getDataType() == DataBuffer.TYPE_INT) { |