code: public static BufferedImage applyMask(BufferedImage image, int rgba)
      {
          final BufferedImage mask = copyImage(image);
          final int height = mask.getHeight();
          final int width = mask.getWidth();
  
          for (int y = 0; y < height; y++)
          {
              for (int x = 0; x < width; x++)
              {
                  final int col = mask.getRGB(x, y);
                  final int flag = 0x00_FF_FF_FF;
                  if (col == rgba)
                  {
                      mask.setRGB(x, y, col & flag);
                  }
              }
          }
          return mask;
      }
docs: Apply a mask to an existing image.
  
  @param image The existing image.
  @param rgba The rgba color value.
  @return The masked image.