/// <summary> Retrieve the various boxes from the JP2 file.</summary> /// <exception cref="ColorSpaceException,">IOException /// </exception> protected internal void getBoxes() { //byte[] data; int type; long len = 0; int boxStart = 0; byte[] boxHeader = new byte[16]; int i = 0; // Search the toplevel boxes for the header box while (true) { in_Renamed.seek(boxStart); in_Renamed.readFully(boxHeader, 0, 16); // CONVERSION PROBLEM? len = (long)CSJ2K.Icc.ICCProfile.getInt(boxHeader, 0); if (len == 1) len = CSJ2K.Icc.ICCProfile.getLong(boxHeader, 8); // Extended // length type = CSJ2K.Icc.ICCProfile.getInt(boxHeader, 4); // Verify the contents of the file so far. if (i == 0 && type != CSJ2K.j2k.fileformat.FileFormatBoxes.JP2_SIGNATURE_BOX) { throw new ColorSpaceException("first box in image not " + "signature"); } else if (i == 1 && type != CSJ2K.j2k.fileformat.FileFormatBoxes.FILE_TYPE_BOX) { throw new ColorSpaceException("second box in image not file"); } else if (type == CSJ2K.j2k.fileformat.FileFormatBoxes.CONTIGUOUS_CODESTREAM_BOX) { throw new ColorSpaceException("header box not found in image"); } else if (type == CSJ2K.j2k.fileformat.FileFormatBoxes.JP2_HEADER_BOX) { break; } // Progress to the next box. ++i; boxStart = (int) (boxStart + len); } // boxStart indexes the start of the JP2_HEADER_BOX, // make headerBoxEnd index the end of the box. long headerBoxEnd = boxStart + len; if (len == 1) boxStart += 8; // Extended length header for (boxStart += 8; boxStart < headerBoxEnd; boxStart = (int) (boxStart + len)) { in_Renamed.seek(boxStart); in_Renamed.readFully(boxHeader, 0, 16); len = (long)CSJ2K.Icc.ICCProfile.getInt(boxHeader, 0); if (len == 1) throw new ColorSpaceException("Extended length boxes " + "not supported"); type = (int)CSJ2K.Icc.ICCProfile.getInt(boxHeader, 4); switch (type) { case CSJ2K.j2k.fileformat.FileFormatBoxes.IMAGE_HEADER_BOX: ihbox = new ImageHeaderBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.COLOUR_SPECIFICATION_BOX: csbox = new ColorSpecificationBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.CHANNEL_DEFINITION_BOX: cdbox = new ChannelDefinitionBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.COMPONENT_MAPPING_BOX: cmbox = new ComponentMappingBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.PALETTE_BOX: pbox = new PaletteBox(in_Renamed, boxStart); break; default: break; } } if (ihbox == null) throw new ColorSpaceException("image header box not found"); if ((pbox == null && cmbox != null) || (pbox != null && cmbox == null)) throw new ColorSpaceException("palette box and component " + "mapping box inconsistency"); }
/// <summary> Retrieve the various boxes from the JP2 file.</summary> /// <exception cref="ColorSpaceException,">IOException /// </exception> protected internal void getBoxes() { //byte[] data; int type; long len = 0; int boxStart = 0; byte[] boxHeader = new byte[16]; int i = 0; // Search the toplevel boxes for the header box while (true) { in_Renamed.seek(boxStart); in_Renamed.readFully(boxHeader, 0, 16); // CONVERSION PROBLEM? len = (long)CSJ2K.Icc.ICCProfile.getInt(boxHeader, 0); if (len == 1) { len = CSJ2K.Icc.ICCProfile.getLong(boxHeader, 8); // Extended } // length type = CSJ2K.Icc.ICCProfile.getInt(boxHeader, 4); // Verify the contents of the file so far. if (i == 0 && type != CSJ2K.j2k.fileformat.FileFormatBoxes.JP2_SIGNATURE_BOX) { throw new ColorSpaceException("first box in image not " + "signature"); } else if (i == 1 && type != CSJ2K.j2k.fileformat.FileFormatBoxes.FILE_TYPE_BOX) { throw new ColorSpaceException("second box in image not file"); } else if (type == CSJ2K.j2k.fileformat.FileFormatBoxes.CONTIGUOUS_CODESTREAM_BOX) { throw new ColorSpaceException("header box not found in image"); } else if (type == CSJ2K.j2k.fileformat.FileFormatBoxes.JP2_HEADER_BOX) { break; } // Progress to the next box. ++i; boxStart = (int)(boxStart + len); } // boxStart indexes the start of the JP2_HEADER_BOX, // make headerBoxEnd index the end of the box. long headerBoxEnd = boxStart + len; if (len == 1) { boxStart += 8; // Extended length header } for (boxStart += 8; boxStart < headerBoxEnd; boxStart = (int)(boxStart + len)) { in_Renamed.seek(boxStart); in_Renamed.readFully(boxHeader, 0, 16); len = (long)CSJ2K.Icc.ICCProfile.getInt(boxHeader, 0); if (len == 1) { throw new ColorSpaceException("Extended length boxes " + "not supported"); } type = (int)CSJ2K.Icc.ICCProfile.getInt(boxHeader, 4); switch (type) { case CSJ2K.j2k.fileformat.FileFormatBoxes.IMAGE_HEADER_BOX: ihbox = new ImageHeaderBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.COLOUR_SPECIFICATION_BOX: csbox = new ColorSpecificationBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.CHANNEL_DEFINITION_BOX: cdbox = new ChannelDefinitionBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.COMPONENT_MAPPING_BOX: cmbox = new ComponentMappingBox(in_Renamed, boxStart); break; case CSJ2K.j2k.fileformat.FileFormatBoxes.PALETTE_BOX: pbox = new PaletteBox(in_Renamed, boxStart); break; default: break; } } if (ihbox == null) { throw new ColorSpaceException("image header box not found"); } if ((pbox == null && cmbox != null) || (pbox != null && cmbox == null)) { throw new ColorSpaceException("palette box and component " + "mapping box inconsistency"); } }