001/******************************************************************************* 002 * This software is provided as a supplement to the authors' textbooks on digital 003 * image processing published by Springer-Verlag in various languages and editions. 004 * Permission to use and distribute this software is granted under the BSD 2-Clause 005 * "Simplified" License (see http://opensource.org/licenses/BSD-2-Clause). 006 * Copyright (c) 2006-2025 Wilhelm Burger, Mark J. Burge. All rights reserved. 007 * Visit https://imagingbook.com for additional details. 008 ******************************************************************************/ 009package imagingbook.common.color.cie; 010 011import imagingbook.core.resource.NamedResource; 012import imagingbook.core.resource.ResourceUtils; 013 014import java.awt.color.ICC_ColorSpace; 015import java.awt.color.ICC_Profile; 016import java.io.IOException; 017import java.net.URI; 018 019public enum NamedIccProfile implements NamedResource { 020 AdobeRGB1998("AdobeRGB1998.icc"), 021 AppleRGB("AppleRGB.icc"), 022 CIERGB("CIERGB.icc"), 023 PAL_SECAM("PAL_SECAM.icc"), 024 SMPTE_C("SMPTE-C.icc"), 025 VideoHD("VideoHD.icc"), 026 VideoNTSC("VideoNTSC.icc"), 027 VideoPAL("VideoPAL.icc"), 028 WideGamutRGB("WideGamutRGB.icc") 029 ; 030 031 private final String filename; 032 private ICC_Profile profile = null; 033 private ICC_ColorSpace colorspace = null; 034 035 NamedIccProfile(String filename) { 036 this.filename = filename; 037 this.profile = null; // singleton profile instance 038 this.colorspace = null; // singleton color space instance 039 } 040 041 @Override 042 public String getFileName() { 043 return filename; 044 } 045 046 /** 047 * Returns the {@link ICC_Profile} associated with this enum item or {@code null} if the profile could not be read 048 * (which is an error). 049 * 050 * @return the {@link ICC_Profile} associated with this enum item 051 */ 052 public ICC_Profile getProfile() { 053 if (this.profile == null) { 054 try { 055 profile = ICC_Profile.getInstance(this.getStream()); 056 } catch (IOException e) { 057 throw new RuntimeException("could not load ICC profile " + this.toString()); 058 } 059 } 060 return this.profile; 061 } 062 063 /** 064 * Returns a {@link ICC_ColorSpace} instance obtained from the associated ICC color profile. An exception is thrown 065 * if the profile could not be read. 066 * 067 * @return the {@link ICC_ColorSpace} associated with this enum item 068 */ 069 public ICC_ColorSpace getColorSpace() { 070 if (this.colorspace == null) { 071 ICC_Profile profile = this.getProfile(); 072 this.colorspace = new ICC_ColorSpace(profile); 073 } 074 return this.colorspace; 075 } 076 077 public static void main(String[] args) { 078 Class clazz = NamedIccProfile.AdobeRGB1998.getClass(); 079 System.out.println("rel directory = " + NamedResource.getRelativeDirectory(clazz)); 080 String relPath = NamedIccProfile.AdobeRGB1998.getRelativePath(); 081 System.out.println("rel path = " + relPath); 082 System.out.println("URL = " + NamedIccProfile.AdobeRGB1998.getURL()); 083 084 URI uri = ResourceUtils.getResourceUri(NamedIccProfile.AdobeRGB1998.getClass(), relPath); 085 System.out.println("uri = " + uri); 086 087 String[] names = NamedResource.getNamedResourceFileNames(NamedIccProfile.AdobeRGB1998.getClass()); 088 for (String n : names) { 089 System.out.println(" " + n); 090 } 091 } 092 093}