Package ca.eandb.jmist.framework.loader.openexr.attribute

Examples of ca.eandb.jmist.framework.loader.openexr.attribute.ChannelList


  public OpenEXRImage(Box2i dataWindow) {
    this(dataWindow, dataWindow);
  }

  public OpenEXRImage(Box2i dataWindow, Box2i displayWindow) {
    attributes.put("channels", new ChannelList());
    attributes.put("compression", CompressionMethod.NONE);
    attributes.put("dataWindow", dataWindow);
    attributes.put("displayWindow", displayWindow);
    attributes.put("lineOrder", LineOrder.INCREASING_Y);
    attributes.put("pixelAspectRatio", new FloatAttribute(1.0f));
View Full Code Here


      int h = dw.getYSize();
      int ymin = dw.getYMin();
      int ymax = dw.getYMax();
      int blockHeight = cm.getScanLinesPerBlock();
      int numBlocks = 1 + (h - 1) / blockHeight;
      ChannelList chlist = getChannelList();

      source.seek(source.getFlushedPosition() + 8 * numBlocks);

      for (int i = 0; i < numBlocks; i++) {
        source.flush();

        int x0 = dw.getXMin();
        int x1 = dw.getXMax();
        int y0 = source.readInt();
        int y1 = Math.min(y0 + blockHeight - 1, ymax);
        Box2i block = new Box2i(x0, y0, x1, y1);
        int size = source.readInt();
        int blockSize = computeTileSize(block);

        IIOByteBuffer buf = new IIOByteBuffer(null, 0, 0);
        source.readBytes(buf, size);
        if (size < blockSize) {
          cm.decompress(buf, block);
          if (buf.getLength() < blockSize) {
            throw new RuntimeException("Undersized block");
          }
        }
        f.write(buf.getData(), buf.getOffset(), buf.getLength());

        ByteBuffer inBuf = ByteBuffer.wrap(buf.getData(), buf.getOffset(), buf.getLength())
            .order(ByteOrder.LITTLE_ENDIAN);

        for (int y = y0; y <= y1; y++) {
          for (Channel channel : chlist.channels()) {
            String name = channel.getName();
            int sx = channel.getxSampling();
            int sy = channel.getySampling();

            if ((y % sy) == 0) {
View Full Code Here

  }

  private synchronized Buffer getChannelBufferSync(String name) {
    Buffer buf = data.get(name);
    if (buf == null) {
      ChannelList chlist = getChannelList();
      Channel channel = chlist.getChannel(name);
      Box2i dataWindow = getDataWindow();
      int w = dataWindow.getXSize();
      int h = dataWindow.getYSize();
      int sx = 1 + (w - 1) / channel.getxSampling();
      int sy = 1 + (h - 1) / channel.getySampling();
View Full Code Here

    }
    return buf;
  }

  private int computeTileSize(Box2i tile) {
    ChannelList chlist = getChannelList();
    int x0 = tile.getXMin();
    int y0 = tile.getYMin();
    int x1 = tile.getXMax();
    int y1 = tile.getYMax();

    int size = 0;
    for (Channel channel : chlist.channels()) {
      PixelType type = channel.getPixelType();
      int sx = channel.getxSampling();
      int sy = channel.getySampling();
      int nx = 1 + (x1 - x0 - (x1 % sx)) / sx;
      int ny = 1 + (y1 - y0 - (y1 % sy)) / sy;
View Full Code Here

    }
    return size;
  }

  private int computeMaximumTileSize(V2i tileSize) {
    ChannelList chlist = getChannelList();
    int tw = tileSize.getX();
    int th = tileSize.getY();

    int size = 0;
    for (Channel channel : chlist.channels()) {
      PixelType type = channel.getPixelType();
      int sx = channel.getxSampling();
      int sy = channel.getySampling();
      int nx = 1 + (tw - 1) / sx;
      int ny = 1 + (th - 1) / sy;
View Full Code Here

    }
    return size;
  }

  public void write(ImageOutputStream out) throws IOException {
    ChannelList chlist = getChannelList();
    long start = out.getStreamPosition();

    out.setByteOrder(ByteOrder.LITTLE_ENDIAN);
    out.writeInt(MAGIC);
    out.writeInt(VERSION);

    for (Map.Entry<String, Attribute> entry : attributes.entrySet()) {
      Attribute attr = entry.getValue();
      String name = entry.getKey();
      String type = attr.getClass().getAnnotation(OpenEXRAttributeType.class).value();
      out.writeBytes(name);
      out.writeByte(0);
      out.writeBytes(type);
      out.writeByte(0);
      out.flush();
      long attrStart = out.getStreamPosition() + 4;
      out.seek(attrStart);
      attr.write(out);
      long attrEnd = out.getStreamPosition();
      out.seek(out.getFlushedPosition());
      out.writeInt((int) (attrEnd - attrStart));
      out.seek(attrEnd);
      out.flush();
    }
    out.writeByte(0);

    CompressionMethod cm = getCompressionMethod();
    Box2i dw = getDataWindow();
    int xmin = dw.getXMin();
    int ymin = dw.getYMin();
    int xmax = dw.getXMax();
    int ymax = dw.getYMax();

    int numBlocks = dw.getYSize() / cm.getScanLinesPerBlock();
    long blockPtrPos = out.getStreamPosition();
    long blockPos = blockPtrPos + 8 * numBlocks;

    int maximumBlockSize = computeMaximumTileSize(new V2i(dw.getXSize(),
        Math.min(dw.getYSize(), cm.getScanLinesPerBlock())));
    byte[] blockData = new byte[maximumBlockSize];
    IIOByteBuffer buf = new IIOByteBuffer(null, 0, 0);
    ByteBuffer bytes = ByteBuffer.wrap(blockData).order(ByteOrder.LITTLE_ENDIAN);

    int firstBlock;
    int lastBlock;
    int blockIncr;
    switch (getLineOrder()) {
    case INCREASING_Y:
    case RANDOM_Y:
      firstBlock = 0;
      lastBlock = numBlocks;
      blockIncr = 1;
      break;

    case DECREASING_Y:
      firstBlock = numBlocks - 1;
      lastBlock = -1;
      blockIncr = -1;
      break;

    default:
      throw new UnexpectedException("Invalid line order");
    }

    for (int i = firstBlock; i != lastBlock; i += blockIncr) {
      out.seek(blockPtrPos + 8 * i);
      out.writeLong(blockPos - start);
      out.seek(blockPos);
      bytes.rewind();

      // TODO write the next block here
      int x0 = dw.getXMin();
      int x1 = dw.getXMax();
      int y0 = dw.getYMin() + i * cm.getScanLinesPerBlock();
      int y1 = Math.min(y0 + cm.getScanLinesPerBlock() - 1, dw.getYMax());
      Box2i block = new Box2i(x0, y0, x1, y1);
      int blockSize = computeTileSize(block);

      for (int y = y0; y <= y1; y++) {
        for (Channel channel : chlist.channels()) {
          String name = channel.getName();
          int sx = channel.getxSampling();
          int sy = channel.getySampling();
          if (y % sy == 0) {
            int nx = 1 + (x1 - x0 - (x1 % sx)) / sx;
View Full Code Here

  @Override
  public void initialize(int w, int h, ColorModel colorModel) {
    this.colorModel = colorModel;
    image = new OpenEXRImage(w, h);

    ChannelList chlist = image.getChannelList();

    if (rawPixelType != null) {
      for (int i = 0, n = colorModel.getNumChannels(); i < n; i++) {
        String name = colorModel.getChannelName(i);
        chlist.addChannel(new Channel(name, rawPixelType));
      }
    }

    if (rgbPixelType != null) {
      chlist.addChannel(new Channel("R", rgbPixelType));
      chlist.addChannel(new Channel("G", rgbPixelType));
      chlist.addChannel(new Channel("B", rgbPixelType));
    }
  }
View Full Code Here

TOP

Related Classes of ca.eandb.jmist.framework.loader.openexr.attribute.ChannelList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.