001/* ***** BEGIN LICENSE BLOCK ***** 002 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 003 * 004 * The contents of this file are subject to the Mozilla Public License Version 005 * 1.1 (the "License"); you may not use this file except in compliance with 006 * the License. You may obtain a copy of the License at 007 * http://www.mozilla.org/MPL/ 008 * 009 * Software distributed under the License is distributed on an "AS IS" basis, 010 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 011 * for the specific language governing rights and limitations under the 012 * License. 013 * 014 * The Original Code is part of dcm4che, an implementation of DICOM(TM) in 015 * Java(TM), hosted at https://github.com/gunterze/dcm4che. 016 * 017 * The Initial Developer of the Original Code is 018 * Agfa Healthcare. 019 * Portions created by the Initial Developer are Copyright (C) 2013 020 * the Initial Developer. All Rights Reserved. 021 * 022 * Contributor(s): 023 * See @authors listed below 024 * 025 * Alternatively, the contents of this file may be used under the terms of 026 * either the GNU General Public License Version 2 or later (the "GPL"), or 027 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 028 * in which case the provisions of the GPL or the LGPL are applicable instead 029 * of those above. If you wish to allow use of your version of this file only 030 * under the terms of either the GPL or the LGPL, and not to allow others to 031 * use your version of this file under the terms of the MPL, indicate your 032 * decision by deleting the provisions above and replace them with the notice 033 * and other provisions required by the GPL or the LGPL. If you do not delete 034 * the provisions above, a recipient may use your version of this file under 035 * the terms of any one of the MPL, the GPL or the LGPL. 036 * 037 * ***** END LICENSE BLOCK ***** */ 038 039package org.dcm4che3.image; 040 041import java.awt.image.BandedSampleModel; 042import java.awt.image.ColorModel; 043import java.awt.image.PixelInterleavedSampleModel; 044import java.awt.image.SampleModel; 045 046import org.dcm4che3.data.Attributes; 047 048/** 049 * @author Gunter Zeilinger <gunterze@gmail.com> 050 * 051 */ 052public enum PhotometricInterpretation { 053 MONOCHROME1 { 054 @Override 055 public boolean isMonochrome() { 056 return true; 057 } 058 059 @Override 060 public boolean isInvers() { 061 return true; 062 } 063 064 @Override 065 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 066 return ColorModelFactory.createMonochromeColorModel(bits, dataType); 067 } 068 }, 069 MONOCHROME2 { 070 @Override 071 public boolean isMonochrome() { 072 return true; 073 } 074 075 @Override 076 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 077 return ColorModelFactory.createMonochromeColorModel(bits, dataType); 078 } 079 }, 080 PALETTE_COLOR { 081 @Override 082 public String toString() { 083 return "PALETTE COLOR"; 084 } 085 086 @Override 087 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 088 return ColorModelFactory.createPaletteColorModel(bits, dataType, ds); 089 } 090 }, 091 RGB { 092 @Override 093 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 094 return ColorModelFactory.createRGBColorModel(bits, dataType, ds); 095 } 096 }, 097 YBR_FULL { 098 @Override 099 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 100 return ColorModelFactory.createYBRFullColorModel(bits, dataType, ds); 101 } 102 }, 103 YBR_FULL_422 { 104 @Override 105 public int frameLength(int w, int h, int samples, int bitsAllocated) { 106 return ColorSubsampling.YBR_XXX_422.frameLength(w, h); 107 } 108 109 @Override 110 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 111 return ColorModelFactory.createYBRColorModel(bits, dataType, ds, 112 YBR.FULL, ColorSubsampling.YBR_XXX_422); 113 } 114 115 @Override 116 public SampleModel createSampleModel(int dataType, int w, int h, 117 int samples, boolean banded) { 118 return new SampledComponentSampleModel(w, h, ColorSubsampling.YBR_XXX_422); 119 } 120 121 @Override 122 public PhotometricInterpretation decompress() { 123 return RGB; 124 } 125 126 @Override 127 public boolean isSubSambled() { 128 return true; 129 } 130 }, 131 YBR_PARTIAL_422 { 132 @Override 133 public int frameLength(int w, int h, int samples, int bitsAllocated) { 134 return ColorSubsampling.YBR_XXX_422.frameLength(w, h); 135 } 136 137 @Override 138 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 139 return ColorModelFactory.createYBRColorModel(bits, dataType, ds, 140 YBR.PARTIAL, ColorSubsampling.YBR_XXX_422); 141 } 142 143 @Override 144 public SampleModel createSampleModel(int dataType, int w, int h, 145 int samples, boolean banded) { 146 return new SampledComponentSampleModel(w, h, ColorSubsampling.YBR_XXX_422); 147 } 148 149 @Override 150 public PhotometricInterpretation decompress() { 151 return RGB; 152 } 153 154 @Override 155 public boolean isSubSambled() { 156 return true; 157 } 158 }, 159 YBR_PARTIAL_420 { 160 @Override 161 public int frameLength(int w, int h, int samples, int bitsAllocated) { 162 return ColorSubsampling.YBR_XXX_420.frameLength(w, h); 163 } 164 165 @Override 166 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 167 return ColorModelFactory.createYBRColorModel(bits, dataType, ds, 168 YBR.PARTIAL, ColorSubsampling.YBR_XXX_420); 169 } 170 171 @Override 172 public SampleModel createSampleModel(int dataType, int w, int h, 173 int samples, boolean banded) { 174 return new SampledComponentSampleModel(w, h, ColorSubsampling.YBR_XXX_420); 175 } 176 177 @Override 178 public PhotometricInterpretation decompress() { 179 return RGB; 180 } 181 182 @Override 183 public boolean isSubSambled() { 184 return true; 185 } 186 }, 187 YBR_ICT { 188 @Override 189 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 190 throw new UnsupportedOperationException(); 191 } 192 193 @Override 194 public PhotometricInterpretation decompress() { 195 return RGB; 196 } 197 }, 198 YBR_RCT { 199 @Override 200 public ColorModel createColorModel(int bits, int dataType, Attributes ds) { 201 throw new UnsupportedOperationException(); 202 } 203 204 @Override 205 public PhotometricInterpretation decompress() { 206 return RGB; 207 } 208 }; 209 210 public static PhotometricInterpretation fromString(String s) { 211 return s.equals("PALETTE COLOR") ? PALETTE_COLOR : valueOf(s); 212 } 213 214 public int frameLength(int w, int h, int samples, int bitsAllocated) { 215 return w * h * samples * (bitsAllocated >> 3); 216 } 217 218 public boolean isMonochrome() { 219 return false; 220 } 221 222 public PhotometricInterpretation decompress() { 223 return this; 224 } 225 226 public boolean isInvers() { 227 return false; 228 } 229 230 public boolean isSubSambled() { 231 return false; 232 } 233 234 public abstract ColorModel createColorModel(int bits, int dataType, 235 Attributes ds); 236 237 public SampleModel createSampleModel(int dataType, int w, int h, 238 int samples, boolean banded) { 239 int[] indicies = new int[samples]; 240 for (int i = 1; i < samples; i++) 241 indicies[i] = i; 242 return banded 243 ? new BandedSampleModel(dataType, w, h, 244 w, indicies, new int[samples]) 245 : new PixelInterleavedSampleModel(dataType, w, h, 246 samples, w * samples, indicies); 247 } 248}