| 1360 | /// @return Translucent/Opaque image based on the alpha value and the pixels of |
| 1361 | /// this image |
| 1362 | public Image modifyAlpha(byte alpha) { |
| 1363 | int w = getWidth(); |
| 1364 | int h = getHeight(); |
| 1365 | int size = w * h; |
| 1366 | int[] arr = getRGB(); |
| 1367 | if (isSimdOptimizationsEnabled() && size >= 16) { |
| 1368 | int alphaInt = (((int) alpha) << 24) & 0xff000000; |
| 1369 | replaceAlphaPreserveTransparentSimd(arr, 0, alphaInt, size); |
| 1370 | } else { |
| 1371 | int alphaInt = (((int) alpha) << 24) & 0xff000000; |
| 1372 | for (int iter = 0; iter < size; iter++) { |
| 1373 | int currentAlpha = (arr[iter] >> 24) & 0xff; |
| 1374 | if (currentAlpha != 0) { |
| 1375 | arr[iter] = (arr[iter] & 0xffffff) | alphaInt; |
| 1376 | } |
| 1377 | } |
| 1378 | } |
| 1379 | Image i = createImageWithRgbCache(arr, w, h); |
| 1380 | i.opaqueTested = true; |
| 1381 | i.opaque = false; |
| 1382 | return i; |
| 1383 | } |
| 1384 | |
| 1385 | /// Creates a new image instance with the alpha channel of opaque |
| 1386 | /// pixels within the image using the new alpha value. Transparent (alpha == 0) |