Beispiel #1
0
		/// <summary> This method extracts a marker segment in a tile-part header and stores
		/// it into a byte buffer for the second pass. The marker is first
		/// recognized, then its flag is activated and, finally, its content is
		/// buffered in an element of byte arrays accessible thanks to a hashTable.
		/// If a marker segment is not recognized, it prints a warning and skip it
		/// according to its length.
		/// 
		/// </summary>
		/// <param name="marker">The marker to process
		/// 
		/// </param>
		/// <param name="ehs">The encoded header stream
		/// 
		/// </param>
		/// <param name="tileIdx">The index of the current tile
		/// 
		/// </param>
		/// <param name="tilePartIdx">The index of the current tile part
		/// 
		/// </param>
		public virtual void  extractTilePartMarkSeg(short marker, RandomAccessIO ehs, int tileIdx, int tilePartIdx)
		{
			
			System.String htKey = ""; // Name used as a hash-table key
			if (ht == null)
			{
				ht = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
			}
			
			switch (marker)
			{
				
				case CSJ2K.j2k.codestream.Markers.SOT: 
					throw new CorruptedCodestreamException("Second SOT marker " + "segment found in tile-" + "part header");
				
				case CSJ2K.j2k.codestream.Markers.SIZ: 
					throw new CorruptedCodestreamException("SIZ found in tile-part" + " header");
				
				case CSJ2K.j2k.codestream.Markers.EOC: 
					throw new CorruptedCodestreamException("EOC found in tile-part" + " header");
				
				case CSJ2K.j2k.codestream.Markers.TLM: 
					throw new CorruptedCodestreamException("TLM found in tile-part" + " header");
				
				case CSJ2K.j2k.codestream.Markers.PLM: 
					throw new CorruptedCodestreamException("PLM found in tile-part" + " header");
				
				case CSJ2K.j2k.codestream.Markers.PPM: 
					throw new CorruptedCodestreamException("PPM found in tile-part" + " header");
				
				case CSJ2K.j2k.codestream.Markers.COD: 
					if ((nfMarkSeg & COD_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one COD " + "marker " + "found in tile-part" + " header");
					}
					nfMarkSeg |= COD_FOUND;
					htKey = "COD";
					break;
				
				case CSJ2K.j2k.codestream.Markers.COC: 
					nfMarkSeg |= COC_FOUND;
					htKey = "COC" + (nCOCMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.QCD: 
					if ((nfMarkSeg & QCD_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one QCD " + "marker " + "found in tile-part" + " header");
					}
					nfMarkSeg |= QCD_FOUND;
					htKey = "QCD";
					break;
				
				case CSJ2K.j2k.codestream.Markers.QCC: 
					nfMarkSeg |= QCC_FOUND;
					htKey = "QCC" + (nQCCMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.RGN: 
					nfMarkSeg |= RGN_FOUND;
					htKey = "RGN" + (nRGNMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.COM: 
					nfMarkSeg |= COM_FOUND;
					htKey = "COM" + (nCOMMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.CRG: 
					throw new CorruptedCodestreamException("CRG marker found in " + "tile-part header");
				
				case CSJ2K.j2k.codestream.Markers.PPT: 
					nfMarkSeg |= PPT_FOUND;
					if (nPPTMarkSeg == null)
					{
						nPPTMarkSeg = new int[nTiles][];
					}
					if (nPPTMarkSeg[tileIdx] == null)
					{
						nPPTMarkSeg[tileIdx] = new int[nTileParts[tileIdx]];
					}
					htKey = "PPT" + (nPPTMarkSeg[tileIdx][tilePartIdx]++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.SOD: 
					nfMarkSeg |= SOD_FOUND;
					return ;
				
				case CSJ2K.j2k.codestream.Markers.POC: 
					if ((nfMarkSeg & POC_FOUND) != 0)
						throw new CorruptedCodestreamException("More than one POC " + "marker segment found " + "in tile-part" + " header");
					nfMarkSeg |= POC_FOUND;
					htKey = "POC";
					break;
				
				case CSJ2K.j2k.codestream.Markers.PLT: 
					if ((nfMarkSeg & PLM_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("PLT marker found even" + "though PLM marker " + "found in main header");
					}
					FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "PLT marker segment found but " + "not used by JJ2000 decoder.");
					htKey = "UNKNOWN";
					break;
				
				default: 
					htKey = "UNKNOWN";
					FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Non recognized marker segment (0x" + System.Convert.ToString(marker, 16) + ") in tile-part header" + " of tile " + tileIdx + " !");
					break;
				
			}
			
			// Read marker segment length and create corresponding byte buffer
			int markSegLen = ehs.readUnsignedShort();
			byte[] buf = new byte[markSegLen];
			
			// Copy data (after re-insertion of marker segment length);
			buf[0] = (byte) ((markSegLen >> 8) & 0xFF);
			buf[1] = (byte) (markSegLen & 0xFF);
			ehs.readFully(buf, 2, markSegLen - 2);
			
			if (!htKey.Equals("UNKNOWN"))
			{
				// Store array in hashTable
				ht[htKey] = buf;
			}
		}
Beispiel #2
0
		/// <summary> This method extract a marker segment from the main header and stores it
		/// into a byte buffer for the second pass. The marker segment is first
		/// identified. Then its flag is activated. Finally, its content is
		/// buffered into a byte array stored in an hashTable.
		/// 
		/// <p>If the marker is not recognized, it prints a warning and skips it
		/// according to its length.</p>
		/// 
		/// <p>SIZ marker segment shall be the first encountered marker segment.</p>
		/// 
		/// </summary>
		/// <param name="marker">The marker segment to process
		/// 
		/// </param>
		/// <param name="ehs">The encoded header stream
		/// 
		/// </param>
		private void  extractMainMarkSeg(short marker, RandomAccessIO ehs)
		{
			if (nfMarkSeg == 0)
			{
				// First non-delimiting marker of the header
				// JPEG 2000 part 1 specify that it must be SIZ
				if (marker != CSJ2K.j2k.codestream.Markers.SIZ)
				{
					throw new CorruptedCodestreamException("First marker after " + "SOC " + "must be SIZ " + System.Convert.ToString(marker, 16));
				}
			}
			
			System.String htKey = ""; // Name used as a key for the hash-table
			if (ht == null)
			{
				ht = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
			}
			
			switch (marker)
			{
				
				case CSJ2K.j2k.codestream.Markers.SIZ: 
					if ((nfMarkSeg & SIZ_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one SIZ marker " + "segment found in main " + "header");
					}
					nfMarkSeg |= SIZ_FOUND;
					htKey = "SIZ";
					break;
				
				case CSJ2K.j2k.codestream.Markers.SOD: 
					throw new CorruptedCodestreamException("SOD found in main header");
				
				case CSJ2K.j2k.codestream.Markers.EOC: 
					throw new CorruptedCodestreamException("EOC found in main header");
				
				case CSJ2K.j2k.codestream.Markers.SOT: 
					if ((nfMarkSeg & SOT_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one SOT " + "marker " + "found right after " + "main " + "or tile header");
					}
					nfMarkSeg |= SOT_FOUND;
					return ;
				
				case CSJ2K.j2k.codestream.Markers.COD: 
					if ((nfMarkSeg & COD_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one COD " + "marker " + "found in main header");
					}
					nfMarkSeg |= COD_FOUND;
					htKey = "COD";
					break;
				
				case CSJ2K.j2k.codestream.Markers.COC: 
					nfMarkSeg |= COC_FOUND;
					htKey = "COC" + (nCOCMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.QCD: 
					if ((nfMarkSeg & QCD_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one QCD " + "marker " + "found in main header");
					}
					nfMarkSeg |= QCD_FOUND;
					htKey = "QCD";
					break;
				
				case CSJ2K.j2k.codestream.Markers.QCC: 
					nfMarkSeg |= QCC_FOUND;
					htKey = "QCC" + (nQCCMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.RGN: 
					nfMarkSeg |= RGN_FOUND;
					htKey = "RGN" + (nRGNMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.COM: 
					nfMarkSeg |= COM_FOUND;
					htKey = "COM" + (nCOMMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.CRG: 
					if ((nfMarkSeg & CRG_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one CRG " + "marker " + "found in main header");
					}
					nfMarkSeg |= CRG_FOUND;
					htKey = "CRG";
					break;
				
				case CSJ2K.j2k.codestream.Markers.PPM: 
					nfMarkSeg |= PPM_FOUND;
					htKey = "PPM" + (nPPMMarkSeg++);
					break;
				
				case CSJ2K.j2k.codestream.Markers.TLM: 
					if ((nfMarkSeg & TLM_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one TLM " + "marker " + "found in main header");
					}
					nfMarkSeg |= TLM_FOUND;
					break;
				
				case CSJ2K.j2k.codestream.Markers.PLM: 
					if ((nfMarkSeg & PLM_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one PLM " + "marker " + "found in main header");
					}
					FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "PLM marker segment found but " + "not used by by JJ2000 decoder.");
					nfMarkSeg |= PLM_FOUND;
					htKey = "PLM";
					break;
				
				case CSJ2K.j2k.codestream.Markers.POC: 
					if ((nfMarkSeg & POC_FOUND) != 0)
					{
						throw new CorruptedCodestreamException("More than one POC " + "marker segment found " + "in main header");
					}
					nfMarkSeg |= POC_FOUND;
					htKey = "POC";
					break;
				
				case CSJ2K.j2k.codestream.Markers.PLT: 
					throw new CorruptedCodestreamException("PLT found in main header");
				
				case CSJ2K.j2k.codestream.Markers.PPT: 
					throw new CorruptedCodestreamException("PPT found in main header");
				
				default: 
					htKey = "UNKNOWN";
					FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Non recognized marker segment (0x" + System.Convert.ToString(marker, 16) + ") in main header!");
					break;
				
			}
			
			if (marker < unchecked((short)0xffffff30) || marker > unchecked((short)0xffffff3f))
			{
				// Read marker segment length and create corresponding byte buffer
				int markSegLen = ehs.readUnsignedShort();
				byte[] buf = new byte[markSegLen];
				
				// Copy data (after re-insertion of the marker segment length);
				buf[0] = (byte) ((markSegLen >> 8) & 0xFF);
				buf[1] = (byte) (markSegLen & 0xFF);
				ehs.readFully(buf, 2, markSegLen - 2);
				
				if (!htKey.Equals("UNKNOWN"))
				{
					// Store array in hashTable
					ht[htKey] = buf;
				}
			}
		}