CSJ2K.j2k.image.ImgDataConverter.getData C# (CSharp) Метод

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

Implements the 'getInternCompData()' and the 'getCompData()' methods. The 'intern' flag signals which of the two methods should run as.
private getData ( CSJ2K.j2k.image.DataBlk blk, int c, bool intern ) : CSJ2K.j2k.image.DataBlk
blk CSJ2K.j2k.image.DataBlk The data block to get. /// ///
c int The index of the component from which to get the data. /// ///
intern bool If true behave as 'getInternCompData(). Otherwise behave /// as 'getCompData()' /// ///
Результат CSJ2K.j2k.image.DataBlk
        private DataBlk getData(DataBlk blk, int c, bool intern)
        {
            DataBlk reqBlk; // Reference to block used in request to source

            // Keep request data type
            int otype = blk.DataType;

            if (otype == srcBlk.DataType)
            {
                // Probably requested type is same as source type
                reqBlk = blk;
            }
            else
            {
                // Probably requested type is not the same as source type
                reqBlk = srcBlk;
                // We need to copy requested coordinates and size
                reqBlk.ulx = blk.ulx;
                reqBlk.uly = blk.uly;
                reqBlk.w = blk.w;
                reqBlk.h = blk.h;
            }

            // Get source data block
            if (intern)
            {
                // We can use the intern variant
                srcBlk = src.getInternCompData(reqBlk, c);
            }
            else
            {
                // Do not use the intern variant. Note that this is not optimal
                // since if we are going to convert below then we could have used
                // the intern variant. But there is currently no way to know if we
                // will need to do conversion or not before getting the data.
                srcBlk = src.getCompData(reqBlk, c);
            }

            // Check if casting is needed
            if (srcBlk.DataType == otype)
            {
                return srcBlk;
            }

            int i;
            int k, kSrc, kmin;
            float mult;
            int w = srcBlk.w;
            int h = srcBlk.h;

            switch (otype)
            {

                case DataBlk.TYPE_FLOAT: // Cast INT -> FLOAT

                    float[] farr;
                    int[] srcIArr;

                    // Get data array from resulting blk
                    farr = (float[])blk.Data;
                    if (farr == null || farr.Length < w * h)
                    {
                        farr = new float[w * h];
                        blk.Data = farr;
                    }

                    blk.scanw = srcBlk.w;
                    blk.offset = 0;
                    blk.progressive = srcBlk.progressive;
                    srcIArr = (int[])srcBlk.Data;

                    // Cast data from source to blk
                    fp = src.getFixedPoint(c);
                    if (fp != 0)
                    {
                        mult = 1.0f / (1 << fp);
                        for (i = h - 1, k = w * h - 1, kSrc = srcBlk.offset + (h - 1) * srcBlk.scanw + w - 1;
                             i >= 0;
                             i--)
                        {
                            for (kmin = k - w; k > kmin; k--, kSrc--)
                            {
                                farr[k] = ((srcIArr[kSrc] * mult));
                            }
                            // Jump to geggining of next line in source
                            kSrc -= (srcBlk.scanw - w);
                        }
                    }
                    else
                    {
                        for (i = h - 1, k = w * h - 1, kSrc = srcBlk.offset + (h - 1) * srcBlk.scanw + w - 1;
                             i >= 0;
                             i--)
                        {
                            for (kmin = k - w; k > kmin; k--, kSrc--)
                            {
                                //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'"
                                farr[k] = ((float)(srcIArr[kSrc]));
                            }
                            // Jump to geggining of next line in source
                            kSrc -= (srcBlk.scanw - w);
                        }
                    }
                    break; // End of cast INT-> FLOAT

                case DataBlk.TYPE_INT: // cast FLOAT -> INT
                    int[] iarr;
                    float[] srcFArr;

                    // Get data array from resulting blk
                    iarr = (int[])blk.Data;
                    if (iarr == null || iarr.Length < w * h)
                    {
                        iarr = new int[w * h];
                        blk.Data = iarr;
                    }
                    blk.scanw = srcBlk.w;
                    blk.offset = 0;
                    blk.progressive = srcBlk.progressive;
                    srcFArr = (float[])srcBlk.Data;

                    // Cast data from source to blk
                    if (fp != 0)
                    {
                        //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'"
                        mult = (float)(1 << fp);
                        for (i = h - 1, k = w * h - 1, kSrc = srcBlk.offset + (h - 1) * srcBlk.scanw + w - 1;
                             i >= 0;
                             i--)
                        {
                            for (kmin = k - w; k > kmin; k--, kSrc--)
                            {
                                if (srcFArr[kSrc] > 0.0f)
                                {
                                    //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'"
                                    iarr[k] = (int)(srcFArr[kSrc] * mult + 0.5f);
                                }
                                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'"
                                    iarr[k] = (int)(srcFArr[kSrc] * mult - 0.5f);
                                }
                            }
                            // Jump to geggining of next line in source
                            kSrc -= (srcBlk.scanw - w);
                        }
                    }
                    else
                    {
                        for (i = h - 1, k = w * h - 1, kSrc = srcBlk.offset + (h - 1) * srcBlk.scanw + w - 1;
                             i >= 0;
                             i--)
                        {
                            for (kmin = k - w; k > kmin; k--, kSrc--)
                            {
                                if (srcFArr[kSrc] > 0.0f)
                                {
                                    //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'"
                                    iarr[k] = (int)(srcFArr[kSrc] + 0.5f);
                                }
                                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'"
                                    iarr[k] = (int)(srcFArr[kSrc] - 0.5f);
                                }
                            }
                            // Jump to geggining of next line in source
                            kSrc -= (srcBlk.scanw - w);
                        }
                    }
                    break; // End cast FLOAT -> INT

                default:
                    throw new System.ArgumentException("Only integer and float data " + "are " + "supported by JJ2000");

            }
            return blk;
        }