예제 #1
0
 /// <summary> Apply forward component transformation associated with the current
 /// tile. If no component transformation has been requested by the user,
 /// data are not modified.
 ///
 /// <p>This method calls the getInternCompData() method, but respects the
 /// definitions of the getCompData() method defined in the BlkImgDataSrc
 /// interface.</p>
 ///
 /// </summary>
 /// <param name="blk">Determines the rectangular area to return, and the data is
 /// returned in this object.
 ///
 /// </param>
 /// <param name="c">Index of the output component.
 ///
 /// </param>
 /// <returns> The requested DataBlk
 ///
 /// </returns>
 /// <seealso cref="BlkImgDataSrc.getCompData">
 ///
 /// </seealso>
 public virtual DataBlk getCompData(DataBlk blk, int c)
 {
     // If requesting a component whose index is greater than 3 or there is
     // no transform return a copy of data (getInternCompData returns the
     // actual data in those cases)
     if (c >= 3 || transfType == NONE)
     {
         return(src.getCompData(blk, c));
     }
     else
     {
         // We can use getInternCompData (since data is a copy anyways)
         return(getInternCompData(blk, c));
     }
 }
예제 #2
0
        /// <summary> 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".
        ///
        /// <p>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.</p>
        ///
        /// <p>This method, in general, is less efficient than the
        /// 'getInternCompData()' method since, in general, it copies the
        /// data. However if the array of returned data is to be modified by the
        /// caller then this method is preferable.</p>
        ///
        /// <p>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.</p>
        ///
        /// <p>The returned data may have its 'progressive' attribute set. In this
        /// case the returned data is only an approximation of the "final"
        /// data.</p>
        ///
        /// </summary>
        /// <param name="blk">Its coordinates and dimensions specify the area to return,
        /// relative to the current tile. If it contains a non-null data array,
        /// then it must be large enough. If it contains a null data array a new
        /// one is created. Some 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.
        ///
        /// </param>
        /// <returns> The requested DataBlk
        ///
        /// </returns>
        /// <seealso cref="getInternCompData">
        ///
        /// </seealso>
        public DataBlk getCompData(DataBlk blk, int c)
        {
            // Check that block is inside tile
            if (blk.ulx < 0 || blk.uly < 0 || blk.w > compW[c] || blk.h > compH[c])
            {
                throw new System.ArgumentException("Block is outside the tile");
            }
            // Translate to the source's coordinates
            //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'"
            int incx = (int)System.Math.Ceiling(x0siz / (double)src.getCompSubsX(c));
            //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'"
            int incy = (int)System.Math.Ceiling(y0siz / (double)src.getCompSubsY(c));

            blk.ulx -= incx;
            blk.uly -= incy;
            blk      = src.getCompData(blk, c);
            // Translate back to the tiled coordinates
            blk.ulx += incx;
            blk.uly += incy;
            return(blk);
        }
예제 #3
0
 /// <summary> 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".
 ///
 /// <P>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.
 ///
 /// <P>This method, in general, is less efficient than the
 /// 'getInternCompData()' method since, in general, it copies the
 /// data. However if the array of returned data is to be modified by the
 /// caller then this method is preferable.
 ///
 /// <P>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.
 ///
 /// <P>The returned data may have its 'progressive' attribute set. In this
 /// case the returned data is only an approximation of the "final" data.
 ///
 /// </summary>
 /// <param name="blk">Its coordinates and dimensions specify the area to return,
 /// relative to the current tile. If it contains a non-null data array,
 /// then it must be large enough. If it contains a null data array a new
 /// one is created. Some 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.
 ///
 /// </param>
 /// <seealso cref="getInternCompData">
 ///
 /// </seealso>
 public virtual DataBlk getCompData(DataBlk out_Renamed, int c)
 {
     return(src.getCompData(out_Renamed, c));
 }
예제 #4
0
        /// <summary> Implements the 'getInternCompData()' and the 'getCompData()'
        /// methods. The 'intern' flag signals which of the two methods should run
        /// as.
        ///
        /// </summary>
        /// <param name="blk">The data block to get.
        ///
        /// </param>
        /// <param name="c">The index of the component from which to get the data.
        ///
        /// </param>
        /// <param name="intern">If true behave as 'getInternCompData(). Otherwise behave
        /// as 'getCompData()'
        ///
        /// </param>
        /// <returns> The requested data block
        ///
        /// </returns>
        /// <seealso cref="getInternCompData">
        ///
        /// </seealso>
        /// <seealso cref="getCompData">
        ///
        /// </seealso>
        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);
        }