/// <summary> Reads all tiles headers and keep offset of their first /// packet. Finally it calls the rate allocation method. /// /// </summary> /// <param name="hd">HeaderDecoder of the codestream. /// /// </param> /// <param name="ehs">The input stream where to read bit-stream. /// /// </param> /// <param name="decSpec">The decoder specifications /// /// </param> /// <param name="pl">The ParameterList instance created from the /// command-line arguments. /// /// </param> /// <param name="cdstrInfo">Whether or not to print information found in /// codestream. /// /// </param> /// <seealso cref="allocateRate"> /// /// </seealso> public FileBitstreamReaderAgent(HeaderDecoder hd, RandomAccessIO ehs, DecoderSpecs decSpec, ParameterList pl, bool cdstrInfo, HeaderInfo hi):base(hd, decSpec) { this.pl = pl; this.printInfo = cdstrInfo; this.hi = hi; // Check whether quit conditiosn used usePOCQuit = pl.getBooleanParameter("poc_quit"); // Get decoding rate bool rateInBytes; bool parsing = pl.getBooleanParameter("parsing"); try { trate = pl.getFloatParameter("rate"); if (trate == - 1) { trate = System.Single.MaxValue; } } catch (System.FormatException) { throw new System.ApplicationException("Invalid value in 'rate' option: " + pl.getParameter("rate")); } catch (System.ArgumentException) { throw new System.ApplicationException("'rate' option is missing"); } try { tnbytes = pl.getIntParameter("nbytes"); } catch (System.FormatException) { throw new System.ApplicationException("Invalid value in 'nbytes' option: " + pl.getParameter("nbytes")); } catch (System.ArgumentException) { throw new System.ApplicationException("'nbytes' option is missing"); } // Check that '-rate' and '-nbytes' are not used at the same time ParameterList defaults = pl.DefaultParameterList; if (tnbytes != defaults.getFloatParameter("nbytes")) { rateInBytes = true; } else { rateInBytes = false; } if (rateInBytes) { trate = tnbytes * 8f / hd.MaxCompImgWidth / hd.MaxCompImgHeight; } else { //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" tnbytes = (int) (trate * hd.MaxCompImgWidth * hd.MaxCompImgHeight) / 8; if (tnbytes < 0) tnbytes = int.MaxValue; } isTruncMode = !pl.getBooleanParameter("parsing"); // Check if quit conditions are being used int ncbQuit; try { ncbQuit = pl.getIntParameter("ncb_quit"); } catch (System.FormatException) { throw new System.ApplicationException("Invalid value in 'ncb_quit' option: " + pl.getParameter("ncb_quit")); } catch (System.ArgumentException) { throw new System.ApplicationException("'ncb_quit' option is missing"); } if (ncbQuit != - 1 && !isTruncMode) { throw new System.ApplicationException("Cannot use -parsing and -ncb_quit condition at " + "the same time."); } try { lQuit = pl.getIntParameter("l_quit"); } catch (System.FormatException) { throw new System.ApplicationException("Invalid value in 'l_quit' option: " + pl.getParameter("l_quit")); } catch (System.ArgumentException) { throw new System.ApplicationException("'l_quit' option is missing"); } // initializations in_Renamed = ehs; pktDec = new PktDecoder(decSpec, hd, ehs, this, isTruncMode, ncbQuit); tileParts = new int[nt]; totTileLen = new int[nt]; tilePartLen = new int[nt][]; tilePartNum = new int[nt][]; firstPackOff = new int[nt][]; tilePartsRead = new int[nt]; totTileHeadLen = new int[nt]; tilePartHeadLen = new int[nt][]; nBytes = new int[nt]; baknBytes = new int[nt]; hd.nTileParts = new int[nt]; // CONVERSION PROBLEM? //this.isTruncMode = isTruncMode; int t = 0, pos, tp = 0, tptot = 0; // Keeps main header's length, takes file format overhead into account int cdstreamStart = hd.mainHeadOff; // Codestream offset in the file mainHeadLen = in_Renamed.Pos - cdstreamStart; headLen = mainHeadLen; // If ncb and lbody quit conditions are used, headers are not counted if (ncbQuit == - 1) { anbytes = mainHeadLen; } else { anbytes = 0; } // If cannot even read the first tile-part if (anbytes > tnbytes) { throw new System.ApplicationException("Requested bitrate is too small."); } // Read all tile-part headers from all tiles. int tilePartStart; bool rateReached = false; int mdl; //int numtp = 0; totAllTileLen = 0; remainingTileParts = nt; // at least as many tile-parts as tiles int maxTP = nt; // If maximum 1 tile part per tile specified try { while (remainingTileParts != 0) { tilePartStart = in_Renamed.Pos; // Read tile-part header try { t = readTilePartHeader(); if (isEOCFound) { // Some tiles are missing but the // codestream is OK break; } tp = tilePartsRead[t]; if (isPsotEqualsZero) { // Psot may equals zero for the // last tile-part: it is assumed that this tile-part // contain all data until EOC tilePartLen[t][tp] = in_Renamed.length() - 2 - tilePartStart; } } catch (System.IO.EndOfStreamException e) { firstPackOff[t][tp] = in_Renamed.length(); throw e; } pos = in_Renamed.Pos; // In truncation mode, if target decoding rate is reached in // tile-part header, skips the tile-part and stop reading // unless the ncb and lbody quit condition is in use if (isTruncMode && ncbQuit == - 1) { if ((pos - cdstreamStart) > tnbytes) { firstPackOff[t][tp] = in_Renamed.length(); rateReached = true; break; } } // Set tile part position and header length firstPackOff[t][tp] = pos; tilePartHeadLen[t][tp] = (pos - tilePartStart); // Update length counters totTileLen[t] += tilePartLen[t][tp]; totTileHeadLen[t] += tilePartHeadLen[t][tp]; totAllTileLen += tilePartLen[t][tp]; if (isTruncMode) { if (anbytes + tilePartLen[t][tp] > tnbytes) { anbytes += tilePartHeadLen[t][tp]; headLen += tilePartHeadLen[t][tp]; rateReached = true; nBytes[t] += (tnbytes - anbytes); break; } else { anbytes += tilePartHeadLen[t][tp]; headLen += tilePartHeadLen[t][tp]; nBytes[t] += (tilePartLen[t][tp] - tilePartHeadLen[t][tp]); } } else { if (anbytes + tilePartHeadLen[t][tp] > tnbytes) { break; } else { anbytes += tilePartHeadLen[t][tp]; headLen += tilePartHeadLen[t][tp]; } } // If this is first tile-part, remember header length if (tptot == 0) firstTilePartHeadLen = tilePartHeadLen[t][tp]; // Go to the beginning of next tile part tilePartsRead[t]++; in_Renamed.seek(tilePartStart + tilePartLen[t][tp]); remainingTileParts--; maxTP--; tptot++; // If Psot of the current tile-part was equal to zero, it is // assumed that it contains all data until the EOC marker if (isPsotEqualsZero) { if (remainingTileParts != 0) { FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Some tile-parts have not " + "been found. The codestream may be corrupted."); } break; } } } catch (System.IO.EndOfStreamException) { if (printInfo) { } FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Codestream truncated in tile " + t); // Set specified rate to end of file if valid int fileLen = in_Renamed.length(); if (fileLen < tnbytes) { tnbytes = fileLen; trate = tnbytes * 8f / hd.MaxCompImgWidth / hd.MaxCompImgHeight; } // Bit-rate allocation if (!isTruncMode) { allocateRate(); } // Update 'res' value once all tile-part headers are read if (pl.getParameter("res") == null) { targetRes = decSpec.dls.Min; } else { try { targetRes = pl.getIntParameter("res"); if (targetRes < 0) { throw new System.ArgumentException("Specified negative " + "resolution level " + "index: " + targetRes); } } catch (System.FormatException) { throw new System.ArgumentException("Invalid resolution level " + "index ('-res' option) " + pl.getParameter("res")); } } // Verify reduction in resolution level mdl = decSpec.dls.Min; if (targetRes > mdl) { FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Specified resolution level (" + targetRes + ") is larger" + " than the maximum value. Setting it to " + mdl + " (maximum value)"); targetRes = mdl; } // Backup nBytes for (int tIdx = 0; tIdx < nt; tIdx++) { baknBytes[tIdx] = nBytes[tIdx]; } return ; } remainingTileParts = 0; // Update 'res' value once all tile-part headers are read if (pl.getParameter("res") == null) { targetRes = decSpec.dls.Min; } else { try { targetRes = pl.getIntParameter("res"); if (targetRes < 0) { throw new System.ArgumentException("Specified negative " + "resolution level index: " + targetRes); } } catch (System.FormatException) { throw new System.ArgumentException("Invalid resolution level " + "index ('-res' option) " + pl.getParameter("res")); } } // Verify reduction in resolution level mdl = decSpec.dls.Min; if (targetRes > mdl) { FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Specified resolution level (" + targetRes + ") is larger" + " than the maximum possible. Setting it to " + mdl + " (maximum possible)"); targetRes = mdl; } if (printInfo) { } // Check presence of EOC marker is decoding rate not reached or if // this marker has not been found yet if (!isEOCFound && !isPsotEqualsZero) { try { short eocCheck = 0; if (in_Renamed.Pos + sizeof(short) <= in_Renamed.length()) eocCheck = in_Renamed.readShort(); if (!rateReached && !isPsotEqualsZero && eocCheck != CSJ2K.j2k.codestream.Markers.EOC) { FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "EOC marker not found. " + "Codestream is corrupted."); } } catch (System.IO.EndOfStreamException) { FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "EOC marker is missing"); } } // Bit-rate allocation if (!isTruncMode) { allocateRate(); } else { // Take EOC into account if rate is not reached if (in_Renamed.Pos >= tnbytes) anbytes += 2; } // Backup nBytes for (int tIdx = 0; tIdx < nt; tIdx++) { baknBytes[tIdx] = nBytes[tIdx]; if (printInfo) { FacilityManager.getMsgLogger().println("" + hi.toStringTileHeader(tIdx, tilePartLen[tIdx].Length), 2, 2); } } }
/// <summary> Constructs a new 'AnWTFilterSpec' for the specified number of /// components and tiles. /// /// </summary> /// <param name="nt">The number of tiles /// /// </param> /// <param name="nc">The number of components /// /// </param> /// <param name="type">the type of the specification module i.e. tile specific, /// component specific or both. /// /// </param> /// <param name="qts">Quantization specifications /// /// </param> /// <param name="pl">The ParameterList /// /// </param> public AnWTFilterSpec(int nt, int nc, byte type, QuantTypeSpec qts, ParameterList pl):base(nt, nc, type) { // Check parameters pl.checkList(AnWTFilter.OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(AnWTFilter.ParameterInfo)); System.String param = pl.getParameter("Ffilters"); bool isFilterSpecified = true; // No parameter specified if (param == null) { isFilterSpecified = false; // If lossless compression, uses the reversible filters in each // tile-components if (pl.getBooleanParameter("lossless")) { setDefault(parseFilters(REV_FILTER_STR)); return ; } // If no filter is specified through the command-line, use // REV_FILTER_STR or NON_REV_FILTER_STR according to the // quantization type for (int t = nt - 1; t >= 0; t--) { for (int c = nc - 1; c >= 0; c--) { switch (qts.getSpecValType(t, c)) { case SPEC_DEF: if (getDefault() == null) { if (pl.getBooleanParameter("lossless")) setDefault(parseFilters(REV_FILTER_STR)); if (((System.String) qts.getDefault()).Equals("reversible")) { setDefault(parseFilters(REV_FILTER_STR)); } else { setDefault(parseFilters(NON_REV_FILTER_STR)); } } specValType[t][c] = SPEC_DEF; break; case SPEC_COMP_DEF: if (!isCompSpecified(c)) { if (((System.String) qts.getCompDef(c)).Equals("reversible")) { setCompDef(c, parseFilters(REV_FILTER_STR)); } else { setCompDef(c, parseFilters(NON_REV_FILTER_STR)); } } specValType[t][c] = SPEC_COMP_DEF; break; case SPEC_TILE_DEF: if (!isTileSpecified(t)) { if (((System.String) qts.getTileDef(t)).Equals("reversible")) { setTileDef(t, parseFilters(REV_FILTER_STR)); } else { setTileDef(t, parseFilters(NON_REV_FILTER_STR)); } } specValType[t][c] = SPEC_TILE_DEF; break; case SPEC_TILE_COMP: if (!isTileCompSpecified(t, c)) { if (((System.String) qts.getTileCompVal(t, c)).Equals("reversible")) { setTileCompVal(t, c, parseFilters(REV_FILTER_STR)); } else { setTileCompVal(t, c, parseFilters(NON_REV_FILTER_STR)); } } specValType[t][c] = SPEC_TILE_COMP; break; default: throw new System.ArgumentException("Unsupported " + "specification " + "type"); } } } return ; } // Parse argument SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param); System.String word; // current word byte curSpecType = SPEC_DEF; // Specification type of the // current parameter bool[] tileSpec = null; // Tiles concerned by the specification bool[] compSpec = null; // Components concerned by the specification AnWTFilter[][] filter; while (stk.HasMoreTokens()) { word = stk.NextToken(); switch (word[0]) { case 't': // Tiles specification case 'T': // Tiles specification tileSpec = parseIdx(word, nTiles); if (curSpecType == SPEC_COMP_DEF) curSpecType = SPEC_TILE_COMP; else curSpecType = SPEC_TILE_DEF; break; case 'c': // Components specification case 'C': // Components specification compSpec = parseIdx(word, nComp); if (curSpecType == SPEC_TILE_DEF) curSpecType = SPEC_TILE_COMP; else curSpecType = SPEC_COMP_DEF; break; case 'w': // WT filters specification case 'W': // WT filters specification if (pl.getBooleanParameter("lossless") && word.ToUpper().Equals("w9x7".ToUpper())) { throw new System.ArgumentException("Cannot use non " + "reversible " + "wavelet transform with" + " '-lossless' option"); } filter = parseFilters(word); if (curSpecType == SPEC_DEF) { setDefault(filter); } else if (curSpecType == SPEC_TILE_DEF) { for (int i = tileSpec.Length - 1; i >= 0; i--) if (tileSpec[i]) { setTileDef(i, filter); } } else if (curSpecType == SPEC_COMP_DEF) { for (int i = compSpec.Length - 1; i >= 0; i--) if (compSpec[i]) { setCompDef(i, filter); } } else { for (int i = tileSpec.Length - 1; i >= 0; i--) { for (int j = compSpec.Length - 1; j >= 0; j--) { if (tileSpec[i] && compSpec[j]) { setTileCompVal(i, j, filter); } } } } // Re-initialize curSpecType = SPEC_DEF; tileSpec = null; compSpec = null; break; default: throw new System.ArgumentException("Bad construction for " + "parameter: " + word); } } // Check that default value has been specified if (getDefault() == null) { int ndefspec = 0; for (int t = nt - 1; t >= 0; t--) { for (int c = nc - 1; c >= 0; c--) { if (specValType[t][c] == SPEC_DEF) { ndefspec++; } } } // If some tile-component have received no specification, it takes // the default value defined in ParameterList if (ndefspec != 0) { if (((System.String) qts.getDefault()).Equals("reversible")) setDefault(parseFilters(REV_FILTER_STR)); else setDefault(parseFilters(NON_REV_FILTER_STR)); } else { // All tile-component have been specified, takes the first // tile-component value as default. setDefault(getTileCompVal(0, 0)); switch (specValType[0][0]) { case SPEC_TILE_DEF: for (int c = nc - 1; c >= 0; c--) { if (specValType[0][c] == SPEC_TILE_DEF) specValType[0][c] = SPEC_DEF; } tileDef[0] = null; break; case SPEC_COMP_DEF: for (int t = nt - 1; t >= 0; t--) { if (specValType[t][0] == SPEC_COMP_DEF) specValType[t][0] = SPEC_DEF; } compDef[0] = null; break; case SPEC_TILE_COMP: specValType[0][0] = SPEC_DEF; tileCompVal["t0c0"] = null; break; } } } // Check consistency between filter and quantization type // specification for (int t = nt - 1; t >= 0; t--) { for (int c = nc - 1; c >= 0; c--) { // Reversible quantization if (((System.String) qts.getTileCompVal(t, c)).Equals("reversible")) { // If filter is reversible, it is OK if (isReversible(t, c)) continue; // If no filter has been defined, use reversible filter if (!isFilterSpecified) { setTileCompVal(t, c, parseFilters(REV_FILTER_STR)); } else { // Non reversible filter specified -> Error throw new System.ArgumentException("Filter of " + "tile-component" + " (" + t + "," + c + ") does" + " not allow " + "reversible " + "quantization. " + "Specify '-Qtype " + "expounded' or " + "'-Qtype derived'" + "in " + "the command line."); } } else { // No reversible quantization // No reversible filter -> OK if (!isReversible(t, c)) continue; // If no filter has been specified, use non-reversible // filter if (!isFilterSpecified) { setTileCompVal(t, c, parseFilters(NON_REV_FILTER_STR)); } else { // Reversible filter specified -> Error throw new System.ArgumentException("Filter of " + "tile-component" + " (" + t + "," + c + ") does" + " not allow " + "non-reversible " + "quantization. " + "Specify '-Qtype " + "reversible' in " + "the command line"); } } } } }
/// <summary> Constructs a new 'QuantTypeSpec' for the specified number of components /// and tiles and the arguments of "-Qtype" option. This constructor is /// called by the encoder. /// /// </summary> /// <param name="nt">The number of tiles /// /// </param> /// <param name="nc">The number of components /// /// </param> /// <param name="type">the type of the specification module i.e. tile specific, /// component specific or both. /// /// </param> /// <param name="pl">The ParameterList /// /// </param> public QuantTypeSpec(int nt, int nc, byte type, ParameterList pl):base(nt, nc, type) { System.String param = pl.getParameter("Qtype"); if (param == null) { if (pl.getBooleanParameter("lossless")) { setDefault("reversible"); } else { setDefault("expounded"); } return ; } // Parse argument SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param); System.String word; // current word byte curSpecValType = SPEC_DEF; // Specification type of the // current parameter bool[] tileSpec = null; // Tiles concerned by the specification bool[] compSpec = null; // Components concerned by the specification while (stk.HasMoreTokens()) { word = stk.NextToken().ToLower(); switch (word[0]) { case 't': // Tiles specification tileSpec = parseIdx(word, nTiles); if (curSpecValType == SPEC_COMP_DEF) { curSpecValType = SPEC_TILE_COMP; } else { curSpecValType = SPEC_TILE_DEF; } break; case 'c': // Components specification compSpec = parseIdx(word, nComp); if (curSpecValType == SPEC_TILE_DEF) { curSpecValType = SPEC_TILE_COMP; } else { curSpecValType = SPEC_COMP_DEF; } break; case 'r': // reversible specification case 'd': // derived quantization step size specification case 'e': // expounded quantization step size specification if (!word.ToUpper().Equals("reversible".ToUpper()) && !word.ToUpper().Equals("derived".ToUpper()) && !word.ToUpper().Equals("expounded".ToUpper())) { throw new System.ArgumentException("Unknown parameter " + "for " + "'-Qtype' option: " + word); } if (pl.getBooleanParameter("lossless") && (word.ToUpper().Equals("derived".ToUpper()) || word.ToUpper().Equals("expounded".ToUpper()))) { throw new System.ArgumentException("Cannot use non " + "reversible " + "quantization with " + "'-lossless' option"); } if (curSpecValType == SPEC_DEF) { // Default specification setDefault(word); } else if (curSpecValType == SPEC_TILE_DEF) { // Tile default specification for (int i = tileSpec.Length - 1; i >= 0; i--) { if (tileSpec[i]) { setTileDef(i, word); } } } else if (curSpecValType == SPEC_COMP_DEF) { // Component default specification for (int i = compSpec.Length - 1; i >= 0; i--) if (compSpec[i]) { setCompDef(i, word); } } else { // Tile-component specification for (int i = tileSpec.Length - 1; i >= 0; i--) { for (int j = compSpec.Length - 1; j >= 0; j--) { if (tileSpec[i] && compSpec[j]) { setTileCompVal(i, j, word); } } } } // Re-initialize curSpecValType = SPEC_DEF; tileSpec = null; compSpec = null; break; default: throw new System.ArgumentException("Unknown parameter for " + "'-Qtype' option: " + word); } } // Check that default value has been specified if (getDefault() == null) { int ndefspec = 0; for (int t = nt - 1; t >= 0; t--) { for (int c = nc - 1; c >= 0; c--) { if (specValType[t][c] == SPEC_DEF) { ndefspec++; } } } // If some tile-component have received no specification, the // quantization type is 'reversible' (if '-lossless' is specified) // or 'expounded' (if not). if (ndefspec != 0) { if (pl.getBooleanParameter("lossless")) { setDefault("reversible"); } else { setDefault("expounded"); } } else { // All tile-component have been specified, takes arbitrarily // the first tile-component value as default and modifies the // specification type of all tile-component sharing this // value. setDefault(getTileCompVal(0, 0)); switch (specValType[0][0]) { case SPEC_TILE_DEF: for (int c = nc - 1; c >= 0; c--) { if (specValType[0][c] == SPEC_TILE_DEF) specValType[0][c] = SPEC_DEF; } tileDef[0] = null; break; case SPEC_COMP_DEF: for (int t = nt - 1; t >= 0; t--) { if (specValType[t][0] == SPEC_COMP_DEF) specValType[t][0] = SPEC_DEF; } compDef[0] = null; break; case SPEC_TILE_COMP: specValType[0][0] = SPEC_DEF; tileCompVal["t0c0"] = null; break; } } } }
/// <summary> Initializes the header writer with the references to the coding chain. /// /// </summary> /// <param name="origsrc">The original image data (before any component mixing, /// tiling, etc.) /// /// </param> /// <param name="isorigsig">An array specifying for each component if it was /// originally signed or not. /// /// </param> /// <param name="dwt">The discrete wavelet transform module. /// /// </param> /// <param name="tiler">The tiler module. /// /// </param> /// <param name="encSpec">The encoder specifications /// /// </param> /// <param name="roiSc">The ROI scaler module. /// /// </param> /// <param name="ralloc">The post compression rate allocator. /// /// </param> /// <param name="pl">ParameterList instance. /// /// </param> public HeaderEncoder(ImgData origsrc, bool[] isorigsig, ForwardWT dwt, Tiler tiler, EncoderSpecs encSpec, ROIScaler roiSc, PostCompRateAllocator ralloc, ParameterList pl) { pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo)); if (origsrc.NumComps != isorigsig.Length) { throw new System.ArgumentException(); } this.origSrc = origsrc; this.isOrigSig = isorigsig; this.dwt = dwt; this.tiler = tiler; this.encSpec = encSpec; this.roiSc = roiSc; this.ralloc = ralloc; baos = new System.IO.MemoryStream(); //UPGRADE_TODO: Class 'java.io.DataOutputStream' was converted to 'System.IO.BinaryWriter' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataOutputStream'" hbuf = new CSJ2K.Util.EndianBinaryWriter(baos, true); nComp = origsrc.NumComps; enJJ2KMarkSeg = pl.getBooleanParameter("Hjj2000_COM"); otherCOMMarkSeg = pl.getParameter("HCOM"); }
/// <summary> Constructs a new 'ForwCompTransfSpec' for the specified number of /// components and tiles, the wavelet filters type and the parameter of the /// option 'Mct'. This constructor is called by the encoder. It also checks /// that the arguments belong to the recognized arguments list. /// /// <p>This constructor chose the component transformation type depending /// on the wavelet filters : RCT with w5x3 filter and ICT with w9x7 /// filter. Note: All filters must use the same data type.</p> /// /// </summary> /// <param name="nt">The number of tiles /// /// </param> /// <param name="nc">The number of components /// /// </param> /// <param name="type">the type of the specification module i.e. tile specific, /// component specific or both. /// /// </param> /// <param name="wfs">The wavelet filter specifications /// /// </param> /// <param name="pl">The ParameterList /// /// </param> public ForwCompTransfSpec(int nt, int nc, byte type, AnWTFilterSpec wfs, ParameterList pl):base(nt, nc, type) { System.String param = pl.getParameter("Mct"); if (param == null) { // The option has not been specified // If less than three component, do not use any component // transformation if (nc < 3) { setDefault("none"); return ; } // If the compression is lossless, uses RCT else if (pl.getBooleanParameter("lossless")) { setDefault("rct"); return ; } else { AnWTFilter[][] anfilt; int[] filtType = new int[nComp]; for (int c = 0; c < 3; c++) { anfilt = (AnWTFilter[][]) wfs.getCompDef(c); filtType[c] = anfilt[0][0].FilterType; } // Check that the three first components use the same filters bool reject = false; for (int c = 1; c < 3; c++) { if (filtType[c] != filtType[0]) reject = true; } if (reject) { setDefault("none"); } else { anfilt = (AnWTFilter[][]) wfs.getCompDef(0); if (anfilt[0][0].FilterType == CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7) { setDefault("ict"); } else { setDefault("rct"); } } } // Each tile receives a component transform specification // according the type of wavelet filters that are used by the // three first components for (int t = 0; t < nt; t++) { AnWTFilter[][] anfilt; int[] filtType = new int[nComp]; for (int c = 0; c < 3; c++) { anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, c); filtType[c] = anfilt[0][0].FilterType; } // Check that the three components use the same filters bool reject = false; for (int c = 1; c < nComp; c++) { if (filtType[c] != filtType[0]) reject = true; } if (reject) { setTileDef(t, "none"); } else { anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, 0); if (anfilt[0][0].FilterType == CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7) { setTileDef(t, "ict"); } else { setTileDef(t, "rct"); } } } return ; } // Parse argument SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param); System.String word; // current word byte curSpecType = SPEC_DEF; // Specification type of the // current parameter bool[] tileSpec = null; // Tiles concerned by the // specification //System.Boolean value_Renamed; while (stk.HasMoreTokens()) { word = stk.NextToken(); switch (word[0]) { case 't': // Tiles specification tileSpec = parseIdx(word, nTiles); if (curSpecType == SPEC_COMP_DEF) { curSpecType = SPEC_TILE_COMP; } else { curSpecType = SPEC_TILE_DEF; } break; case 'c': // Components specification throw new System.ArgumentException("Component specific " + " parameters" + " not allowed with " + "'-Mct' option"); default: if (word.Equals("off")) { if (curSpecType == SPEC_DEF) { setDefault("none"); } else if (curSpecType == SPEC_TILE_DEF) { for (int i = tileSpec.Length - 1; i >= 0; i--) if (tileSpec[i]) { setTileDef(i, "none"); } } } else if (word.Equals("on")) { if (nc < 3) { throw new System.ArgumentException("Cannot use component" + " transformation on a " + "image with less than " + "three components"); } if (curSpecType == SPEC_DEF) { // Set arbitrarily the default // value to RCT (later will be found the suitable // component transform for each tile) setDefault("rct"); } else if (curSpecType == SPEC_TILE_DEF) { for (int i = tileSpec.Length - 1; i >= 0; i--) { if (tileSpec[i]) { if (getFilterType(i, wfs) == CSJ2K.j2k.wavelet.FilterTypes_Fields.W5X3) { setTileDef(i, "rct"); } else { setTileDef(i, "ict"); } } } } } else { throw new System.ArgumentException("Default parameter of " + "option Mct not" + " recognized: " + param); } // Re-initialize curSpecType = SPEC_DEF; tileSpec = null; break; } } // Check that default value has been specified if (getDefault() == null) { // If not, set arbitrarily the default value to 'none' but // specifies explicitely a default value for each tile depending // on the wavelet transform that is used setDefault("none"); for (int t = 0; t < nt; t++) { if (isTileSpecified(t)) { continue; } AnWTFilter[][] anfilt; int[] filtType = new int[nComp]; for (int c = 0; c < 3; c++) { anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, c); filtType[c] = anfilt[0][0].FilterType; } // Check that the three components use the same filters bool reject = false; for (int c = 1; c < nComp; c++) { if (filtType[c] != filtType[0]) reject = true; } if (reject) { setTileDef(t, "none"); } else { anfilt = (AnWTFilter[][]) wfs.getTileCompVal(t, 0); if (anfilt[0][0].FilterType == CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7) { setTileDef(t, "ict"); } else { setTileDef(t, "rct"); } } } } // Check validity of component transformation of each tile compared to // the filter used. for (int t = nt - 1; t >= 0; t--) { if (((System.String) getTileDef(t)).Equals("none")) { // No comp. transf is used. No check is needed continue; } else if (((System.String) getTileDef(t)).Equals("rct")) { // Tile is using Reversible component transform int filterType = getFilterType(t, wfs); switch (filterType) { case CSJ2K.j2k.wavelet.FilterTypes_Fields.W5X3: // OK break; case CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7: // Must use ICT if (isTileSpecified(t)) { // User has requested RCT -> Error throw new System.ArgumentException("Cannot use RCT " + "with 9x7 filter " + "in tile " + t); } else { // Specify ICT for this tile setTileDef(t, "ict"); } break; default: throw new System.ArgumentException("Default filter is " + "not JPEG 2000 part" + " I compliant"); } } else { // ICT int filterType = getFilterType(t, wfs); switch (filterType) { case CSJ2K.j2k.wavelet.FilterTypes_Fields.W5X3: // Must use RCT if (isTileSpecified(t)) { // User has requested ICT -> Error throw new System.ArgumentException("Cannot use ICT " + "with filter 5x3 " + "in tile " + t); } else { setTileDef(t, "rct"); } break; case CSJ2K.j2k.wavelet.FilterTypes_Fields.W9X7: // OK break; default: throw new System.ArgumentException("Default filter is " + "not JPEG 2000 part" + " I compliant"); } } } }
/// <summary> Constructs a new ForwCompTransf object that operates on the /// specified source of image data. /// /// </summary> /// <param name="imgSrc">The source from where to get the data to be /// transformed /// /// </param> /// <param name="decSpec">The decoder specifications /// /// </param> /// <param name="utdepth">The bit depth of the un-transformed components /// /// </param> /// <param name="pl">The command line optinons of the decoder /// /// </param> /// <seealso cref="BlkImgDataSrc"> /// /// </seealso> public InvCompTransf(BlkImgDataSrc imgSrc, DecoderSpecs decSpec, int[] utdepth, ParameterList pl):base(imgSrc) { this.cts = decSpec.cts; this.wfs = decSpec.wfs; src = imgSrc; this.utdepth = utdepth; noCompTransf = !(pl.getBooleanParameter("comp_transf")); }
/// <summary> Creates and returns the entropy decoder corresponding to the /// information read from the codestream header and with the special /// additional parameters from the parameter list. /// /// </summary> /// <param name="src">The bit stream reader agent where to get code-block data /// from. /// /// </param> /// <param name="pl">The parameter list containing parameters applicable to the /// entropy decoder (other parameters can also be present). /// /// </param> /// <returns> The entropy decoder /// /// </returns> public virtual EntropyDecoder createEntropyDecoder(CodedCBlkDataSrcDec src, ParameterList pl) { bool doer; bool verber; int mMax; // Check parameters pl.checkList(EntropyDecoder.OPT_PREFIX, ParameterList.toNameArray(EntropyDecoder.ParameterInfo)); // Get error detection option doer = pl.getBooleanParameter("Cer"); // Get verbose error detection option verber = pl.getBooleanParameter("Cverber"); // Get maximum number of bit planes from m quit condition mMax = pl.getIntParameter("m_quit"); return new StdEntropyDecoder(src, decSpec, doer, verber, mMax); }
/// <summary> Creates a ROIScaler object. The Quantizer is the source of data to /// scale. /// /// <p>The ROI Scaler creates a ROIMaskGenerator depending on what ROI /// information is in the ParameterList. If only rectangular ROI are used, /// the fast mask generator for rectangular ROI can be used.</p> /// /// </summary> /// <param name="src">The source of data to scale /// /// </param> /// <param name="pl">The parameter list (or options). /// /// </param> /// <param name="encSpec">The encoder specifications for addition of roi specs /// /// </param> /// <exception cref="IllegalArgumentException">If an error occurs while parsing /// the options in 'pl' /// /// </exception> public static ROIScaler createInstance(Quantizer src, ParameterList pl, EncoderSpecs encSpec) { System.Collections.ArrayList roiVector = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); ROIMaskGenerator maskGen = null; // Check parameters pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo)); // Get parameters and check if there are and ROIs specified System.String roiopt = pl.getParameter("Rroi"); if (roiopt == null) { // No ROIs specified! Create ROIScaler with no mask generator return new ROIScaler(src, null, false, - 1, false, encSpec); } // Check if the lowest resolution levels should belong to the ROI int sLev = pl.getIntParameter("Rstart_level"); // Check if the ROIs are block-aligned bool useBlockAligned = pl.getBooleanParameter("Ralign"); // Check if generic mask generation is specified bool onlyRect = !pl.getBooleanParameter("Rno_rect"); // Parse the ROIs parseROIs(roiopt, src.NumComps, roiVector); ROI[] roiArray = new ROI[roiVector.Count]; roiVector.CopyTo(roiArray); // If onlyRect has been forced, check if there are any non-rectangular // ROIs specified. Currently, only the presence of circular ROIs will // make this false if (onlyRect) { for (int i = roiArray.Length - 1; i >= 0; i--) if (!roiArray[i].rect) { onlyRect = false; break; } } if (onlyRect) { // It's possible to use the fast ROI mask generation when only // rectangular ROIs are specified. maskGen = new RectROIMaskGenerator(roiArray, src.NumComps); } else { // It's necessary to use the generic mask generation maskGen = new ArbROIMaskGenerator(roiArray, src.NumComps, src); } return new ROIScaler(src, maskGen, true, sLev, useBlockAligned, encSpec); }