Esempio n. 1
0
  /** Generate a tiled image that contains a view of the mask. */
  @SuppressWarnings("restriction")
  public TiledImage getMaskImage() {
    TiledImage ti =
        new TiledImage(
            0,
            0,
            mwidth,
            mheight,
            0,
            0,
            new PixelInterleavedSampleModel(
                DataBuffer.TYPE_BYTE, mwidth, mheight, 1, mwidth, Transform.bandstride),
            new ComponentColorModel(
                ColorSpace.getInstance(ColorSpace.CS_GRAY),
                false,
                false,
                ComponentColorModel.OPAQUE,
                DataBuffer.TYPE_BYTE));

    WritableRaster gradRaster = ti.getWritableTile(0, 0);
    DataBufferByte gradDB = (DataBufferByte) gradRaster.getDataBuffer();
    byte[] gradImageData = gradDB.getData();

    int maskwh = mwidth * mheight;
    for (int i = 0; i < maskwh; i++) gradImageData[i] = (byte) mask[i];

    return ti;
  }
  /** Decodes an image */
  public PlanarImage decodeJAI() throws IOException {

    // ------------------------------------------- construimos la imagen
    int tileWidth = width, tileHeight = height;

    int[] order = new int[bands];
    for (int i = 0; i < bands; i++) order[i] = i;
    ComponentSampleModel csm =
        new ComponentSampleModel(
            DataBuffer.TYPE_SHORT, tileWidth, tileHeight, tileWidth * bands, bands, order);

    for (int i = 0; i < bands; i++) order[i] = 16;
    ColorSpace cs;
    switch (bands) {
      case 1:
        cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
        break;
      case 3:
        cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
        break;
      default:
        // F = 15 component
        cs = ColorSpace.getInstance(ColorSpace.TYPE_FCLR);
    }
    ComponentColorModel ccm =
        new ComponentColorModel(
            cs, order, false, false, Transparency.OPAQUE, DataBuffer.TYPE_SHORT);

    outImage = new TiledImage(0, 0, width, height, 0, 0, csm, ccm);

    // --------------------------------------------------- decodificamos

    decode(); // ya redefinimos aqui el setValue, asi que todo el proceso es igual

    return outImage;
  }