protected void uploadorigin_onclick(object sender, EventArgs e) { Button btn = sender as Button; RepeaterItem ri = btn.NamingContainer as RepeaterItem; FileUpload fu = ri.FindControl("fu") as FileUpload; DropDownList ddl = ri.FindControl("alpha_list") as DropDownList; if (fu.HasFile) { Session.Add(fu.PostedFile.FileName, new AltariaImage(new Bitmap(fu.PostedFile.InputStream), fu.PostedFile.FileName)); step3.Visible = true; embed.Visible = false; //Extract watermark int alpha = (int)(Convert.ToDouble(ddl.SelectedValue) * 10.0); original_img.ImageUrl = "ImageHandler.ashx?original=" + fu.PostedFile.FileName; extracted_img.ImageUrl = "ImageHandler.ashx?file=" + ((Label)(ri.FindControl("ci"))).Text + "&wm=" + fu.PostedFile.FileName + "&mode=abfull_ex_rand&alpha=" + alpha; AltariaImage nai = new AltariaImage(new Bitmap(fu.PostedFile.InputStream), fu.PostedFile.FileName).SaltAndPepper(5); Session.Add("snp1", nai); snp1.ImageUrl = "ImageHandler.ashx?original=snp1"; extracted_snp1.ImageUrl = "ImageHandler.ashx?file=" + ((Label)(ri.FindControl("ci"))).Text + "&wm=snp1&mode=abfull_ex_rand&alpha=" + alpha; AltariaImage nai2 = new AltariaImage(new Bitmap(fu.PostedFile.InputStream), fu.PostedFile.FileName).CompressImage(50L); Session.Add("compress1", nai2); compress1.ImageUrl = "ImageHandler.ashx?original=compress1"; extracted_compress1.ImageUrl = "ImageHandler.ashx?file=" + ((Label)(ri.FindControl("ci"))).Text + "&wm=compress1&mode=abfull_ex_rand&alpha=" + alpha; } }
/// <summary> /// Performs a salt and pepper attack on the bmp. /// </summary> /// <param name="p">the intensity to perform the attack at</param> /// <returns>the resulting image</returns> internal AltariaImage SaltAndPepper(double p) { AltariaImage nai = new AltariaImage(new Bitmap(this.originalbmp), this.Name); SaltAndPepperNoise filter = new SaltAndPepperNoise(p); filter.ApplyInPlace(nai.originalbmp); return(nai); }
protected void UploadedImages_ItemDataBound(object sender, RepeaterItemEventArgs riea) { step1.Visible = false; if (riea.Item.ItemType == ListItemType.Item || riea.Item.ItemType == ListItemType.AlternatingItem) { //AltariaImage ai = riea.Item.DataItem as AltariaImage; AltariaImage ai = riea.Item.DataItem as AltariaImage; if (ai.watermarked) { //watermarked riea.Item.FindControl("wm_form").Visible = false; } else { //not watermarked, embed watermark } } }
//Upload file protected void upload_onclick(object sender, EventArgs e) { if (Page.IsValid) { HttpFileCollection hfc = Request.Files; for (int i = 0; i < hfc.Count; i++) { HttpPostedFile file = hfc[i]; AltariaImage temp_ai = new AltariaImage(new Bitmap(file.InputStream), file.FileName); ai.Add(temp_ai); //add uploaded file to session Session.Add(file.FileName, temp_ai); } UploadedImages.DataSource = ai; step2.Visible = true; UploadedImages.DataBind(); } }
/// <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; } }
/// <summary> /// Performs a salt and pepper attack on the bmp. /// </summary> /// <param name="p">the intensity to perform the attack at</param> /// <returns>the resulting image</returns> internal AltariaImage SaltAndPepper(double p) { AltariaImage nai = new AltariaImage(new Bitmap(this.originalbmp), this.Name); SaltAndPepperNoise filter = new SaltAndPepperNoise(p); filter.ApplyInPlace(nai.originalbmp); return nai; }
/// <summary> /// Extract the watermark /// </summary> /// <param name="origin">The original image to compare with the watermarked image</param> /// <param name="wm_height">optional. specifies the watermark height. defaults to 32.</param> /// <param name="wm_width">optional. specifies the watermark width. defaults to 32.</param> /// <param name="random">optional. specifies whether the watermark has been embedded randomly. defaults to false.</param> /// <param name="alpha">optional. specifies the alpha. defaults to AltariaImage's constant alpha.</param> public Bitmap ExtractWatermark(AltariaImage origin, bool random = false, int wm_height = 32, int wm_width = 32, double alpha = alpha) { //get hl and lh of the planes as individual bitmaps Bitmap hl_r, lh_r; Bitmap hl_g, lh_g; Bitmap hl_b, lh_b; Bitmap origin_hl_r, origin_lh_r; Bitmap origin_hl_g, origin_lh_g; Bitmap origin_hl_b, origin_lh_b; double finalpixel = 0; Bitmap result = new Bitmap(wm_width, wm_height); Rectangle hl_crop = new Rectangle(Width / 2, 0, Width / 2, Height / 2); Rectangle lh_crop = new Rectangle(0, Height / 2, Width / 2, Height / 2); // r_plane hl_r = r_plane.Clone(hl_crop, r_plane.PixelFormat); lh_r = r_plane.Clone(lh_crop, r_plane.PixelFormat); origin_hl_r = origin.r_plane.Clone(hl_crop, origin.r_plane.PixelFormat); origin_lh_r = origin.r_plane.Clone(lh_crop, origin.r_plane.PixelFormat); // g_plane hl_g = g_plane.Clone(hl_crop, g_plane.PixelFormat); lh_g = g_plane.Clone(lh_crop, g_plane.PixelFormat); origin_hl_g = origin.g_plane.Clone(hl_crop, origin.g_plane.PixelFormat); origin_lh_g = origin.g_plane.Clone(lh_crop, origin.g_plane.PixelFormat); // r_plane hl_b = b_plane.Clone(hl_crop, b_plane.PixelFormat); lh_b = b_plane.Clone(lh_crop, b_plane.PixelFormat); origin_hl_b = origin.b_plane.Clone(hl_crop, origin.b_plane.PixelFormat); origin_lh_b = origin.b_plane.Clone(lh_crop, origin.b_plane.PixelFormat); List<Bitmap> watermarks = new List<Bitmap>(); if (random) { //extract the embedded watermarks from the randomized embedding //determine the position of placement based on maximum coefficient of original image int max_hl_r = 0, max_hl_g = 0, max_hl_b = 0; int max_lh_r = 0, max_lh_g = 0, max_lh_b = 0; for (int i = 0; i < hl_r.Width; i++) for (int j = 0; j < hl_r.Height; j++) { int temp = hl_r.GetPixel(i, j).R; //oh yeah ternary operations because I am lazy //hl max_hl_r = temp > max_hl_r ? temp : max_hl_r; temp = hl_g.GetPixel(i, j).G; max_hl_g = temp > max_hl_g ? temp : max_hl_g; temp = hl_b.GetPixel(i, j).B; max_hl_b = temp > max_hl_b ? temp : max_hl_b; //lh temp = lh_r.GetPixel(i, j).R; max_lh_r = temp > max_lh_r ? temp : max_lh_r; temp = lh_g.GetPixel(i, j).G; max_lh_g = temp > max_lh_g ? temp : max_lh_g; temp = lh_b.GetPixel(i, j).B; max_lh_b = temp > max_lh_b ? temp : max_lh_b; } //extracting the watermark for (int i = 0, ii = hl_r.Width - wm_width; i < wm_width; i++, ii++) { //hl_r for (int j = 0, start = max_hl_r; j < wm_height; j++, start++) { int s = start % hl_r.Width; finalpixel = (hl_r.GetPixel(i, s).R - alpha * origin_hl_r.GetPixel(i, s).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //hl_g for (int j = 0, start = max_hl_g; j < wm_height; j++, start++) { int s = start % hl_g.Width; finalpixel = (hl_g.GetPixel(ii, s).G - alpha * origin_hl_g.GetPixel(ii, s).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //hl_b for (int j = 0, jj = hl_b.Height - wm_height, start = max_hl_b; j < wm_height; j++, start++, jj++) { finalpixel = (hl_b.GetPixel(i, jj).B - alpha * origin_hl_b.GetPixel(i, jj).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //lh_r for (int j = 0, start = max_lh_r; j < wm_height; j++, start++) { int s = start % lh_r.Width; finalpixel = (lh_r.GetPixel(i, s).R - alpha * origin_lh_r.GetPixel(i, s).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //lh_g for (int j = 0, start = max_lh_g; j < wm_height; j++, start++) { int s = start % lh_g.Width; finalpixel = (lh_g.GetPixel(ii, s).G - alpha * origin_lh_g.GetPixel(ii, s).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //lh_b for (int j = 0, jj = lh_b.Height - wm_height, start = max_lh_b; j < wm_height; j++, start++, jj++) { finalpixel = (lh_b.GetPixel(i, jj).B - alpha * origin_lh_b.GetPixel(i, jj).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); } } else { //extract the embedded watermarks for (int i = 0; i < wm_width; i++) for (int j = 0; j < wm_height; j++) { //lh_r finalpixel = (lh_r.GetPixel(i, j).R - alpha * origin_lh_r.GetPixel(i, j).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); for (int i = 0; i < wm_width; i++) for (int j = 0; j < wm_height; j++) { //hl_r finalpixel = (hl_r.GetPixel(i, j).R - alpha * origin_hl_r.GetPixel(i, j).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); for (int i = 0; i < wm_width; i++) for (int j = 0; j < wm_height; j++) { //lh_g finalpixel = (lh_g.GetPixel(i, j).G - alpha * origin_lh_g.GetPixel(i, j).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); for (int i = 0; i < wm_width; i++) for (int j = 0; j < wm_height; j++) { //hl_g finalpixel = (hl_g.GetPixel(i, j).G - alpha * origin_hl_g.GetPixel(i, j).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); for (int i = 0; i < wm_width; i++) for (int j = 0; j < wm_height; j++) { //lh_b finalpixel = (lh_b.GetPixel(i, j).B - alpha * origin_lh_b.GetPixel(i, j).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); for (int i = 0; i < wm_width; i++) for (int j = 0; j < wm_height; j++) { //hl_b finalpixel = (hl_b.GetPixel(i, j).B - alpha * origin_hl_b.GetPixel(i, j).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) finalpixel = 0; result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); } Bitmap finalresult = new Bitmap(wm_width * 6, wm_height); using (Graphics g = Graphics.FromImage(finalresult)) { for (int i = 0; i < 6; i++) { g.DrawImage(watermarks[i], i * wm_width, 0); } } //test finalresult.Save("C:\\temp\\result.bmp"); return finalresult; }
/// <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; } }
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); } }
/// <summary> /// Extract the watermark /// </summary> /// <param name="origin">The original image to compare with the watermarked image</param> /// <param name="wm_height">optional. specifies the watermark height. defaults to 32.</param> /// <param name="wm_width">optional. specifies the watermark width. defaults to 32.</param> /// <param name="random">optional. specifies whether the watermark has been embedded randomly. defaults to false.</param> /// <param name="alpha">optional. specifies the alpha. defaults to AltariaImage's constant alpha.</param> public Bitmap ExtractWatermark(AltariaImage origin, bool random = false, int wm_height = 32, int wm_width = 32, double alpha = alpha) { //get hl and lh of the planes as individual bitmaps Bitmap hl_r, lh_r; Bitmap hl_g, lh_g; Bitmap hl_b, lh_b; Bitmap origin_hl_r, origin_lh_r; Bitmap origin_hl_g, origin_lh_g; Bitmap origin_hl_b, origin_lh_b; double finalpixel = 0; Bitmap result = new Bitmap(wm_width, wm_height); Rectangle hl_crop = new Rectangle(Width / 2, 0, Width / 2, Height / 2); Rectangle lh_crop = new Rectangle(0, Height / 2, Width / 2, Height / 2); // r_plane hl_r = r_plane.Clone(hl_crop, r_plane.PixelFormat); lh_r = r_plane.Clone(lh_crop, r_plane.PixelFormat); origin_hl_r = origin.r_plane.Clone(hl_crop, origin.r_plane.PixelFormat); origin_lh_r = origin.r_plane.Clone(lh_crop, origin.r_plane.PixelFormat); // g_plane hl_g = g_plane.Clone(hl_crop, g_plane.PixelFormat); lh_g = g_plane.Clone(lh_crop, g_plane.PixelFormat); origin_hl_g = origin.g_plane.Clone(hl_crop, origin.g_plane.PixelFormat); origin_lh_g = origin.g_plane.Clone(lh_crop, origin.g_plane.PixelFormat); // r_plane hl_b = b_plane.Clone(hl_crop, b_plane.PixelFormat); lh_b = b_plane.Clone(lh_crop, b_plane.PixelFormat); origin_hl_b = origin.b_plane.Clone(hl_crop, origin.b_plane.PixelFormat); origin_lh_b = origin.b_plane.Clone(lh_crop, origin.b_plane.PixelFormat); List <Bitmap> watermarks = new List <Bitmap>(); if (random) { //extract the embedded watermarks from the randomized embedding //determine the position of placement based on maximum coefficient of original image int max_hl_r = 0, max_hl_g = 0, max_hl_b = 0; int max_lh_r = 0, max_lh_g = 0, max_lh_b = 0; for (int i = 0; i < hl_r.Width; i++) { for (int j = 0; j < hl_r.Height; j++) { int temp = hl_r.GetPixel(i, j).R; //oh yeah ternary operations because I am lazy //hl max_hl_r = temp > max_hl_r ? temp : max_hl_r; temp = hl_g.GetPixel(i, j).G; max_hl_g = temp > max_hl_g ? temp : max_hl_g; temp = hl_b.GetPixel(i, j).B; max_hl_b = temp > max_hl_b ? temp : max_hl_b; //lh temp = lh_r.GetPixel(i, j).R; max_lh_r = temp > max_lh_r ? temp : max_lh_r; temp = lh_g.GetPixel(i, j).G; max_lh_g = temp > max_lh_g ? temp : max_lh_g; temp = lh_b.GetPixel(i, j).B; max_lh_b = temp > max_lh_b ? temp : max_lh_b; } } //extracting the watermark for (int i = 0, ii = hl_r.Width - wm_width; i < wm_width; i++, ii++) { //hl_r for (int j = 0, start = max_hl_r; j < wm_height; j++, start++) { int s = start % hl_r.Width; finalpixel = (hl_r.GetPixel(i, s).R - alpha * origin_hl_r.GetPixel(i, s).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //hl_g for (int j = 0, start = max_hl_g; j < wm_height; j++, start++) { int s = start % hl_g.Width; finalpixel = (hl_g.GetPixel(ii, s).G - alpha * origin_hl_g.GetPixel(ii, s).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //hl_b for (int j = 0, jj = hl_b.Height - wm_height, start = max_hl_b; j < wm_height; j++, start++, jj++) { finalpixel = (hl_b.GetPixel(i, jj).B - alpha * origin_hl_b.GetPixel(i, jj).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //lh_r for (int j = 0, start = max_lh_r; j < wm_height; j++, start++) { int s = start % lh_r.Width; finalpixel = (lh_r.GetPixel(i, s).R - alpha * origin_lh_r.GetPixel(i, s).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //lh_g for (int j = 0, start = max_lh_g; j < wm_height; j++, start++) { int s = start % lh_g.Width; finalpixel = (lh_g.GetPixel(ii, s).G - alpha * origin_lh_g.GetPixel(ii, s).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); //lh_b for (int j = 0, jj = lh_b.Height - wm_height, start = max_lh_b; j < wm_height; j++, start++, jj++) { finalpixel = (lh_b.GetPixel(i, jj).B - alpha * origin_lh_b.GetPixel(i, jj).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } watermarks.Add(result); } } else { //extract the embedded watermarks for (int i = 0; i < wm_width; i++) { for (int j = 0; j < wm_height; j++) { //lh_r finalpixel = (lh_r.GetPixel(i, j).R - alpha * origin_lh_r.GetPixel(i, j).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } } watermarks.Add(result); for (int i = 0; i < wm_width; i++) { for (int j = 0; j < wm_height; j++) { //hl_r finalpixel = (hl_r.GetPixel(i, j).R - alpha * origin_hl_r.GetPixel(i, j).R) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } } watermarks.Add(result); for (int i = 0; i < wm_width; i++) { for (int j = 0; j < wm_height; j++) { //lh_g finalpixel = (lh_g.GetPixel(i, j).G - alpha * origin_lh_g.GetPixel(i, j).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } } watermarks.Add(result); for (int i = 0; i < wm_width; i++) { for (int j = 0; j < wm_height; j++) { //hl_g finalpixel = (hl_g.GetPixel(i, j).G - alpha * origin_hl_g.GetPixel(i, j).G) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } } watermarks.Add(result); for (int i = 0; i < wm_width; i++) { for (int j = 0; j < wm_height; j++) { //lh_b finalpixel = (lh_b.GetPixel(i, j).B - alpha * origin_lh_b.GetPixel(i, j).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } } watermarks.Add(result); for (int i = 0; i < wm_width; i++) { for (int j = 0; j < wm_height; j++) { //hl_b finalpixel = (hl_b.GetPixel(i, j).B - alpha * origin_hl_b.GetPixel(i, j).B) / (1.0 - alpha); if (finalpixel < 0 || finalpixel > 255) { finalpixel = 0; } result.SetPixel(i, j, Color.FromArgb((int)finalpixel, (int)finalpixel, (int)finalpixel)); } } watermarks.Add(result); } Bitmap finalresult = new Bitmap(wm_width * 6, wm_height); using (Graphics g = Graphics.FromImage(finalresult)) { for (int i = 0; i < 6; i++) { g.DrawImage(watermarks[i], i * wm_width, 0); } } //test finalresult.Save("C:\\temp\\result.bmp"); return(finalresult); }