| 1146 | /// |
| 1147 | /// image masked based on the given object |
| 1148 | public Image applyMask(Object mask, int x, int y) { |
| 1149 | int[] rgb = getRGB(); |
| 1150 | byte[] maskData = ((IndexedImage) mask).getImageDataByte(); |
| 1151 | int mWidth = ((IndexedImage) mask).getWidth(); |
| 1152 | int mHeight = ((IndexedImage) mask).getHeight(); |
| 1153 | int imgWidth = getWidth(); |
| 1154 | int aWidth = imgWidth - x; |
| 1155 | int aHeight = getHeight() - y; |
| 1156 | if (aWidth > mWidth) { |
| 1157 | aWidth = mWidth; |
| 1158 | } |
| 1159 | if (aHeight > mHeight) { |
| 1160 | aHeight = mHeight; |
| 1161 | } |
| 1162 | |
| 1163 | for (int xPos = 0; xPos < aWidth; xPos++) { |
| 1164 | for (int yPos = 0; yPos < aHeight; yPos++) { |
| 1165 | int aX = x + xPos; |
| 1166 | int aY = y + yPos; |
| 1167 | int imagePos = aX + aY * imgWidth; |
| 1168 | int maskAlpha = maskData[aX + aY * mWidth] & 0xff; |
| 1169 | maskAlpha = (maskAlpha << 24) & 0xff000000; |
| 1170 | rgb[imagePos] = (rgb[imagePos] & 0xffffff) | maskAlpha; |
| 1171 | |
| 1172 | } |
| 1173 | } |
| 1174 | return createImageWithRgbCache(rgb, imgWidth, getHeight()); |
| 1175 | } |
| 1176 | |
| 1177 | /// Applies the given alpha mask onto this image and returns the resulting image |
| 1178 | /// see the createMask method for indication on how to convert an image into an alpha |