Esempio n. 1
0
        public void SetSrcSizeTest()
        {
            PixelMapScaler scaler = new PixelMapScaler();

            scaler._HCoord = new int[1];
            scaler._VCoord = new int[1];

            Assert.Null(scaler._PixelMap1);
            Assert.Null(scaler._PixelMap2);
            Assert.NotNull(scaler._HCoord);
            Assert.NotNull(scaler._VCoord);
            Assert.Equal(-1, scaler._L1);
            Assert.Equal(-1, scaler._L2);
            Assert.Equal(0, scaler._DestWidth);
            Assert.Equal(0, scaler._DestHeight);
            Assert.Equal(0, scaler._SrcWidth);
            Assert.Equal(0, scaler._SrcHeight);

            scaler.SetSrcSize(15, 17);
            Assert.Equal(0, scaler._DestWidth);
            Assert.Equal(0, scaler._DestHeight);
            Assert.Null(scaler._HCoord);
            Assert.Null(scaler._VCoord);
            Assert.Equal(15, scaler._SrcWidth);
            Assert.Equal(17, scaler._SrcHeight);
        }
Esempio n. 2
0
        public void PixelMapScalerTest001()
        {
            PixelMapScaler scaler = new PixelMapScaler();

            Assert.Null(scaler._PixelMap1);
            Assert.Null(scaler._PixelMap2);
            Assert.Null(scaler._HCoord);
            Assert.Null(scaler._VCoord);
            Assert.Equal(-1, scaler._L1);
            Assert.Equal(-1, scaler._L2);
        }
Esempio n. 3
0
        private static PixelMapScaler CreateVerifyPixelMapScaler(int srcWidth, int srcHeight, int targetWidth, int targetHeight)
        {
            PixelMapScaler scaler = new PixelMapScaler(srcWidth, srcHeight, targetWidth, targetHeight);

            Assert.Null(scaler._PixelMap1);
            Assert.Null(scaler._PixelMap2);
            Assert.Null(scaler._HCoord);
            Assert.Null(scaler._VCoord);
            Assert.Equal(-1, scaler._L1);
            Assert.Equal(-1, scaler._L2);
            Assert.Equal(srcWidth, scaler._SrcWidth);
            Assert.Equal(srcHeight, scaler._SrcHeight);
            Assert.Equal(targetWidth, scaler._DestWidth);
            Assert.Equal(targetHeight, scaler._DestHeight);
            return(scaler);
        }
Esempio n. 4
0
        public void PixelMapScalerTest002()
        {
            int srcWidth     = 16;
            int srcHeight    = 17;
            int targetWidth  = 18;
            int targetHeight = 19;

            PixelMapScaler scaler = new PixelMapScaler(srcWidth, srcHeight, targetWidth, targetHeight);

            Assert.Null(scaler._PixelMap1);
            Assert.Null(scaler._PixelMap2);
            Assert.Null(scaler._HCoord);
            Assert.Null(scaler._VCoord);
            Assert.Equal(-1, scaler._L1);
            Assert.Equal(-1, scaler._L2);
            Assert.Equal(srcWidth, scaler._SrcWidth);
            Assert.Equal(srcHeight, scaler._SrcHeight);
            Assert.Equal(targetWidth, scaler._DestWidth);
            Assert.Equal(targetHeight, scaler._DestHeight);
            scaler.SetDestSize(0, 0);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets the background pixmap
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="subSample"></param>
        /// <param name="gamma"></param>
        /// <param name="retval"></param>
        /// <returns></returns>
        public GPixmap GetBgPixmap(GRect rect, int subsample, double gamma, GPixmap retval)
        {
            Verify.SubsampleRange(subsample);

            GPixmap pMap = null;
            int width = Width;
            int height = Height;

            if (width <= 0 || height <= 0)
                return null;

            double gammaCorr = 1.0D;

            if (gamma > 0.0D && Gamma > 0)
            {
                gammaCorr = gamma / Gamma;
            }

            if (gammaCorr < 0.10000000000000001D)
            {
                gammaCorr = 0.10000000000000001D;
            }
            else if (gammaCorr > 10D)
            {
                gammaCorr = 10D;
            }

            IInterWavePixelMap bgIWPixmap = BackgroundIWPixelMap;

            if (bgIWPixmap != null)
            {
                int iwWidth = bgIWPixmap.Width;
                int iwHeight = bgIWPixmap.Height;

                if (iwWidth == 0 || iwHeight == 0)
                    return null;

                int red = ComputeRed(width, height, iwWidth, iwHeight);

                if (red < 1 || red > 12)
                    return null;

                if (subsample == red)
                {
                    pMap = bgIWPixmap.GetPixelMap(1, rect, retval);
                }
                else if (subsample == (2 * red))
                {
                    pMap = bgIWPixmap.GetPixelMap(2, rect, retval);
                }
                else if (subsample == (4 * red))
                {
                    pMap = bgIWPixmap.GetPixelMap(4, rect, retval);
                }
                else if (subsample == (8 * red))
                {
                    pMap = bgIWPixmap.GetPixelMap(8, rect, retval);
                }
                else if ((red * 4) == (subsample * 3))
                {
                    GRect xrect = new GRect();
                    xrect.Right = (int)Math.Floor(rect.Right * 4D / 3D);
                    xrect.Bottom = (int)Math.Floor(rect.Bottom * 4D / 3D);
                    xrect.Left = (int)Math.Ceiling((double)rect.Left * 4D / 3D);
                    xrect.Top = (int)Math.Ceiling((double)rect.Top * 4D / 3D);

                    GRect nrect = new GRect(0, 0, rect.Width, rect.Height);

                    if (xrect.Left > iwWidth)
                        xrect.Left = iwWidth;

                    if (xrect.Top > iwHeight)
                        xrect.Top = iwHeight;

                    GPixmap iwPMap = bgIWPixmap.GetPixelMap(1, xrect, null);
                    pMap = (retval != null) ? retval : new PixelMap();
                    pMap.Downsample43(iwPMap, nrect);
                }
                else
                {
                    int po2 = 16;

                    while (po2 > 1 && subsample < po2 * red)
                        po2 >>= 1;

                    int inw = ((iwWidth + po2) - 1) / po2;
                    int inh = ((iwHeight + po2) - 1) / po2;
                    int outw = ((width + subsample) - 1) / subsample;
                    int outh = ((height + subsample) - 1) / subsample;
                    PixelMapScaler mapScaler = new PixelMapScaler(inw, inh, outw, outh);

                    mapScaler.SetHorzRatio(red * po2, subsample);
                    mapScaler.SetVertRatio(red * po2, subsample);

                    GRect xrect = mapScaler.GetRequiredRect(rect);
                    GPixmap iwPMap = bgIWPixmap.GetPixelMap(po2, xrect, null);
                    pMap = (retval != null) ? retval : new PixelMap();

                    mapScaler.Scale(xrect, iwPMap, rect, pMap);
                }

                if (pMap != null && gammaCorr != 1.0D)
                {
                    pMap.ApplyGammaCorrection(gammaCorr);

                    for (int i = 0; i < 9; i++)
                        pMap.ApplyGammaCorrection(gammaCorr);
                }

                return pMap;
            }
            else
                return null;
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the background pixmap
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="subSample"></param>
        /// <param name="gamma"></param>
        /// <param name="retval"></param>
        /// <returns></returns>
        public GPixmap GetBgPixmap(GRect rect, int subsample, double gamma, GPixmap retval)
        {
            GPixmap pm    = null;
            int     width = (Info == null)
                            ? 0
                            : Info.Width;
            int height = (Info == null)
                             ? 0
                             : Info.Height;

            if ((width <= 0) || (height <= 0) || (Info == null))
            {
                return(null);
            }

            double gamma_correction = 1.0D;

            if ((gamma > 0.0D) && (Info != null))
            {
                gamma_correction = gamma / Info.Gamma;
            }

            if (gamma_correction < 0.10000000000000001D)
            {
                gamma_correction = 0.10000000000000001D;
            }
            else if (gamma_correction > 10D)
            {
                gamma_correction = 10D;
            }

            IWPixelMap bgIWPixmap = BackgroundIWPixelMap;

            if (bgIWPixmap != null)
            {
                int w = bgIWPixmap.Width;
                int h = bgIWPixmap.Height;

                if ((w == 0) || (h == 0) || (width == 0) || (height == 0))
                {
                    return(null);
                }

                int red = ComputeRed(width, height, w, h);

                if ((red < 1) || (red > 12))
                {
                    return(null);
                }

                if (subsample == red)
                {
                    pm = bgIWPixmap.GetPixmap(1, rect, retval);
                }
                else if (subsample == (2 * red))
                {
                    pm = bgIWPixmap.GetPixmap(2, rect, retval);
                }
                else if (subsample == (4 * red))
                {
                    pm = bgIWPixmap.GetPixmap(4, rect, retval);
                }
                else if (subsample == (8 * red))
                {
                    pm = bgIWPixmap.GetPixmap(8, rect, retval);
                }
                else if ((red * 4) == (subsample * 3))
                {
                    GRect xrect = new GRect();
                    xrect.Right  = (int)Math.Floor(rect.Right * 4D / 3D);
                    xrect.Bottom = (int)Math.Floor(rect.Bottom * 4D / 3D);
                    xrect.Left   = (int)Math.Ceiling((double)rect.Left * 4D / 3D);
                    xrect.Top    = (int)Math.Ceiling((double)rect.Top * 4D / 3D);

                    GRect nrect = new GRect(0, 0, rect.Width, rect.Height);
                    if (xrect.Left > w)
                    {
                        xrect.Left = w;
                    }

                    if (xrect.Top > h)
                    {
                        xrect.Top = h;
                    }

                    GPixmap ipm = bgIWPixmap.GetPixmap(1, xrect, null);
                    pm = (retval != null)
                             ? retval
                             : new GPixmap();
                    pm.Downsample43(ipm, nrect);
                }
                else
                {
                    int po2 = 16;

                    while ((po2 > 1) && (subsample < (po2 * red)))
                    {
                        po2 >>= 1;
                    }

                    int            inw  = ((w + po2) - 1) / po2;
                    int            inh  = ((h + po2) - 1) / po2;
                    int            outw = ((width + subsample) - 1) / subsample;
                    int            outh = ((height + subsample) - 1) / subsample;
                    PixelMapScaler ps   = new PixelMapScaler(inw, inh, outw, outh);
                    ps.SetHorzRatio(red * po2, subsample);
                    ps.SetVertRatio(red * po2, subsample);

                    GRect   xrect = ps.GetRequiredRect(rect);
                    GPixmap ipm   = bgIWPixmap.GetPixmap(po2, xrect, null);
                    pm = (retval != null)
                             ? retval
                             : new GPixmap();
                    ps.Scale(xrect, ipm, rect, pm);
                }

                if ((pm != null) && (gamma_correction != 1.0D))
                {
                    pm.ApplyGammaCorrection(gamma_correction);

                    for (int i = 0; i < 9; i++)
                    {
                        pm.ApplyGammaCorrection(gamma_correction);
                    }
                }

                return(pm);
            }
            else
            {
                return(null);
            }
        }