Esempio n. 1
0
        /// <summary>
        /// <para>Returns, in the blk argument, a block of image data containing the
        /// specifed rectangular area, in the specified component. The data is
        /// returned, as a copy of the internal data, therefore the returned data
        /// can be modified "in place".</para>
        ///
        /// <para>The rectangular area to return is specified by the 'ulx', 'uly', 'w'
        /// and 'h' members of the 'blk' argument, relative to the current
        /// tile. These members are not modified by this method. The 'offset' of
        /// the returned data is 0, and the 'scanw' is the same as the block's
        /// width. See the 'DataBlk' class.</para>
        ///
        /// <para>If the data array in 'blk' is 'null', then a new one is created. If
        /// the data array is not 'null' then it is reused, and it must be large
        /// enough to contain the block's data. Otherwise an 'ArrayStoreException'
        /// or an 'IndexOutOfBoundsException' is thrown by the Java system.</para>
        ///
        /// <para>The returned data has its 'progressive' attribute set to that of the
        /// input data.</para>
        ///
        /// </summary>
        /// <param name="blk">Its coordinates and dimensions specify the area to
        /// return. If it contains a non-null data array, then it must have the
        /// correct dimensions. If it contains a null data array a new one is
        /// created. The fields in this object are modified to return the data.
        ///
        /// </param>
        /// <param name="c">The index of the component from which to get the data. Only 0
        /// and 3 are valid.
        ///
        /// </param>
        /// <returns> The requested DataBlk
        /// </returns>
        /// <seealso cref="getInternCompData">
        ///
        /// </seealso>
        public override DataBlk getCompData(DataBlk outblk, int c)
        {
            int    type   = outblk.DataType;
            double colors = Math.Pow(2, src.getNomRangeBits(c));
            double bitoff = colors * 0.375D;

            if (type == DataBlk.TYPE_INT)
            {
                DataBlkInt intblk = (DataBlkInt)src.getInternCompData(outblk, c);

                for (int i = 0; i < intblk.data_array.Length; i++)
                {
                    int tmp = intblk.data_array[i];

                    tmp += (int)(colors / 2);
                    tmp -= (int)bitoff;
                    tmp *= 2;
                    tmp -= (int)(colors / 2);

                    intblk.data_array[i] = tmp;
                }
                outblk = intblk;
            }
            else if (type == DataBlk.TYPE_FLOAT)
            {
                FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Unsupported e-sRGB DataType (float)");

                DataBlkFloat fltblk = (DataBlkFloat)src.getInternCompData(outblk, c);
                outblk = fltblk;
            }
            return(outblk);
        }
        private static void  standardizeMatrixLineThroughLut(DataBlkFloat inb, float[] out_Renamed, float dwInputMaxValue, LookUpTableFP lut)
        {
            int   j = 0;
            float wTemp;

            float[] in_Renamed = (float[])inb.Data;              // input pixel reference
            float[] lutFP      = lut.lut;

            for (int y = inb.uly; y < inb.uly + inb.h; ++y)
            {
                for (int x = inb.ulx; x < inb.ulx + inb.w; ++x)
                {
                    int i = inb.offset + (y - inb.uly) * inb.scanw + (x - inb.ulx);                     // pixel index.
                    if (in_Renamed[i] > dwInputMaxValue)
                    {
                        wTemp = dwInputMaxValue;
                    }
                    else if (in_Renamed[i] < 0)
                    {
                        wTemp = 0;
                    }
                    else
                    {
                        wTemp = in_Renamed[i];
                    }
                    //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'"
                    out_Renamed[j++] = lutFP[(int)wTemp];
                }
            }
        }
Esempio n. 3
0
        /// <summary> Output a DataBlkFloat array where each sample in each component
        /// is the product of the YCC matrix * the vector of samples across
        /// the input components.
        /// </summary>
        /// <param name="inblk">input DataBlkFloat array
        /// </param>
        /// <returns> output DataBlkFloat array
        /// </returns>
        private static DataBlkFloat[] mult(DataBlkFloat[] inblk)
        {
            if (inblk.Length != 3)
            {
                throw new System.ArgumentException("bad input array size");
            }

            int i, j;
            int length = inblk[0].h * inblk[0].w;

            DataBlkFloat[] outblk      = new DataBlkFloat[3];
            float[][]      out_Renamed = new float[3][];
            float[][]      in_Renamed  = new float[3][];

            for (i = 0; i < 3; ++i)
            {
                in_Renamed[i] = inblk[i].DataFloat;
                outblk[i]     = new DataBlkFloat();
                copyGeometry(outblk[i], inblk[i]);
                outblk[i].offset = inblk[i].offset;
                out_Renamed[i]   = new float[length];
                outblk[i].Data   = out_Renamed[i];
            }

            for (j = 0; j < length; ++j)
            {
                out_Renamed[0][j] = (Matrix00 * in_Renamed[0][inblk[0].offset + j] + Matrix01 * in_Renamed[1][inblk[1].offset + j] + Matrix02 * in_Renamed[2][inblk[2].offset + j]);

                out_Renamed[1][j] = (Matrix10 * in_Renamed[0][inblk[0].offset + j] + Matrix11 * in_Renamed[1][inblk[1].offset + j] + Matrix12 * in_Renamed[2][inblk[2].offset + j]);

                out_Renamed[2][j] = (Matrix20 * in_Renamed[0][inblk[0].offset + j] + Matrix21 * in_Renamed[1][inblk[1].offset + j] + Matrix22 * in_Renamed[2][inblk[2].offset + j]);
            }

            return(outblk);
        }
        /// <summary> Populate the output block by looking up the values in the lut, using the input
        /// as lut indices.
        /// </summary>
        /// <param name="inb">input samples
        /// </param>
        /// <param name="outb">output samples.
        /// </param>
        /// <exception cref="MonochromeTransformException">
        /// </exception>
        public virtual void  apply(DataBlkFloat inb, DataBlkFloat outb)
        {
            int i, j, o; // x, y removed

            float[] in_Renamed  = (float[])inb.Data;
            float[] out_Renamed = (float[])outb.Data;


            if (out_Renamed == null || out_Renamed.Length < in_Renamed.Length)
            {
                out_Renamed = new float[in_Renamed.Length];
                outb.Data   = out_Renamed;

                outb.uly    = inb.uly;
                outb.ulx    = inb.ulx;
                outb.h      = inb.h;
                outb.w      = inb.w;
                outb.offset = inb.offset;
                outb.scanw  = inb.scanw;
            }

            o = inb.offset;
            for (i = 0; i < inb.h * inb.w; ++i)
            {
                //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'"
                j = (int)in_Renamed[i];
                if (j < 0)
                {
                    j = 0;
                }
                else if (j > dwInputMaxValue)
                {
                    j = dwInputMaxValue;
                }
                out_Renamed[i] = lut[j];
            }
        }
Esempio n. 5
0
		/// <summary> Output a DataBlkFloat array where each sample in each component
		/// is the product of the YCC matrix * the vector of samples across 
		/// the input components.
		/// </summary>
		/// <param name="inblk">input DataBlkFloat array
		/// </param>
		/// <returns> output DataBlkFloat array
		/// </returns>
		private static DataBlkFloat[] mult(DataBlkFloat[] inblk)
		{
			
			if (inblk.Length != 3)
				throw new System.ArgumentException("bad input array size");
			
			int i, j;
			int length = inblk[0].h * inblk[0].w;
			DataBlkFloat[] outblk = new DataBlkFloat[3];
			float[][] out_Renamed = new float[3][];
			float[][] in_Renamed = new float[3][];
			
			for (i = 0; i < 3; ++i)
			{
				in_Renamed[i] = inblk[i].DataFloat;
				outblk[i] = new DataBlkFloat();
				copyGeometry(outblk[i], inblk[i]);
				outblk[i].offset = inblk[i].offset;
				out_Renamed[i] = new float[length];
				outblk[i].Data = out_Renamed[i];
			}
			
			for (j = 0; j < length; ++j)
			{
				out_Renamed[0][j] = (Matrix00 * in_Renamed[0][inblk[0].offset + j] + Matrix01 * in_Renamed[1][inblk[1].offset + j] + Matrix02 * in_Renamed[2][inblk[2].offset + j]);
				
				out_Renamed[1][j] = (Matrix10 * in_Renamed[0][inblk[0].offset + j] + Matrix11 * in_Renamed[1][inblk[1].offset + j] + Matrix12 * in_Renamed[2][inblk[2].offset + j]);
				
				out_Renamed[2][j] = (Matrix20 * in_Renamed[0][inblk[0].offset + j] + Matrix21 * in_Renamed[1][inblk[1].offset + j] + Matrix22 * in_Renamed[2][inblk[2].offset + j]);
			}
			
			return outblk;
		}
		private static void  standardizeMatrixLineThroughLut(DataBlkFloat inb, float[] out_Renamed, float dwInputMaxValue, LookUpTableFP lut)
		{
			int j = 0;
			float wTemp;
			float[] in_Renamed = (float[]) inb.Data; // input pixel reference
			float[] lutFP = lut.lut;
			
			for (int y = inb.uly; y < inb.uly + inb.h; ++y)
			{
				for (int x = inb.ulx; x < inb.ulx + inb.w; ++x)
				{
					int i = inb.offset + (y - inb.uly) * inb.scanw + (x - inb.ulx); // pixel index.
					if (in_Renamed[i] > dwInputMaxValue)
						wTemp = dwInputMaxValue;
					else if (in_Renamed[i] < 0)
						wTemp = 0;
					else
						wTemp = in_Renamed[i];
					//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'"
					out_Renamed[j++] = lutFP[(int) wTemp];
				}
			}
		}
		/// <summary> Performs the transform.  Pass the input throught the LookUpTableFP, apply the
		/// matrix to the output and finally pass the intermediate buffer through the
		/// LookUpTable8.  This operation is designated (LFP*M*L8) * Data are already 
		/// constructed.  Although the data for only one component is returned, the
		/// transformation must be done for all components, because the matrix application
		/// involves a linear combination of component input to produce the output.
		/// </summary>
		/// <param name="ncols">number of columns in the input
		/// </param>
		/// <param name="nrows">number of rows in the input
		/// </param>
		/// <param name="inb">input data block
		/// </param>
		/// <param name="outb">output data block
		/// </param>
		/// <exception cref="MatrixBasedTransformException">
		/// </exception>
		public virtual void  apply(DataBlkFloat[] inb, DataBlkFloat[] outb)
		{
			
			float[][] in_Renamed = new float[3][], out_Renamed = new float[3][]; // data references.
			
			int nrows = inb[0].h, ncols = inb[0].w;
			
			if ((fBuf == null) || (fBuf[0].Length < ncols * nrows))
			{
				float[][] tmpArray = new float[3][];
				for (int i = 0; i < 3; i++)
				{
					tmpArray[i] = new float[ncols * nrows];
				}
				fBuf = tmpArray;
			}
			
			// for each component (rgb)
			for (int c = 0; c < 3; ++c)
			{
				
				// Reference the input and output pixels.
				in_Renamed[c] = (float[]) inb[c].Data;
				out_Renamed[c] = (float[]) outb[c].Data;
				
				// Assure a properly sized output buffer.
				if (out_Renamed[c] == null || out_Renamed[c].Length < in_Renamed[c].Length)
				{
					out_Renamed[c] = new float[in_Renamed[c].Length];
					outb[c].Data = out_Renamed[c];
				}
				
				// The first thing to do is to process the input into a standard form
				// and through the first input LUT, producing floating point output values
				standardizeMatrixLineThroughLut(inb[c], fBuf[c], dwMaxValue[c], fLut[c]);
			}
			
			int[] lut32 = lut.lut;
			
			// For each row and column 
			int index = 0, val;
			for (int y = 0; y < inb[0].h; ++y)
			{
				int end = index + inb[0].w;
				while (index < end)
				{
					// Calculate the rgb pixel indices for this row / column
					
					// Apply the matrix to the intermediate floating point data inorder to index the 
					// final LUT.
					//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'"
					val = (int) (matrix[M00] * fBuf[RED][index] + matrix[M01] * fBuf[GREEN][index] + matrix[M02] * fBuf[BLUE][index] + 0.5);
					// Clip the calculated value if necessary..
					if (val < 0)
						out_Renamed[0][index] = lut32[0];
					else if (val >= lut32.Length)
						out_Renamed[0][index] = lut32[lut32.Length - 1];
					else
						out_Renamed[0][index] = lut32[val];
					
					//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'"
					val = (int) (matrix[M10] * fBuf[RED][index] + matrix[M11] * fBuf[GREEN][index] + matrix[M12] * fBuf[BLUE][index] + 0.5);
					// Clip the calculated value if necessary..
					if (val < 0)
						out_Renamed[1][index] = lut32[0];
					else if (val >= lut32.Length)
						out_Renamed[1][index] = lut32[lut32.Length - 1];
					else
						out_Renamed[1][index] = lut32[val];
					
					//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'"
					val = (int) (matrix[M20] * fBuf[RED][index] + matrix[M21] * fBuf[GREEN][index] + matrix[M22] * fBuf[BLUE][index] + 0.5);
					// Clip the calculated value if necessary..
					if (val < 0)
						out_Renamed[2][index] = lut32[0];
					else if (val >= lut32.Length)
						out_Renamed[2][index] = lut32[lut32.Length - 1];
					else
						out_Renamed[2][index] = lut32[val];
					
					index++;
				}
			}
		}
		/// <summary> Populate the output block by looking up the values in the lut, using the input
		/// as lut indices.
		/// </summary>
		/// <param name="inb">input samples
		/// </param>
		/// <param name="outb">output samples.
		/// </param>
		/// <exception cref="MonochromeTransformException">
		/// </exception>
		public virtual void  apply(DataBlkFloat inb, DataBlkFloat outb)
		{

            int i, j, o; // x, y removed
			
			float[] in_Renamed = (float[]) inb.Data;
			float[] out_Renamed = (float[]) outb.Data;
			
			
			if (out_Renamed == null || out_Renamed.Length < in_Renamed.Length)
			{
				out_Renamed = new float[in_Renamed.Length];
				outb.Data = out_Renamed;
				
				outb.uly = inb.uly;
				outb.ulx = inb.ulx;
				outb.h = inb.h;
				outb.w = inb.w;
				outb.offset = inb.offset;
				outb.scanw = inb.scanw;
			}
			
			o = inb.offset;
			for (i = 0; i < inb.h * inb.w; ++i)
			{
				//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'"
				j = (int) in_Renamed[i];
				if (j < 0)
					j = 0;
				else if (j > dwInputMaxValue)
					j = dwInputMaxValue;
				out_Renamed[i] = lut[j];
			}
		}