NisoImageMetadata { public static String extractIccProfileDescription(byte[] data) throws IllegalArgumentException { ICC_Profile profile = ICC_Profile.getInstance(data); byte[] dataProf = profile.getData(ICC_Profile.icSigProfileDescriptionTag); if (dataProf == null) { return null; } String description = null; ByteBuffer bb = ByteBuffer.wrap(dataProf).asReadOnlyBuffer(); int majorVersion = profile.getMajorVersion(); int minorVersion = profile.getMinorVersion(); LOGGER.fine("Version " + majorVersion + "." + minorVersion); int beginTag = bb.getInt(0); if (beginTag == ICC_Profile.icSigProfileDescriptionTag) { final int OFFSET_LENGTH = 8; final int OFFSET_DESC = OFFSET_LENGTH + 4; int lengthAscii = bb.getInt(OFFSET_LENGTH); byte[] asciiDesc = new byte[lengthAscii -1]; bb.position(OFFSET_DESC); bb.get(asciiDesc); description = new String(asciiDesc, StandardCharsets.US_ASCII); } else { final int OFFSET_NUMBER = 8; final int MLUC_TAG = 0x6D6C7563; final int OFFSET_NAME_LENGTH = 20; final int OFFSET_NAME_OFFSET = 24; int tagMluc = bb.getInt(0); int nb = bb.getInt(OFFSET_NUMBER); if (tagMluc != MLUC_TAG || nb < 1) { throw new IllegalArgumentException(CoreMessageConstants.ERR_ICC_PRFL_DESC_MISS); } int firstNameLength = bb.getInt(OFFSET_NAME_LENGTH); int firstNameOffset = bb.getInt(OFFSET_NAME_OFFSET); byte[] desc = new byte[firstNameLength]; bb.position(firstNameOffset); bb.get(desc); description = new String(desc, StandardCharsets.UTF_16BE); } return description; } NisoImageMetadata(); int getAutoFocus(); int getBackLight(); int [] getBitsPerSample(); Rational getBrightness(); String getByteOrder(); int getChecksumMethod(); String getChecksumValue(); int [] getColormapBitCodeValue(); int [] getColormapBlueValue(); int [] getColormapGreenValue(); int [] getColormapRedValue(); String getColormapReference(); int getColorSpace(); double getColorTemp(); int getCompressionLevel(); int getCompressionScheme(); String getDateTimeCreated(); String getDateTimeProcessed(); String getDeviceSource(); String getDigitalCameraManufacturer(); String getDigitalCameraModelName(); String getDigitalCameraModelNumber(); String getDigitalCameraModelSerialNo(); int getDisplayOrientation(); String getExifVersion(); Rational getExposureBias(); double getExposureIndex(); int getExposureProgram(); double getExposureTime(); int [] getExtraSamples(); long getFileSize(); int getFlash(); Rational getFlashEnergy(); int getFlashReturn(); double getFNumber(); double getFocalLength(); int [] getGrayResponseCurve(); int getGrayResponseUnit(); String getHostComputer(); String getImageData(); String getImageIdentifier(); String getImageIdentifierLocation(); long getImageLength(); String getImageProducer(); long getImageWidth(); Rational getMaxApertureValue(); int getMeteringMode(); String getMethodology(); String getMimeType(); int getOrientation(); String getOS(); String getOSVersion(); String getPerformanceData(); double getPixelSize(); int getPlanarConfiguration(); String getPreferredPresentation(); String getJp2Tiles(); void setJp2Tiles(String jp2Tiles); int getJp2Layers(); void setJp2Layers(int jp2Layers); int getJp2ResolutionLevels(); void setJp2ResolutionLevels(int jp2ResolutionLevels); Rational getPrimaryChromaticitiesBlueX(); Rational getPrimaryChromaticitiesBlueY(); Rational getPrimaryChromaticitiesGreenX(); Rational getPrimaryChromaticitiesGreenY(); Rational getPrimaryChromaticitiesRedX(); Rational getPrimaryChromaticitiesRedY(); String[] getProcessingActions(); String getProcessingAgency(); String getProcessingSoftwareName(); String getProcessingSoftwareVersion(); String getProfileName(); String getProfiles(); String getProfileURL(); Rational [] getReferenceBlackWhite(); long getRowsPerStrip(); int getSamplesPerPixel(); int getSamplingFrequencyPlane(); int getSamplingFrequencyUnit(); String getScannerManufacturer(); String getScannerModelName(); String getScannerModelNumber(); String getScannerModelSerialNo(); String getScanningSoftware(); String getScanningSoftwareVersionNo(); int getSceneIlluminant(); int getSegmentType(); int getSensor(); String getSourceData(); String getSourceID(); String getSourceType(); double getSourceXDimension(); int getSourceXDimensionUnit(); double getSourceYDimension(); int getSourceYDimensionUnit(); long [] getStripByteCounts(); long [] getStripOffsets(); double [] getSubjectDistance(); String getTargetIDManufacturer(); String getTargetIDMedia(); String getTargetIDName(); String getTargetIDNo(); int getTargetType(); long [] getTileByteCounts(); long getTileLength(); long [] getTileOffsets(); long getTileWidth(); Rational getWhitePointXValue(); Rational getWhitePointYValue(); double getXPrintAspectRatio(); double getXPhysScanResolution(); Rational getXSamplingFrequency(); long getXTargetedDisplayAR(); Rational [] getYCbCrCoefficients(); int getYCbCrPositioning(); int [] getYCbCrSubSampling(); double getYPhysScanResolution(); double getYPrintAspectRatio(); Rational getYSamplingFrequency(); long getYTargetedDisplayAR(); Property getViewerData(); void setAutoFocus(int focus); void setBackLight(int light); void setBitsPerSample(int [] bits); void setBrightness(Rational brightness); void setByteOrder(String order); void setColormapBitCodeValue(int [] value); void setColormapBlueValue(int [] value); void setColormapGreenValue(int [] value); void setColormapRedValue(int [] value); void setColormapReference(String reference); void setColorSpace(int space); void setColorTemp(double temp); void setCompressionLevel(int level); void setCompressionScheme(int scheme); void setDateTimeCreated(String date); void setDateTimeProcessed(String date); void setDeviceSource(String source); void setDigitalCameraManufacturer(String manufacturer); void setDigitalCameraModelName(String modelName); void setDigitalCameraModelNumber(String modelNumber); void setDigitalCameraModelSerialNo(String modelSerialNo); void setDisplayOrientation(int orientation); void setExifVersion(String version); void setExposureBias(Rational bias); void setExposureIndex(double index); void setExposureProgram(int program); void setExposureTime(double time); void setExtraSamples(int [] extra); void setFileSize(long size); void setFNumber(double f); void setFlashEnergy(Rational energy); void setFlashReturn(int ret); void setFlash(int flash); void setFocalLength(double length); void setGrayResponseCurve(int [] curve); void setGrayResponseUnit(int unit); void setHostComputer(String computer); void setImageData(String imageData); void setImageIdentifier(String identifier); void setImageIdentifierLocation(String location); void setImageLength(long length); void setImageProducer(String producer); void setImageWidth(long width); void setMaxApertureValue(Rational value); void setMeteringMode(int mode); void setMethodology(String methodology); void setMimeType(String type); void setOrientation(int orientation); void setOS(String os); void setOSVersion(String version); void setPerformanceData(String performanceData); void setPixelSize(double size); void setPlanarConfiguration(int configuration); void setPreferredPresentation(String presentation); void setPrimaryChromaticitiesBlueX(Rational x); void setPrimaryChromaticitiesBlueY(Rational y); void setPrimaryChromaticitiesGreenX(Rational x); void setPrimaryChromaticitiesGreenY(Rational y); void setPrimaryChromaticitiesRedX(Rational x); void setPrimaryChromaticitiesRedY(Rational y); void setProcessingActions(String[] actions); void setProcessingAgency(String processingAgency); void setProcessingSoftwareName(String name); void setProcessingSoftwareVersion(String version); void setProfileName(String name); void setProfiles(String profiles); void setProfileURL(String URL); void setReferenceBlackWhite(Rational [] reference); void setRowsPerStrip(long rows); void setSamplingFrequencyPlane(int plane); void setSamplesPerPixel(int samples); void setSamplingFrequencyUnit(int unit); void setScannerManufacturer(String manufacturer); void setScannerModelName(String name); void setScannerModelNumber(String number); void setScannerModelSerialNo(String number); void setScanningSoftware(String software); void setScanningSoftwareVersionNo(String number); void setSceneIlluminant(int illuminant); void setSensor(int sensor); void setSourceData(String sourceData); void setSourceID(String id); void setSourceType(String type); void setSourceXDimension(double x); void setSourceXDimensionUnit(int unit); void setSourceYDimension(double y); void setSourceYDimensionUnit(int unit); void setStripByteCounts(long [] counts); void setStripOffsets(long [] offsets); void setSubjectDistance(double [] distance); void setTargetIDManufacturer(String targetIDManufacturer); void setTargetIDMedia(String targetIDMedia); void setTargetIDName(String targetIDName); void setTargetIDNo(String targetIDNo); void setTargetType(int targetType); void setTileByteCounts(long [] counts); void setTileLength(long length); void setTileOffsets(long [] offsets); void setTileWidth(long width); void setWhitePointXValue(Rational x); void setWhitePointYValue(Rational y); void setXPhysScanResolution(double x); void setXPrintAspectRatio(double x); void setXSamplingFrequency(Rational x); void setXTargetedDisplayAspectRatio(long x); void setYCbCrCoefficients(Rational [] coefficients); void setYCbCrPositioning(int positioning); void setYCbCrSubSampling(int [] sampling); void setYPhysScanResolution(double y); void setYPrintAspectRatio(double y); void setYSamplingFrequency(Rational y); void setYTargetedDisplayAspectRatio(long y); void setViewerData(Property viewerData); static String extractIccProfileDescription(byte[] data); static final String [] AUTOFOCUS; static final String [] BACKLIGHT; static final String [] BYTEORDER; static final String [] CHECKSUM_METHOD; static final String [] COLORSPACE; static final int [] COLORSPACE_INDEX; static final String [] COMPRESSION_SCHEME; static final int COMPRESSION_JPEG2000_LOSSY; static final int COMPRESSION_JPEG2000_LOSSLESS; static final int [] COMPRESSION_SCHEME_INDEX; static final String [] DISPLAY_ORIENTATION; static final String [] EXTRA_SAMPLES; static final String [] EXPOSURE_PROGRAM; static final String [] FLASH; static final String [] FLASH_20; static final String [] FLASH_RETURN; static final String [] GRAY_RESPONSE_UNIT_02; static final String [] GRAY_RESPONSE_UNIT_20; static final String [] EXTRA_SAMPLE_20; static final String [] METERING_MODE; static final String [] ORIENTATION; static final String [] PLANAR_CONFIGURATION; static final String [] SAMPLING_FREQUENCY_PLANE; static final String [] SAMPLING_FREQUENCY_UNIT; static final String [] SCENE_ILLUMINANT; static final int [] SCENE_ILLUMINANT_INDEX; static final String [] SEGMENT_TYPE; static final String [] SENSOR; static final String [] SOURCE_DIMENSION_UNIT; static final String [] YCBCR_POSITIONING; static final String [] TARGET_TYPE; static final int NULL; static final double NILL; }
@Test public void testExtractIccProfileDescriptionBad() { final byte ANY_BYTE_1 = (byte) 0xFF; final byte ANY_BYTE_2 = (byte) 0xFE; final byte[] BAD_ICC = new byte[] { ANY_BYTE_1, ANY_BYTE_2, ANY_BYTE_1, ANY_BYTE_2 }; try { NisoImageMetadata.extractIccProfileDescription(BAD_ICC); fail(ERROR_TEST); } catch (IllegalArgumentException iae) { assertNotNull(iae); } }
@Test public void testExtractIccProfileDescriptionGoodv2() throws IOException { try (InputStream is = this.getClass().getResourceAsStream("sRGB2014.icc")) { byte[] iccData = toByteArray(is); String profileName = NisoImageMetadata .extractIccProfileDescription(iccData); assertEquals("sRGB2014", profileName); } catch (IllegalArgumentException iae) { fail(ERROR_TEST + iae.getMessage()); } }
@Test public void testExtractIccProfileDescriptionGoodv4() throws IOException { try (InputStream is = this.getClass().getResourceAsStream( "sRGB_v4_ICC_preference.icc")) { byte[] iccData = toByteArray(is); String profileName = NisoImageMetadata .extractIccProfileDescription(iccData); assertEquals("sRGB v4 ICC preference perceptual intent beta", profileName); } catch (IllegalArgumentException iae) { fail(ERROR_TEST + iae.getMessage()); } }