CSJ2K.j2k.image.invcomptransf.InvCompTransf.invICT C# (CSharp) Метод

invICT() приватный Метод

Apply inverse irreversible component transformation to obtain requested component from specified block of data. Whatever the type of requested DataBlk, it always returns a DataBlkFloat.
private invICT ( CSJ2K.j2k.image.DataBlk blk, int c ) : CSJ2K.j2k.image.DataBlk
blk CSJ2K.j2k.image.DataBlk Determine the rectangular area to return /// ///
c int The index of the requested component /// ///
Результат CSJ2K.j2k.image.DataBlk
        private DataBlk invICT(DataBlk blk, int c)
        {
            if (c >= 3 && c < NumComps)
            {
                // Requesting a component whose index is greater than 3
                int k, k0, mink, i; //  k1, k2 removed
                int w = blk.w; //width of output block
                int h = blk.h; //height of ouput block

                int[] out_data; // array of output data

                //Reference to output block data array
                out_data = (int[])blk.Data;

                //Create data array of blk if necessary
                if (out_data == null)
                {
                    out_data = new int[h * w];
                    blk.Data = out_data;
                }

                // Variables
                DataBlkFloat indb = new DataBlkFloat(blk.ulx, blk.uly, w, h);
                float[] indata; // input data array

                // Get the input data
                // (returned block may be larger than requested one)
                src.getInternCompData(indb, c);
                indata = (float[])indb.Data;

                // Copy the data converting from int to int
                k = w * h - 1;
                k0 = indb.offset + (h - 1) * indb.scanw + w - 1;
                for (i = h - 1; i >= 0; i--)
                {
                    for (mink = k - w; k > mink; k--, k0--)
                    {
                        //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_data[k] = (int)(indata[k0]);
                    }
                    // Jump to beggining of previous line in input
                    k0 -= (indb.scanw - w);
                }

                // Set the progressivity and offset
                blk.progressive = indb.progressive;
                blk.offset = 0;
                blk.scanw = w;
            }
            // If asking a component for the first time for this block,
            // do transform for the 3 components
            else if ((outdata[c] == null) || (dbi.ulx > blk.ulx) || (dbi.uly > blk.uly)
                     || (dbi.ulx + dbi.w < blk.ulx + blk.w) || (dbi.uly + dbi.h < blk.uly + blk.h))
            {
                int k, k0, k1, k2, mink, i;
                int w = blk.w; //width of output block
                int h = blk.h; //height of ouput block

                //Reference to output block data array
                outdata[c] = (int[])blk.Data;

                //Create data array of blk if necessary
                if (outdata[c] == null || outdata[c].Length != w * h)
                {
                    outdata[c] = new int[h * w];
                    blk.Data = outdata[c];
                }

                outdata[(c + 1) % 3] = new int[outdata[c].Length];
                outdata[(c + 2) % 3] = new int[outdata[c].Length];

                if (block0 == null || block0.DataType != DataBlk.TYPE_FLOAT) block0 = new DataBlkFloat();
                if (block2 == null || block2.DataType != DataBlk.TYPE_FLOAT) block2 = new DataBlkFloat();
                if (block1 == null || block1.DataType != DataBlk.TYPE_FLOAT) block1 = new DataBlkFloat();
                block0.w = block2.w = block1.w = blk.w;
                block0.h = block2.h = block1.h = blk.h;
                block0.ulx = block2.ulx = block1.ulx = blk.ulx;
                block0.uly = block2.uly = block1.uly = blk.uly;

                float[] data0, data1, data2; // input data arrays

                // Fill in buffer blocks (to be read only)
                // Returned blocks may have different size and position
                block0 = (DataBlkFloat)src.getInternCompData(block0, 0);
                data0 = (float[])block0.Data;
                block2 = (DataBlkFloat)src.getInternCompData(block2, 1);
                data2 = (float[])block2.Data;
                block1 = (DataBlkFloat)src.getInternCompData(block1, 2);
                data1 = (float[])block1.Data;

                // Set the progressiveness of the output data
                blk.progressive = block0.progressive || block1.progressive || block2.progressive;
                blk.offset = 0;
                blk.scanw = w;

                // set attributes of the DataBlk used for buffering
                dbi.progressive = blk.progressive;
                dbi.ulx = blk.ulx;
                dbi.uly = blk.uly;
                dbi.w = blk.w;
                dbi.h = blk.h;

                //Perform conversion

                // Initialize general indexes
                k = w * h - 1;
                k0 = block0.offset + (h - 1) * block0.scanw + w - 1;
                k2 = block2.offset + (h - 1) * block2.scanw + w - 1;
                k1 = block1.offset + (h - 1) * block1.scanw + w - 1;

                for (i = h - 1; i >= 0; i--)
                {
                    for (mink = k - w; k > mink; k--, k0--, k2--, k1--)
                    {
                        //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'"
                        outdata[0][k] = (int)(data0[k0] + 1.402f * data1[k1] + 0.5f);
                        //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'"
                        outdata[1][k] = (int)(data0[k0] - 0.34413f * data2[k2] - 0.71414f * data1[k1] + 0.5f);
                        //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'"
                        outdata[2][k] = (int)(data0[k0] + 1.772f * data2[k2] + 0.5f);
                    }
                    // Jump to beggining of previous line in input
                    k0 -= (block0.scanw - w);
                    k2 -= (block2.scanw - w);
                    k1 -= (block1.scanw - w);
                }
                outdata[c] = null;
            }
            else if ((c >= 0) && (c <= 3))
            {
                //Asking for the 2nd or 3rd block component
                blk.Data = outdata[c];
                blk.progressive = dbi.progressive;
                blk.offset = (blk.uly - dbi.uly) * dbi.w + blk.ulx - dbi.ulx;
                blk.scanw = dbi.w;
                outdata[c] = null;
            }
            else
            {
                // Requesting a non valid component index
                throw new System.ArgumentException();
            }
            return blk;
        }