001/* 002 * $RCSfile: WTDecompSpec.java,v $ 003 * $Revision: 1.1 $ 004 * $Date: 2005/02/11 05:02:27 $ 005 * $State: Exp $ 006 * 007 * Class: WTDecompSpec 008 * 009 * Description: <short description of class> 010 * 011 * 012 * 013 * COPYRIGHT: 014 * 015 * This software module was originally developed by Raphaël Grosbois and 016 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel 017 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David 018 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research 019 * Centre France S.A) in the course of development of the JPEG2000 020 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This 021 * software module is an implementation of a part of the JPEG 2000 022 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio 023 * Systems AB and Canon Research Centre France S.A (collectively JJ2000 024 * Partners) agree not to assert against ISO/IEC and users of the JPEG 025 * 2000 Standard (Users) any of their rights under the copyright, not 026 * including other intellectual property rights, for this software module 027 * with respect to the usage by ISO/IEC and Users of this software module 028 * or modifications thereof for use in hardware or software products 029 * claiming conformance to the JPEG 2000 Standard. Those intending to use 030 * this software module in hardware or software products are advised that 031 * their use may infringe existing patents. The original developers of 032 * this software module, JJ2000 Partners and ISO/IEC assume no liability 033 * for use of this software module or modifications thereof. No license 034 * or right to this software module is granted for non JPEG 2000 Standard 035 * conforming products. JJ2000 Partners have full right to use this 036 * software module for his/her own purpose, assign or donate this 037 * software module to any third party and to inhibit third parties from 038 * using this software module for non JPEG 2000 Standard conforming 039 * products. This copyright notice must be included in all copies or 040 * derivative works of this software module. 041 * 042 * Copyright (c) 1999/2000 JJ2000 Partners. 043 * 044 * 045 * 046 */ 047 048 049package jj2000.j2k.wavelet; 050 051import jj2000.j2k.*; 052 053/** 054 * This class holds the decomposition type to be used in each part of the 055 * image; the default one, the component specific ones, the tile default ones 056 * and the component-tile specific ones. 057 * 058 * <P>The decomposition type identifiers values are the same as in the 059 * codestream. 060 * 061 * <P>The hierarchy is:<br> 062 * - Tile and component specific decomposition<br> 063 * - Tile specific default decomposition<br> 064 * - Component main default decomposition<br> 065 * - Main default decomposition<br> 066 * 067 * <P>At the moment tiles are not supported by this class. 068 * */ 069public class WTDecompSpec { 070 /** 071 * ID for the dyadic wavelet tree decomposition (also called 072 * "Mallat" in JPEG 2000): 0x00. 073 */ 074 public final static int WT_DECOMP_DYADIC = 0; 075 076 /** 077 * ID for the SPACL (as defined in JPEG 2000) wavelet tree 078 * decomposition (1 level of decomposition in the high bands and 079 * some specified number for the lowest LL band): 0x02. */ 080 public final static int WT_DECOMP_SPACL = 2; 081 082 /** 083 * ID for the PACKET (as defined in JPEG 2000) wavelet tree 084 * decomposition (2 levels of decomposition in the high bands and 085 * some specified number for the lowest LL band): 0x01. */ 086 public final static int WT_DECOMP_PACKET = 1; 087 088 /** The identifier for "main default" specified decomposition */ 089 public final static byte DEC_SPEC_MAIN_DEF = 0; 090 091 /** The identifier for "component default" specified decomposition */ 092 public final static byte DEC_SPEC_COMP_DEF = 1; 093 094 /** The identifier for "tile specific default" specified decomposition */ 095 public final static byte DEC_SPEC_TILE_DEF = 2; 096 097 /** The identifier for "tile and component specific" specified 098 decomposition */ 099 public final static byte DEC_SPEC_TILE_COMP = 3; 100 101 /** The spec type for each tile and component. The first index is the 102 * component index, the second is the tile index. NOTE: The tile specific 103 * things are not supported yet. */ 104 // Use byte to save memory (no need for speed here). 105 private byte specValType[]; 106 107 /** The main default decomposition */ 108 private int mainDefDecompType; 109 110 /** The main default number of decomposition levels */ 111 private int mainDefLevels; 112 113 /** The component main default decomposition, for each component. */ 114 private int compMainDefDecompType[]; 115 116 /** The component main default decomposition levels, for each component */ 117 private int compMainDefLevels[]; 118 119 /** 120 * Constructs a new 'WTDecompSpec' for the specified number of components 121 * and tiles, with the given main default decomposition type and number of 122 * levels. 123 * 124 * <P>NOTE: The tile specific things are not supported yet 125 * 126 * @param nc The number of components 127 * 128 * @param nt The number of tiles 129 * 130 * @param dec The main default decomposition type 131 * 132 * @param lev The main default number of decomposition levels 133 * 134 * 135 * */ 136 public WTDecompSpec(int nc, int dec, int lev) { 137 mainDefDecompType = dec; 138 mainDefLevels = lev; 139 specValType = new byte[nc]; 140 } 141 142 /** 143 * Sets the "component main default" decomposition type and number of 144 * levels for the specified component. Both 'dec' and 'lev' can not be 145 * negative at the same time. 146 * 147 * @param n The component index 148 * 149 * @param dec The decomposition type. If negative then the main default is 150 * used. 151 * 152 * @param lev The number of levels. If negative then the main defaul is 153 * used. 154 * 155 * 156 * */ 157 public void setMainCompDefDecompType(int n, int dec, int lev) { 158 if (dec < 0 && lev < 0) { 159 throw new IllegalArgumentException(); 160 } 161 // Set spec type and decomp 162 specValType[n] = DEC_SPEC_COMP_DEF; 163 if (compMainDefDecompType == null) { 164 compMainDefDecompType = new int[specValType.length]; 165 compMainDefLevels = new int[specValType.length]; 166 } 167 compMainDefDecompType[n] = (dec >= 0) ? dec : mainDefDecompType; 168 compMainDefLevels[n] = (lev >= 0) ? lev : mainDefLevels; 169 // For the moment disable it since other parts of JJ2000 do not 170 // support this 171 throw new NotImplementedError("Currently, in JJ2000, all components "+ 172 "and tiles must have the same "+ 173 "decomposition type and number of "+ 174 "levels"); 175 } 176 177 /** 178 * Returns the type of specification for the decomposition in the 179 * specified component and tile. The specification type is one of: 180 * 'DEC_SPEC_MAIN_DEF', 'DEC_SPEC_COMP_DEF', 'DEC_SPEC_TILE_DEF', 181 * 'DEC_SPEC_TILE_COMP'. 182 * 183 * <P>NOTE: The tile specific things are not supported yet 184 * 185 * @param n The component index 186 * 187 * @param t The tile index, in raster scan order. 188 * 189 * @return The specification type for component 'n' and tile 't'. 190 * 191 * 192 * */ 193 public byte getDecSpecType(int n) { 194 return specValType[n]; 195 } 196 197 /** 198 * Returns the main default decomposition type. 199 * 200 * @return The main default decomposition type. 201 * 202 * 203 * */ 204 public int getMainDefDecompType() { 205 return mainDefDecompType; 206 } 207 208 /** 209 * Returns the main default decomposition number of levels. 210 * 211 * @return The main default decomposition number of levels. 212 * 213 * 214 * */ 215 public int getMainDefLevels() { 216 return mainDefLevels; 217 } 218 219 /** 220 * Returns the decomposition type to be used in component 'n' and tile 221 * 't'. 222 * 223 * <P>NOTE: The tile specific things are not supported yet 224 * 225 * @param n The component index. 226 * 227 * @param t The tile index, in raster scan order 228 * 229 * @return The decomposition type to be used. 230 * 231 * 232 * */ 233 public int getDecompType(int n) { 234 switch (specValType[n]) { 235 case DEC_SPEC_MAIN_DEF: 236 return mainDefDecompType; 237 case DEC_SPEC_COMP_DEF: 238 return compMainDefDecompType[n]; 239 case DEC_SPEC_TILE_DEF: 240 throw new NotImplementedError(); 241 case DEC_SPEC_TILE_COMP: 242 throw new NotImplementedError(); 243 default: 244 throw new Error("Internal JJ2000 error"); 245 } 246 } 247 248 /** 249 * Returns the decomposition number of levels in component 'n' and tile 250 * 't'. 251 * 252 * <P>NOTE: The tile specific things are not supported yet 253 * 254 * @param n The component index. 255 * 256 * @param t The tile index, in raster scan order 257 * 258 * @return The decomposition number of levels. 259 * 260 * 261 * */ 262 public int getLevels(int n) { 263 switch (specValType[n]) { 264 case DEC_SPEC_MAIN_DEF: 265 return mainDefLevels; 266 case DEC_SPEC_COMP_DEF: 267 return compMainDefLevels[n]; 268 case DEC_SPEC_TILE_DEF: 269 throw new NotImplementedError(); 270 case DEC_SPEC_TILE_COMP: 271 throw new NotImplementedError(); 272 default: 273 throw new Error("Internal JJ2000 error"); 274 } 275 } 276}