public static SurfaceType getSurfaceType(ColorModel cm) {
   switch (cm.getPixelSize()) {
     case 32:
     case 24:
       if (cm instanceof DirectColorModel) {
         if (((DirectColorModel) cm).getRedMask() == 0xff0000) {
           return IntRgbGdi;
         } else {
           return SurfaceType.IntRgbx;
         }
       } else {
         return ThreeByteBgrGdi;
       }
     case 15:
       return Ushort555RgbGdi;
     case 16:
       if ((cm instanceof DirectColorModel) && (((DirectColorModel) cm).getBlueMask() == 0x3e)) {
         return SurfaceType.Ushort555Rgbx;
       } else {
         return Ushort565RgbGdi;
       }
     case 8:
       if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY
           && cm instanceof ComponentColorModel) {
         return SurfaceType.ByteGray;
       } else if (cm instanceof IndexColorModel && isOpaqueGray((IndexColorModel) cm)) {
         return SurfaceType.Index8Gray;
       } else {
         return SurfaceType.ByteIndexedOpaque;
       }
     default:
       throw new sun.java2d.InvalidPipeException(
           "Unsupported bit " + "depth: " + cm.getPixelSize());
   }
 }
 private GDIWindowSurfaceData(WComponentPeer peer, SurfaceType sType) {
   super(sType, peer.getDeviceColorModel());
   ColorModel cm = peer.getDeviceColorModel();
   this.peer = peer;
   int rMask = 0, gMask = 0, bMask = 0;
   int depth;
   switch (cm.getPixelSize()) {
     case 32:
     case 24:
       if (cm instanceof DirectColorModel) {
         depth = 32;
       } else {
         depth = 24;
       }
       break;
     default:
       depth = cm.getPixelSize();
   }
   if (cm instanceof DirectColorModel) {
     DirectColorModel dcm = (DirectColorModel) cm;
     rMask = dcm.getRedMask();
     gMask = dcm.getGreenMask();
     bMask = dcm.getBlueMask();
   }
   this.graphicsConfig = (Win32GraphicsConfig) peer.getGraphicsConfiguration();
   this.solidloops = graphicsConfig.getSolidLoops(sType);
   Win32GraphicsDevice gd = graphicsConfig.getDevice();
   scaleX = gd.getDefaultScaleX();
   scaleY = gd.getDefaultScaleY();
   initOps(peer, depth, rMask, gMask, bMask, gd.getScreen());
   setBlitProxyKey(graphicsConfig.getProxyKey());
 }
  public void testCreateGrayscale() {
    // create a 8-bit grayscale ImageTypeSpecifier
    ImageTypeSpecifier type = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, true);

    ColorModel model = type.getColorModel();
    assertEquals(
        "Failed to return the colorspace type",
        ColorSpace.TYPE_GRAY,
        model.getColorSpace().getType());
    assertEquals("Failed to return the transparency", Transparency.OPAQUE, model.getTransparency());
    assertEquals(
        "Failed to return the transfer type", DataBuffer.TYPE_BYTE, model.getTransferType());
    assertEquals("Failed to return the pixel size", 8, model.getPixelSize());

    // create a 16-bit grayscale AlphaPremultiplied ImageTypeSpecifier
    type = ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true, false);

    model = type.getColorModel();
    assertEquals(
        "Failed to return the colorspace type",
        ColorSpace.TYPE_GRAY,
        model.getColorSpace().getType());
    assertEquals(
        "Failed to return the transparency", Transparency.TRANSLUCENT, model.getTransparency());
    assertEquals(
        "Failed to return the transfer type", DataBuffer.TYPE_USHORT, model.getTransferType());
    assertEquals("Failed to return the pixel size", 32, model.getPixelSize());
  }
  public ColorModelNode(String name, ColorModel colorModel) {
    super(name, colorModel);
    addClassChild();

    ColorSpace colorSpace = colorModel.getColorSpace();
    add(new ColorSpaceNode(colorSpace));

    int numColorComponents = colorModel.getNumColorComponents();
    addIntChild("numColorComponents", numColorComponents);

    int numComponents = colorModel.getNumComponents();
    addIntChild("numComponents", numComponents);

    boolean hasAlpha = colorModel.hasAlpha();
    addBooleanChild("hasAlpha", hasAlpha);

    int pixelSize = colorModel.getPixelSize();
    addIntChild("pixelSize", pixelSize);

    int transferType = colorModel.getTransferType();
    String transferTypeDescription = getTransferTypeDescription(transferType);
    addStringChild("transferType", transferTypeDescription);

    int transparency = colorModel.getTransparency();
    addStringChild("transparency", getTransparencyDescription(transparency));

    boolean isRGB = isRgbColorModel(colorModel);
    addBooleanChild("isRGB", isRGB);

    boolean isBGR = isBgrColorModel(colorModel);
    addBooleanChild("isBGR", isBGR);
  }
  public static void main(String args[]) {
    ColorModel cm =
        new ColorModel(32) {
          public int getAlpha(int pixel) {
            return 255;
          }

          public int getBlue(int pixel) {
            return 255;
          }

          public int getGreen(int pixel) {
            return 255;
          }

          public int getRed(int pixel) {
            return 255;
          }
        };

    cm.hasAlpha();
    cm.isAlphaPremultiplied();
    cm.getTransferType();
    cm.getPixelSize();
    cm.getComponentSize();
    cm.getComponentSize();
    cm.getTransparency();
    cm.getNumComponents();
    cm.getNumColorComponents();
    cm.getRed(20);
    cm.getGreen(20);
    cm.getBlue(20);
    cm.getAlpha(20);
    cm.getRGB(20);
    cm.isAlphaPremultiplied();
    cm.isAlphaPremultiplied();

    cm = ColorModel.getRGBdefault();
  }
 private void makeTransparent() {
   ColorModel colorModel = bufferedImage.getColorModel();
   if (bufferedImage.getColorModel() instanceof IndexColorModel) {
     // vector image (IndexColorModel)
     IndexColorModel icm = (IndexColorModel) colorModel;
     WritableRaster raster = bufferedImage.getRaster();
     // pixel is offset in ICM's palette
     backgroundPixel = 1; // default Cadastre background sample
     int size = icm.getMapSize();
     byte[] reds = new byte[size];
     byte[] greens = new byte[size];
     byte[] blues = new byte[size];
     icm.getReds(reds);
     icm.getGreens(greens);
     icm.getBlues(blues);
     // The cadastre background has now an alpha to 0 (for invertGrey())
     cadastreBackground = 0x00ffffff;
     IndexColorModel icm2 =
         new IndexColorModel(
             colorModel.getPixelSize(), size, reds, greens, blues, backgroundPixel);
     bufferedImage = new BufferedImage(icm2, raster, bufferedImage.isAlphaPremultiplied(), null);
   }
   return;
 }
 private void updateInfo() {
   ImageDocument document = imageComponent.getDocument();
   BufferedImage image = document.getValue();
   if (image != null) {
     ColorModel colorModel = image.getColorModel();
     String format = document.getFormat();
     if (format == null) {
       format = editor != null ? ImagesBundle.message("unknown.format") : "";
     } else {
       format = format.toUpperCase(Locale.ENGLISH);
     }
     VirtualFile file = editor != null ? editor.getFile() : null;
     infoLabel.setText(
         ImagesBundle.message(
             "image.info",
             image.getWidth(),
             image.getHeight(),
             format,
             colorModel.getPixelSize(),
             file != null ? StringUtil.formatFileSize(file.getLength()) : ""));
   } else {
     infoLabel.setText(null);
   }
 }
 /**
  * Returns the current display mode of this <code>GraphicsDevice</code>. The returned display mode
  * is allowed to have a refresh rate {@link DisplayMode#REFRESH_RATE_UNKNOWN} if it is
  * indeterminate. Likewise, the returned display mode is allowed to have a bit depth {@link
  * DisplayMode#BIT_DEPTH_MULTI} if it is indeterminate or if multiple bit depths are supported.
  *
  * @return the current display mode of this graphics device.
  * @see #setDisplayMode(DisplayMode)
  * @since 1.4
  */
 public DisplayMode getDisplayMode() {
   GraphicsConfiguration gc = getDefaultConfiguration();
   Rectangle r = gc.getBounds();
   ColorModel cm = gc.getColorModel();
   return new DisplayMode(r.width, r.height, cm.getPixelSize(), 0);
 }
  public void write(BufferedImage image, AVList params) throws IOException {
    if (image == null) {
      String msg = Logging.getMessage("nullValue.ImageSource");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (0 == image.getWidth() || 0 == image.getHeight()) {
      String msg =
          Logging.getMessage("generic.InvalidImageSize", image.getWidth(), image.getHeight());
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (null == params || 0 == params.getValues().size()) {
      String reason = Logging.getMessage("nullValue.AVListIsNull");
      Logging.logger().finest(Logging.getMessage("GeotiffWriter.GeoKeysMissing", reason));
      params = new AVListImpl();
    } else {
      this.validateParameters(params, image.getWidth(), image.getHeight());
    }

    // how we proceed in part depends upon the image type...
    int type = image.getType();

    // handle CUSTOM type which comes from our GeoTiffreader (for now)
    if (BufferedImage.TYPE_CUSTOM == type) {
      int numColorComponents = 0, numComponents = 0, pixelSize = 0, dataType = 0, csType = 0;
      boolean hasAlpha = false;

      if (null != image.getColorModel()) {
        ColorModel cm = image.getColorModel();

        numColorComponents = cm.getNumColorComponents();
        numComponents = cm.getNumComponents();
        pixelSize = cm.getPixelSize();
        hasAlpha = cm.hasAlpha();

        ColorSpace cs = cm.getColorSpace();
        if (null != cs) csType = cs.getType();
      }

      if (null != image.getSampleModel()) {
        SampleModel sm = image.getSampleModel();
        dataType = sm.getDataType();
      }

      if (dataType == DataBuffer.TYPE_FLOAT && pixelSize == Float.SIZE && numComponents == 1) {
        type = BufferedImage_TYPE_ELEVATION_FLOAT32;
      } else if (dataType == DataBuffer.TYPE_SHORT
          && pixelSize == Short.SIZE
          && numComponents == 1) {
        type = BufferedImage_TYPE_ELEVATION_SHORT16;
      } else if (ColorSpace.CS_GRAY == csType && pixelSize == Byte.SIZE) {
        type = BufferedImage.TYPE_BYTE_GRAY;
      } else if (dataType == DataBuffer.TYPE_USHORT
          && ColorSpace.CS_GRAY == csType
          && pixelSize == Short.SIZE) {
        type = BufferedImage.TYPE_USHORT_GRAY;
      } else if (ColorSpace.TYPE_RGB == csType
          && pixelSize == 3 * Byte.SIZE
          && numColorComponents == 3) {
        type = BufferedImage.TYPE_3BYTE_BGR;
      } else if (ColorSpace.TYPE_RGB == csType
          && hasAlpha
          && pixelSize == 4 * Byte.SIZE
          && numComponents == 4) {
        type = BufferedImage.TYPE_4BYTE_ABGR;
      }
    }

    switch (type) {
      case BufferedImage.TYPE_3BYTE_BGR:
      case BufferedImage.TYPE_4BYTE_ABGR:
      case BufferedImage.TYPE_4BYTE_ABGR_PRE:
      case BufferedImage.TYPE_INT_RGB:
      case BufferedImage.TYPE_INT_BGR:
      case BufferedImage.TYPE_INT_ARGB:
      case BufferedImage.TYPE_INT_ARGB_PRE:
        {
          this.writeColorImage(image, params);
        }
        break;

      case BufferedImage.TYPE_USHORT_GRAY:
      case BufferedImage.TYPE_BYTE_GRAY:
        {
          this.writeGrayscaleImage(image, params);
        }
        break;

      case BufferedImage_TYPE_ELEVATION_SHORT16:
      case BufferedImage_TYPE_ELEVATION_FLOAT32:
        {
          String msg = Logging.getMessage("GeotiffWriter.FeatureNotImplementedd", type);
          Logging.logger().severe(msg);
          throw new IllegalArgumentException(msg);
        }
        //            break;

      case BufferedImage.TYPE_CUSTOM:
      default:
        {
          ColorModel cm = image.getColorModel();
          SampleModel sm = image.getSampleModel();

          StringBuffer sb =
              new StringBuffer(Logging.getMessage("GeotiffWriter.UnsupportedType", type));

          sb.append("\n");
          sb.append("NumBands=").append(sm.getNumBands()).append("\n");
          sb.append("NumDataElements=").append(sm.getNumDataElements()).append("\n");
          sb.append("NumColorComponents=").append(cm.getNumColorComponents()).append("\n");
          sb.append("NumComponents=").append(cm.getNumComponents()).append("\n");
          sb.append("PixelSize=").append(cm.getPixelSize()).append("\n");
          sb.append("hasAlpha=").append(cm.hasAlpha());

          String msg = sb.toString();
          Logging.logger().severe(msg);
          throw new IllegalArgumentException(msg);
        }
    }
  }