Exemple #1
0
        public void Read(ref int[,] array, int offsetX, int offsetY, int width, int height, int min, int max)
        {
            int lastX = offsetX + width, lastY = offsetY + height;
            int count = max - min;
            int bits  = IntegerMath.ILog2(IntegerMath.ToPowerOf2(Math.Abs(count)));

            if (max >= 0)
            {
                for (int y = offsetY; y < lastY; y++)
                {
                    for (int x = offsetX; x < lastX; x++)
                    {
                        array[x, y] = br.ReadBits(bits) + min;
                    }
                }
            }
            else
            {
                for (int y = offsetY; y < lastY; y++)
                {
                    for (int x = offsetX; x < lastX; x++)
                    {
                        array[x, y] = -br.ReadBits(bits) + min;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Perfroms a inverse two dimensional isotropic wavelet transformation for the declared area of the array. The result is copied back to the declared array.
        /// </summary>
        /// <param name="array">2d float array on which the transformation should be performed</param>
        /// <param name="offsetX">x position of the area</param>
        /// <param name="offsetY">y position of the area</param>
        /// <param name="width">width of the area</param>
        /// <param name="height">height of the area</param>
        /// <exception cref="ArgumentException"></exception>
        virtual public void BackTransformIsotropic2D(ref float[,] array, int offsetX, int offsetY, int width, int height)
        {
            //There might be better/simpler solutions to solve this transformation... However, it's working ;-)
            int szHorizontal, szVertical; //horizontal size(width) and vertical size(height)
            int iDifference = IntegerMath.ILog2(width) - IntegerMath.ILog2(height);

            szHorizontal = szMinHorz;
            szVertical   = szMinVert;
            CheckArguments(offsetX, offsetY, width, height);

            if (iDifference > 0) // width is greater than height
            {
                for (int i = 0; i < iDifference; i++)
                {
                    for (int y = offsetY; y < szVertical + offsetY; y++)
                    {
                        //back transform horizontal
                        BackTransformRow(ref array, y, offsetX, szHorizontal);
                    }
                    szHorizontal <<= 1; // multiply width by 2
                }
            }
            else if (iDifference < 0) // height is greater than width
            {
                for (int i = 0; i < -iDifference; i++)
                {
                    for (int x = offsetX; x < szHorizontal + offsetX; x++)
                    {
                        //back transform vertical
                        BackTransformColumn(ref array, x, offsetY, szVertical);
                    }
                    szVertical <<= 1; // multiply height by 2
                }
            }

            while (szHorizontal <= width) //just necessary to check the width, as the number of remaining horizontal and vertical transformations are equal now. (szVertical <= iHeight) || (szHorizontal <= iWidth))
            {
                for (int x = offsetX; x < szHorizontal + offsetX; x++)
                {
                    //back transform vertical
                    BackTransformColumn(ref array, x, offsetY, szVertical);
                }
                for (int y = offsetY; y < szVertical + offsetY; y++)
                {
                    //back transform horizontal
                    BackTransformRow(ref array, y, offsetX, szHorizontal);
                }
                szVertical   <<= 1;
                szHorizontal <<= 1;
            }
        }
Exemple #3
0
        public void Write(ref int[,] array, int offsetX, int offsetY, int width, int height, ref int posMin, ref int posMax, ref int negMin, ref int negMax)
        {
            int  countPos, countNeg, bitsPos, bitsNeg, lastX = offsetX + width, lastY = offsetY + height;
            int  val, iCount = 0, x, y;
            bool bDo, bLastZero;

            posMin = int.MaxValue;
            posMax = int.MinValue;
            negMin = int.MaxValue;
            negMax = int.MinValue;

            for (y = offsetY; y < lastY; y++)
            {
                for (x = offsetX; x < lastX; x++)
                {
                    val = array[x, y];
                    if (val > 0)
                    {
                        if (val > posMax)
                        {
                            posMax = val;
                        }
                        if (val < posMin)
                        {
                            posMin = val;
                        }
                    }
                    else if (val < 0)
                    {
                        if (val > negMax)
                        {
                            negMax = val;
                        }
                        if (val < negMin)
                        {
                            negMin = val;
                        }
                    }
                }
            }

            countPos  = posMax - posMin;
            bitsPos   = IntegerMath.ILog2(IntegerMath.ToPowerOf2(Math.Abs(countPos) + 1));
            countNeg  = negMax - negMin;
            bitsNeg   = IntegerMath.ILog2(IntegerMath.ToPowerOf2(Math.Abs(countNeg) + 1));
            x         = 0;
            y         = 0;
            bLastZero = false;
            if (0 >= 0)
            {
                val = array[x, y];

                bDo = true;
                while (bDo)
                {
                    iCount++;
                    val = array[x, y];
                    if ((val < 0) || (val > 0))
                    {
                        if (bLastZero == true)
                        {
                            bLastZero = false;
                            bDo       = false;
                        }
                    }
                    else
                    {
                        if (bLastZero == false)
                        {
                            bLastZero = true;
                            bDo       = false;
                        }
                    }
                    x++;
                    iCount++;
                    if (x > lastX)
                    {
                        y++;
                        x = offsetX;
                    }
                    if (y > lastY)
                    {
                        bDo = false;
                    }
                }



                for (y = offsetY; y < lastY; y++)
                {
                    for (x = offsetX; x < lastX; x++)
                    {
                        val = array[x, y];

                        if (val > 0)
                        {
                            bw.WriteBits(val - posMin, bitsPos);
                        }
                        else if (val < 0)
                        {
                            bw.WriteBits(-val + negMax, bitsNeg);
                        }
                        else
                        {
                        }
                    }
                }
            }
            else
            {
            }
        }