Exemplo n.º 1
0
        /// <summary>
        /// Embeds a watermark to the planes with alpha blending.
        /// </summary>
        /// <param name="wm">The watermark to embed</param>
        /// <param name="alpha">alpha. defaults to 0.9.</param>
        public void AlphaBlend(AltariaImage wm, double alpha = 0.9)
        {
            if (wm.IsTransformed())
            {
                // SII=alpha*(CI) + (1.0-alpha)*(SI)
                //alpha ranges from 0.0 to 1.0
                Bitmap rbmp = new Bitmap(wm.r_plane);
                Bitmap gbmp = new Bitmap(wm.g_plane);
                Bitmap bbmp = new Bitmap(wm.b_plane);

                double finalpixel = 0;
                //Final pixel = alpha * (First image's source pixel) + (1.0-alpha) * (Second image's source pixel)

                //embed r_plane into all sub bands
                for (int i = 0; i < Width; i++)
                {
                    for (int j = 0; j < Height; j++)
                    {
                        finalpixel = alpha * r_plane.GetPixel(i, j).R + (1.0 - alpha) * rbmp.GetPixel(i, j).R;
                        er_plane.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel));
                    }
                }
                //embed g_plane into all sub bands
                for (int i = 0; i < Width; i++)
                {
                    for (int j = 0; j < Height; j++)
                    {
                        finalpixel = alpha * g_plane.GetPixel(i, j).G + (1.0 - alpha) * gbmp.GetPixel(i, j).G;
                        eg_plane.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel));
                    }
                }
                //embed b_plane into all sub bands
                for (int i = 0; i < Width; i++)
                {
                    for (int j = 0; j < Height; j++)
                    {
                        finalpixel = alpha * b_plane.GetPixel(i, j).B + (1.0 - alpha) * bbmp.GetPixel(i, j).B;
                        eb_plane.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel));
                    }
                }
                watermarked = true;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Embeds a watermark to the planes with alpha blending.
        /// </summary>
        /// <param name="wm">The watermark to embed</param>
        /// <param name="alpha">alpha. defaults to 0.9.</param>
        public void AlphaBlend(AltariaImage wm, double alpha = 0.9)
        {
            if (wm.IsTransformed())
            {
                // SII=alpha*(CI) + (1.0-alpha)*(SI)
                //alpha ranges from 0.0 to 1.0
                Bitmap rbmp = new Bitmap(wm.r_plane);
                Bitmap gbmp = new Bitmap(wm.g_plane);
                Bitmap bbmp = new Bitmap(wm.b_plane);

                double finalpixel = 0;
                //Final pixel = alpha * (First image's source pixel) + (1.0-alpha) * (Second image's source pixel)

                //embed r_plane into all sub bands
                for (int i = 0; i < Width; i++)
                    for (int j = 0; j < Height; j++)
                    {
                        finalpixel = alpha * r_plane.GetPixel(i, j).R + (1.0 - alpha) * rbmp.GetPixel(i, j).R;
                        er_plane.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel));
                    }
                //embed g_plane into all sub bands
                for (int i = 0; i < Width; i++)
                    for (int j = 0; j < Height; j++)
                    {
                        finalpixel = alpha * g_plane.GetPixel(i, j).G + (1.0 - alpha) * gbmp.GetPixel(i, j).G;
                        eg_plane.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel));
                    }
                //embed b_plane into all sub bands
                for (int i = 0; i < Width; i++)
                    for (int j = 0; j < Height; j++)
                    {
                        finalpixel = alpha * b_plane.GetPixel(i, j).B + (1.0 - alpha) * bbmp.GetPixel(i, j).B;
                        eb_plane.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel));
                    }
                watermarked = true;
            }
        }
Exemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            string filename = context.Request.QueryString["file"];
            string wmname   = context.Request.QueryString["wm"];
            string mode     = context.Request.QueryString["mode"];
            string original = context.Request.QueryString["original"];

            context.Response.ContentType = "image/bmp";
            if (original != null)
            {
                try
                {
                    ((AltariaImage)context.Session[original]).originalbmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
                }
                catch (Exception)
                {
                    ((Bitmap)context.Session[original]).Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
            }
            else
            //start embed of watermark
            //--------------------------------------START------------------------------------------------------//
            //step 1: Two images are taken as input
            //AltariaImage wm = new AltariaImage(new Bitmap(fu.PostedFile.InputStream), fu.PostedFile.FileName);
            //AltariaImage wm = new AltariaImage(fu.PostedFile.InputStream, fu.PostedFile.FileName);
            //AltariaImage ci = (AltariaImage)Session[((Label)(ri.FindControl("ci"))).Text];
            if (wmname != null && mode != null)
            {
                AltariaImage wm = (AltariaImage)context.Session[wmname];
                AltariaImage ci = (AltariaImage)context.Session[filename];
                if (!ci.IsTransformed())
                {
                    ci.HaarTransform();
                }
                if (!wm.IsTransformed())
                {
                    wm.HaarTransform();
                }
                //save the transform to session to avoid transformation again
                context.Session[filename] = ci;
                context.Session[wmname]   = wm;
                if (mode == "aball")
                {
                    try
                    {
                        string alpha = context.Request.QueryString["alpha"];
                        double a     = Convert.ToDouble(alpha) / 10.0;
                        ci.AlphaBlend(wm, a);
                    }
                    catch
                    {
                        ci.AlphaBlend(wm);
                    }
                    ci.HaarRestore();
                    ci.ConcatPlanes();
                    ci.concatbmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "aball_plane")
                {
                    ci.AlphaBlend(wm, 0.7);
                    ci.er_plane.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull")
                {
                    try
                    {
                        string alpha = context.Request.QueryString["alpha"];
                        double a     = Convert.ToDouble(alpha) / 10.0;
                        ci.AdvancedAlphaBlend(alpha: a);
                    }
                    catch (Exception)
                    {
                        ci.AdvancedAlphaBlend();
                    }
                    ci.HaarRestore();
                    ci.ConcatPlanes();
                    ci.concatbmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull_plane")
                {
                    ci.AdvancedAlphaBlend(0.5);
                    ci.er_plane.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull_all")
                {
                    try
                    {
                        string alpha = context.Request.QueryString["alpha"];
                        double a     = Convert.ToDouble(alpha) / 10.0;
                        ci.AdvancedAlphaBlend(alpha: a, allplanes: true);
                    }
                    catch (Exception)
                    {
                        ci.AdvancedAlphaBlend(allplanes: true);
                    }
                    ci.HaarRestore();
                    ci.ConcatPlanes();
                    ci.concatbmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull_all_plane")
                {
                    ci.AdvancedAlphaBlend(alpha: 0.7, allplanes: true);
                    ci.er_plane.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull_rand")
                {
                    try
                    {
                        string alpha = context.Request.QueryString["alpha"];
                        double a     = Convert.ToDouble(alpha) / 10.0;
                        ci.AdvancedAlphaBlend(alpha: a, random: true);
                    }
                    catch (Exception)
                    {
                        ci.AdvancedAlphaBlend(random: true);
                    }
                    ci.HaarRestore();
                    ci.ConcatPlanes();
                    ci.concatbmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull_rand_plane")
                {
                    ci.AdvancedAlphaBlend(alpha: 0.7, random: true);
                    ci.eb_plane.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull_ex")
                {
                    Bitmap ex_wm = ci.ExtractWatermark(wm);
                    ex_wm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                else if (mode == "abfull_ex_rand")
                {
                    Bitmap ex_wm;
                    try
                    {
                        string alpha = context.Request.QueryString["alpha"];
                        double a     = Convert.ToDouble(alpha) / 10.0;
                        ex_wm = ci.ExtractWatermark(wm, true, alpha: a);
                    }
                    catch (Exception)
                    {
                        ex_wm = ci.ExtractWatermark(wm, true);
                    }
                    ex_wm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
            }
            else
            {
                AltariaImage ci = (AltariaImage)context.Session[filename];
                ci.originalbmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
            }
        }