/// <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(DataBlkInt inb, DataBlkInt outb)
        {
            int i, j, o; //  x, y removed

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

            if (out_Renamed == null || out_Renamed.Length < in_Renamed.Length)
            {
                out_Renamed = new int[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)
            {
                j = in_Renamed[i];
                if (j < 0)
                {
                    j = 0;
                }
                else if (j > dwInputMaxValue)
                {
                    j = dwInputMaxValue;
                }
                out_Renamed[i] = lut[j];
            }
        }
Пример #2
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(DataBlkInt inb, float[] out_Renamed, int dwInputMaxValue, LookUpTableFP lut)
        {
            int wTemp, j = 0;

            int[]   in_Renamed = (int[])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];
                    }
                    out_Renamed[j++] = lutFP[wTemp];
                }
            }
        }
Пример #4
0
        /// <summary> Output a DataBlkInt 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 DataBlkInt array
        /// </param>
        /// <returns> output DataBlkInt array
        /// </returns>
        private static DataBlkInt[] mult(DataBlkInt[] inblk)
        {
            if (inblk.Length != 3)
            {
                throw new System.ArgumentException("bad input array size");
            }


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

            DataBlkInt[] outblk      = new DataBlkInt[3];
            int[][]      out_Renamed = new int[3][];
            int[][]      in_Renamed  = new int[3][];

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

            for (j = 0; j < length; ++j)
            {
                //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[0][j] = (int)(Matrix00 * in_Renamed[0][inblk[0].offset + j] + Matrix01 * in_Renamed[1][inblk[1].offset + j] + Matrix02 * in_Renamed[2][inblk[2].offset + j]);

                //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[1][j] = (int)(Matrix10 * in_Renamed[0][inblk[0].offset + j] + Matrix11 * in_Renamed[1][inblk[1].offset + j] + Matrix12 * in_Renamed[2][inblk[2].offset + j]);

                //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[2][j] = (int)(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);
        }
Пример #5
0
		/// <summary> Output a DataBlkInt 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 DataBlkInt array
		/// </param>
		/// <returns> output DataBlkInt array
		/// </returns>
		private static DataBlkInt[] mult(DataBlkInt[] inblk)
		{
			
			if (inblk.Length != 3)
				throw new System.ArgumentException("bad input array size");
			
			
			int i, j;
			int length = inblk[0].h * inblk[0].w;
			DataBlkInt[] outblk = new DataBlkInt[3];
			int[][] out_Renamed = new int[3][];
			int[][] in_Renamed = new int[3][];
			
			for (i = 0; i < 3; ++i)
			{
				in_Renamed[i] = inblk[i].DataInt;
				outblk[i] = new DataBlkInt();
				copyGeometry(outblk[i], inblk[i]);
				outblk[i].offset = inblk[i].offset;
				out_Renamed[i] = new int[length];
				outblk[i].Data = out_Renamed[i];
			}
			
			for (j = 0; j < length; ++j)
			{
				//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[0][j] = (int) (Matrix00 * in_Renamed[0][inblk[0].offset + j] + Matrix01 * in_Renamed[1][inblk[1].offset + j] + Matrix02 * in_Renamed[2][inblk[2].offset + j]);
				
				//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[1][j] = (int) (Matrix10 * in_Renamed[0][inblk[0].offset + j] + Matrix11 * in_Renamed[1][inblk[1].offset + j] + Matrix12 * in_Renamed[2][inblk[2].offset + j]);
				
				//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[2][j] = (int) (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(DataBlkInt inb, float[] out_Renamed, int dwInputMaxValue, LookUpTableFP lut)
		{
			int wTemp, j = 0;
			int[] in_Renamed = (int[]) 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];
					out_Renamed[j++] = lutFP[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(DataBlkInt[] inb, DataBlkInt[] outb)
		{
			int[][] in_Renamed = new int[3][], out_Renamed = new int[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 samples.
				in_Renamed[c] = (int[]) inb[c].Data;
				out_Renamed[c] = (int[]) 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 int[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]);
			}
			
			// For each row and column
			float[] ra = fBuf[RED];
			float[] ga = fBuf[GREEN];
			float[] ba = fBuf[BLUE];
			
			int[] ro = out_Renamed[RED];
			int[] go = out_Renamed[GREEN];
			int[] bo = out_Renamed[BLUE];
			int[] lut32 = lut.lut;
			
			double r, g, b;
			int val, index = 0;
			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
					r = ra[index];
					g = ga[index];
					b = ba[index];
					
					// Apply the matrix to the intermediate floating point data in order 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] * r + matrix[M01] * g + matrix[M02] * b + 0.5);
					// Clip the calculated value if necessary..
					if (val < 0)
						ro[index] = lut32[0];
					else if (val >= lut32.Length)
						ro[index] = lut32[lut32.Length - 1];
					else
						ro[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] * r + matrix[M11] * g + matrix[M12] * b + 0.5);
					// Clip the calculated value if necessary..
					if (val < 0)
						go[index] = lut32[0];
					else if (val >= lut32.Length)
						go[index] = lut32[lut32.Length - 1];
					else
						go[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] * r + matrix[M21] * g + matrix[M22] * b + 0.5);
					// Clip the calculated value if necessary..
					if (val < 0)
						bo[index] = lut32[0];
					else if (val >= lut32.Length)
						bo[index] = lut32[lut32.Length - 1];
					else
						bo[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(DataBlkInt inb, DataBlkInt outb)
		{

            int i, j, o; //  x, y removed
			
			int[] in_Renamed = (int[]) inb.Data;
			int[] out_Renamed = (int[]) outb.Data;
			
			if (out_Renamed == null || out_Renamed.Length < in_Renamed.Length)
			{
				out_Renamed = new int[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)
			{
				j = in_Renamed[i];
				if (j < 0)
					j = 0;
				else if (j > dwInputMaxValue)
					j = dwInputMaxValue;
				out_Renamed[i] = lut[j];
			}
		}