Ejemplo n.º 1
0
        public void SaveImgCaption(int id, FormCollection form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    //SAVE THE CAPTION FOR THE CORRECT IMAGE
                    string caption = form["item.caption"].ToString();
                    int    imgId   = Convert.ToInt16(form["item.id"]);

                    //GET THE IMAGE PROPERTIES FROM THE IMG ID
                    image articleImage = db.images.Find(imgId);

                    //MODIFY THE IMAGE CAPTION
                    articleImage.caption = caption;

                    db.Entry(articleImage).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch (DbUpdateException e)
            {
                ViewBag.DbExceptionMessage = e.Message;
            }
            catch (SqlException e)
            {
                ViewBag.SqlExceptionMessage = e.Message;
            }
            catch (Exception e)
            {
                ViewBag.GenericException = e.Message;
            }
            RedirectToAction("Errors", "Navigate");
        }
Ejemplo n.º 2
0
    //-----------------------------------------------------
    // construct from existing BufferedImage and mask
    public MaskedImage(image im, bool[,] mask)
    {
        this.im = im;
        this.width=im.width;
        this.height=im.height;
        this.mask = mask;

                // reference array is length 100, but is truncated at first zero value
        // base[0]=1.0, base[1]=0.99, ..., base[99]=0, base[100]=0
        double[] bas = new double[11]{1.0, 0.99, 0.96, 0.83, 0.38, 0.11, 0.02, 0.005, 0.0006, 0.0001, 0 };

        // stretch base array
        similarity = new double[DSCALE+1];
        for(int i=0;i<DSCALE+1;i++) {
            double t = (double)i/(DSCALE+1);

            // interpolate from base array values
            int j = (int)(100*t), k=j+1;
            double vj = (j<11)?bas[j]:0;
            double vk = (k<11)?bas[k]:0;

            double v = vj + (100*t-j)*(vk-vj);
            similarity[i] = v;
        }
    }
Ejemplo n.º 3
0
 //-----------------------------------------------------
 // construct empty image
 public MaskedImage(int width, int height)
 {
     this.width=width;
     this.height=height;
     this.im = new image(width, height);
     this.mask = new bool[width,height];
 }
Ejemplo n.º 4
0
        public ActionResult addNew(image obj, List <HttpPostedFileBase> files)
        {
            if (ModelState.IsValid)
            {
                foreach (HttpPostedFileBase img in files)
                {
                    if (img != null && img.ContentLength > 0)
                    {
                        var filename = Path.GetFileName(img.FileName);
                        var _ex      = Path.GetExtension(img.FileName);
                        var path     = Path.Combine(Server.MapPath("~/App_Data/Upload/Products"), Hash.EncMD5(filename) + _ex);
                        img.SaveAs(path);

                        addSV.Add_image(
                            Session["token"] as string,
                            (Session["admin"] as MobileStore.ViewService.admin).id,
                            addSV.ID_Return("image"),
                            "~/App_Data/Upload/Products/" + Hash.EncMD5(filename) + _ex,
                            obj.product_id);

                        ViewBag.HtmlStr  = "<div class=\"alert alert-info alert-with-icon col-md-6 col-md-offset-3\" data-notify=\"container\"><i class=\"material-icons\" data-notify=\"icon\">notifications</i><button type = \"button\" aria-hidden=\"true\" class=\"close\"><i class=\"material-icons\">close</i></button><span data-notify=\"message\">Insert Complete!.</span></div>";
                        ViewBag.Message += string.Format("<b>{0}</b> uploaded.<br />", filename);
                    }
                }
            }
            else
            {
                ViewBag.HtmlStr = "<div class=\"alert alert-rose alert-with-icon col-md-6 col-md-offset-3\" data-notify=\"container\"><i class=\"material-icons\" data-notify=\"icon\">notifications</i><button type = \"button\" aria-hidden=\"true\" class=\"close\"><i class=\"material-icons\">close</i></button><span data-notify=\"message\">Insert Error!.</span></div>";
            }
            return(View());
        }
Ejemplo n.º 5
0
        public HttpResponseMessage UploadImage()
        {
            string imageName  = null;
            var    httRequest = HttpContext.Current.Request;
            //Upload Image
            var postedFile = httRequest.Files["Image"];

            //Create custom filename
            imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-");
            imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName);
            var filePath = HttpContext.Current.Server.MapPath("~/Image/" + imageName);

            postedFile.SaveAs(filePath);

            //Save to DB
            using (DatingAppEntities db = new DatingAppEntities())
            {
                image image = new image()
                {
                    ImageCaption = httRequest["ImageCaption"],
                    ImageName    = imageName
                };
                db.image.Add(image);
                db.SaveChanges();
            }
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
Ejemplo n.º 6
0
        public IHttpActionResult Putimage(int id, image image)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != image.Id)
            {
                return(BadRequest());
            }

            db.Entry(image).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!imageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 7
0
        public List <ThemeModel> getThemes()
        {
            List <ThemeModel> list = new List <ThemeModel>();

            using (var db = base.getDatabase())
            {
                Sql thsql     = new Sql("SELECT *  FROM `theme`  ");
                var themelist = db.Fetch <theme>(thsql);
                for (int i = 0; i < themelist.Count; i++)
                {
                    ThemeModel tmodel = new ThemeModel();
                    tmodel.id           = themelist[i].id;
                    tmodel.head_img_id  = themelist[i].head_img_id;
                    tmodel.name         = themelist[i].name;
                    tmodel.topic_img_id = themelist[i].topic_img_id;
                    thsql = new Sql("SELECT *  FROM  image where id = @0", themelist[i].topic_img_id);
                    image      imagelist = db.FirstOrDefault <image>(thsql);
                    ImageModel imodel    = new ImageModel();
                    imodel.id       = imagelist.id;
                    imodel.url      = imagelist.url;
                    tmodel.banImage = imodel;
                    tmodel.tempUrl  = "https://localhost:44390/images" + imagelist.url;

                    list.Add(tmodel);
                }
            }

            return(list);
        }
Ejemplo n.º 8
0
    //-----------------------------------------------------
    public Inpaint(image input, bool[,] mask, int radius)
    {
        // initial image
        this.initial = new MaskedImage(input, mask);

        // patch radius
        this.radius = radius;
        int i = 0;

        // working copies
        source = new MaskedImage(initial.width, initial.height);
        source = initial;

        target = new MaskedImage(source.width, source.height);

        Debug.Log("build pyramid of images...");

        // build pyramid of downscaled images
        pyramid = new MaskedImage[12];
        this.pyramid[i] = source;

        //Debug.Log("pyramid0:"+ pyramid[0].width+"/"+pyramid[0].height);
        while(source.width>radius && source.height>radius)
        {
            source = source.downsample();
            i++;
            this.pyramid[i] = new MaskedImage(source.width, source.height);
            this.pyramid[i] = source;
        }
        maxlevel = i+1;
    }
Ejemplo n.º 9
0
        // Expert image view page
        public ActionResult ExpImageView(long?id, int?page, string sortOrder, string currentFilter, string preColumn, string sucMsg)
        {
            int userID = Convert.ToInt32(Session["UserID"] != null ? Session["UserID"].ToString() : "0"); // Convert session user id to integer for comparison and prevent from NULL

            image  img = db.images.Find(id);                                                              // Find images belong to user id in DB
            report rep = (from r in db.reports
                          where r.ImgID == id
                          select r).FirstOrDefault();     // Find reports belong to this image
            comment cmt = (from s in db.comments
                           where s.ImgID == id
                           select s).FirstOrDefault();      // Find comment belong to the image

            var view = new ImgRepCmtViewModels()            // Initialise a view model for passing into view
            {
                Image   = img,
                Report  = rep,
                Comment = cmt
            };

            //string server = db.Database.Connection.DataSource.ToString(); // Get db server name for retrieving image
            //string img_link = "http://" + server + "/" + img.ImgPath;    // Concatenate image URL
            string img_link = "~/" + img.ImgPath;

            ViewBag.link       = img_link;      // Create viewbag variable for image URL
            ViewBag.Page       = page;          // Create viewbag variable for current page
            ViewBag.Order      = sortOrder;     // Create viewbag variable for current sort
            ViewBag.Filter     = currentFilter; // Create viewbag variable for current filter
            ViewBag.PreColumn  = preColumn;     // Create viewbag variable for filtering column
            ViewBag.SuccessMsg = sucMsg;        // Create viewbag variable for comment successful message
            ViewBag.userName   = (from usr in db.users
                                  where (usr.UserID == userID)
                                  select usr.UserFName).FirstOrDefault().ToString();    // Passing user first name to view
            return(View(view));
        }
Ejemplo n.º 10
0
        public IEnumerable <ImageFullInfo> GetImgs(SearchResult searchResult, int pageNumber, int pageSize)
        {
            IEnumerable <image> allImages = dal.GetImgs();

            List <ImageFullInfo> result = new List <ImageFullInfo>();

            result.Capacity = allImages.Count();

            foreach (SearchResult.Node resultNode in searchResult.Nodes)
            {
                image im = allImages.FirstOrDefault(i => i.Id == resultNode.ImageId);

                if (im != null)
                {
                    result.Add(new ImageFullInfo(im, resultNode.Position));
                }
            }

            int toSkip = 0;

            if (pageNumber > 1)
            {
                toSkip = (pageNumber - 1) * pageSize;
            }
            return(result.OrderBy(im => im.Position.Value).Skip(toSkip).Take(pageSize).ToList());
        }
Ejemplo n.º 11
0
        public void main()
        {
            var img = new image("../dataset/lena.png"); // 画像の読み込み

            plt.imshow(img);
            plt.show();
        }
Ejemplo n.º 12
0
 public static WebResult <bool> UndoDelete(string url)
 {
     try
     {
         image currentImg = DB.images.FirstOrDefault(image => image.url == url);
         if (currentImg != null)
         {
             currentImg.isInRecycleBin = false;
         }
         DB.SaveChanges();
         return(new WebResult <bool>()
         {
             Status = true,
             Message = "Ok",
             Value = true
         });
     }
     catch (Exception e)
     {
         return(new WebResult <bool>()
         {
             Status = false,
             Message = e.Message,
             Value = false
         });
     }
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
    FullBallEffect makeNetworkMediaEffect()
    {
        image effect2 = (image)ScriptableObject.CreateInstance("image");

        effect2.master = this;
        effect2.promo(myLocalNetworkScanner.getLatestImageTexture());
        return(effect2);
    }
Ejemplo n.º 14
0
 public static void insert(image r)
 {
     using (var data = new instDataContext())
     {
         data.images.InsertOnSubmit(r);
         data.SubmitChanges();
     }
 }
Ejemplo n.º 15
0
        public ActionResult DeleteConfirmed(long id)
        {
            image image = db.images.Find(id);

            db.images.Remove(image);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
 public static void insert(image r)
 {
     using (var data = new instDataContext())
     {
         data.images.InsertOnSubmit(r);
         data.SubmitChanges();
     }
 }
Ejemplo n.º 17
0
        private static image MakeImage(ulong id_num, string modelName)
        {
            image img = new image();

            img.id   = "image_" + id_num;
            img.Item = modelName + "/" + id_num + ".png";
            return(img);
        }
Ejemplo n.º 18
0
    private int _widthFinalTexture; // Largeur de la texture voulue

    #endregion Fields

    #region Constructors

    //-----------------------------------------------------
    // Constructeur (l'image finale est 4 fois plus grande que les tailles
    // passées en paramètres : on repète la texture synthétisée 16 fois
    //  @param width La largeur de la texture synthetisée
    //  @param height La hauteur de la texture synthetisée
    public TextureSynthesizer(int width, int height)
    {
        //        super();
        _widthFinalTexture  = width;
        _heightFinalTexture = height;
        //        _in = new BufferedImage(_sampleSize, _sampleSize, BufferedImage.TYPE_INT_ARGB);
        _in = new image(_sampleSize, _sampleSize);
    }
Ejemplo n.º 19
0
 public Register()
 {
     InitializeComponent();
     Properties.Settings.Default.varname = "name";
     Properties.Settings.Default.Save();
     this.txtusername.Text = Properties.Settings.Default.varname;
     for image selection   = File open dialog.(Show dialog)
 }
        public ActionResult delete(string id)
        {
            image i = new image();

            i.img_id = int.Parse(id);
            i.delete();
            return(RedirectToAction("show"));
        }
Ejemplo n.º 21
0
        public ActionResult AdminEditCaption(int id, image img)
        {
            image image = db.images.Find(img.id);

            image.caption       = img.caption;
            db.Entry(img).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Edit", new { id }));
        }
Ejemplo n.º 22
0
 public static void delete(image r)
 {
     using (var data = new instDataContext())
     {
         var obj = data.images.Single(j => j.srno == j.srno);
         data.images.DeleteOnSubmit(obj);
         data.SubmitChanges();
     }
 }
Ejemplo n.º 23
0
        public static image ReadAndSaveFromUrl(this string url, long subdomainid, long ownerid, long contextid, PhotoType type)
        {
            var         req  = WebRequest.Create(url);
            WebResponse resp = null;

            try
            {
                resp = req.GetResponse();
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
            }

            if (resp == null)
            {
                return(null);
            }
            try
            {
                var image = new image();
                using (var repository = new TradelrRepository())
                {
                    var sd        = repository.GetSubDomain(subdomainid);
                    var extension = url.ToImageFormat().ToStringExtension();
                    var filename  = BuildFilename(ownerid, extension);
                    var handler   = new FileHandler(filename, UploadFileType.IMAGE, sd.uniqueid);

                    image.imageType = type.ToString();
                    image.subdomain = subdomainid;
                    image.contextID = contextid;
                    image.url       = handler.Save(resp.GetResponseStream());

                    repository.AddImage(image);
                    switch (type)
                    {
                    case PhotoType.PROFILE:
                        var usr = repository.GetUserById(ownerid);
                        if (usr != null)
                        {
                            usr.profilePhoto = image.id;
                        }
                        repository.Save("ReadAndSaveFromUrl:Profile");
                        break;

                    default:
                        break;
                    }
                }
                return(image);
            }
            catch (Exception ex)
            {
                Syslog.Write(ex);
                return(null);
            }
        }
Ejemplo n.º 24
0
 public static void delete(image r)
 {
     using (var data = new instDataContext())
     {
         var obj = data.images.Single(j => j.srno == j.srno);
         data.images.DeleteOnSubmit(obj);
         data.SubmitChanges();
     }
 }
Ejemplo n.º 25
0
        public static void Main(string[] args)
        {
            var sw    = Stopwatch.StartNew();
            var image = new image(args[0]);

            image.grayscale();
            image.save("gray_" + Path.GetFileName(args[0]));
            Console.WriteLine(sw.Elapsed);
        }
Ejemplo n.º 26
0
        public ActionResult Update()
        {
            var           imagejson = Request["json"];
            image         data      = JsonConvert.DeserializeObject <image>(imagejson);
            Businesslogic bl        = new Businesslogic();

            bl.Update(data);
            return(null);
        }
Ejemplo n.º 27
0
        public void Save(string fileName, string guid)
        {
            image img = new image();

            img.filename = fileName;
            img.guid     = guid;
            db.image.Add(img);
            db.SaveChanges();
        }
Ejemplo n.º 28
0
        // GET: Admin/Edit/5
        public ActionResult Edit(long?id, int?page, string sortOrder, string currentFilter, string preColumn)
        {
            int userID = Convert.ToInt32(Session["UserID"] != null ? Session["UserID"].ToString() : "0");   // Convert session user id to integer for comparison and prevent from NULL

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            image image = db.images.Find(id);

            if (image == null)
            {
                return(HttpNotFound());
            }

            var Patient = db.patients.Select(p => new SelectListItem                                // Create patient selection list
            {
                Text  = p.PatFName + " " + p.PatLName,
                Value = p.PatID.ToString()
            });
            var Creator = db.users.Where(p => p.UserRoleID == 1).Select(p => new SelectListItem     // Create image creator selection list
            {
                Text  = p.UserFName + " " + p.UserLName,
                Value = p.UserID.ToString()
            });
            var DocUser = db.users.Where(p => p.UserRoleID == 2).Select(p => new SelectListItem     // Create doctor selection list
            {
                Text  = p.UserFName + " " + p.UserLName,
                Value = p.UserID.ToString()
            });
            var ExpUser = db.users.Where(p => p.UserRoleID == 3).Select(p => new SelectListItem     // Create expert selection list
            {
                Text  = p.UserFName + " " + p.UserLName,
                Value = p.UserID.ToString()
            });

            //string server = db.Database.Connection.DataSource.ToString(); // Get db server name for retrieving image
            //string img_link = "http://" + server + "/" + image.ImgPath;   // Concatenate image URL
            string img_link = "~/" + image.ImgPath;

            ViewBag.link          = img_link;                                                                        // Create viewbag variable for image URL
            ViewBag.Page          = page;                                                                            // Create viewbag variable for current page
            ViewBag.CurrentSort   = sortOrder;                                                                       // Create viewbag variable for current sort
            ViewBag.CurrentFilter = currentFilter;                                                                   // Create viewbag variable for current filter
            ViewBag.PreColumn     = preColumn;                                                                       // Create viewbag variable for filtering column
            ViewBag.ImgPatID      = new SelectList(Patient.OrderBy(p => p.Text), "Value", "Text", image.ImgPatID);   // Pass the patient selection list with default value
            ViewBag.ImgDocID      = new SelectList(DocUser.OrderBy(p => p.Text), "Value", "Text", image.ImgDocID);   // Pass the doctor selection list with default value
            ViewBag.ImgExpID      = new SelectList(ExpUser.OrderBy(p => p.Text), "Value", "Text", image.ImgExpID);   // Pass the expert selection list with default value
            ViewBag.ImgCreator    = new SelectList(Creator.OrderBy(p => p.Text), "Value", "Text", image.ImgCreator); // Pass the creator selection list with default value
            ViewBag.ImgStatus     = new SelectList(db.imagestatus, "ImgStatID", "ImgStatusName", image.ImgStatus);   // Pass image status selection list with default value
            ViewBag.userName      = (from usr in db.users
                                     where (usr.UserID == userID)
                                     select usr.UserFName).FirstOrDefault().ToString(); // Passing user first name to view

            return(View(image));
        }
Ejemplo n.º 29
0
        // GET: Home/Details/5
        public ActionResult Detail(int id)
        {
            if (user != null)
            {
                ViewBag.kullanici = "kullanici";
            }
            image img = datas.images.Where(f => f.id == id).FirstOrDefault();

            return(View(img));
        }
Ejemplo n.º 30
0
 public static void update(image r)
 {
     using (var data = new instDataContext())
     {
         var obj = data.images.Single(j => j.srno == r.srno);
         obj.picpath = r.picpath;
         obj.comments = r.comments;
         data.SubmitChanges();
     }
 }
Ejemplo n.º 31
0
    static void Main()
    {
        image newimage = new image("newImage", "E", 1, 4, 2017, "image");

        newimage.printData();

        text newtext = new text("newtext", "E", 1, 4, 2017, "text");

        newtext.printData();
    }
Ejemplo n.º 32
0
 public ActionResult Delete(int id)
 {
     using (UploadImageContext db = new UploadImageContext())
     {
         image img = db.images.Where(x => x.Id == id).FirstOrDefault <image>();
         db.images.Remove(img);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted successfully!!!" }, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 33
0
        string GetFileByString(image im)
        {
            Image    image = Image.FromFile(im.Path);
            Encoding enc   = Encoding.Default;

            System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
            image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] b = memoryStream.ToArray();
            return(enc.GetString(b));
        }
Ejemplo n.º 34
0
 public static void update(image r)
 {
     using (var data = new instDataContext())
     {
         var obj = data.images.Single(j => j.srno == r.srno);
         obj.picpath  = r.picpath;
         obj.comments = r.comments;
         data.SubmitChanges();
     }
 }
Ejemplo n.º 35
0
        public void Update(image i)
        {
            var fetchedimage = this.db.image.Where(p => p.guid == i.guid && p.id == i.id).FirstOrDefault();

            fetchedimage.rate     = i.rate;
            fetchedimage.selected = i.selected;
            fetchedimage.comment  = i.comment;

            this.db.SaveChanges();
        }
Ejemplo n.º 36
0
        public static image Createimage(int ID, int fkey_id_files, string description, byte[] img)
        {
            image image = new image();

            image.id            = ID;
            image.fkey_id_files = fkey_id_files;
            image.description   = description;
            image.img           = img;
            return(image);
        }
Ejemplo n.º 37
0
 public Picture Download(int imageId)
 {
     using (ImageDataClassesDataContext db = new ImageDataClassesDataContext())
     {
         image selectedImage = db.images.Where(r => r.imagesid == imageId) as image;
         return(new Picture {
             ImageID = selectedImage.imagesid, ImageTitle = selectedImage.imagename, ImageStream = selectedImage.imagecontent.ToArray()
         });
     }
 }
Ejemplo n.º 38
0
    //-----------------------------------------------------
    public MaskedImage(MaskedImage copy)
    {
        this.im = copy.im;
        width = copy.width;
        height = copy.height;
        this.mask = new bool[width,height];

        for(int y=0;y<height;y++)
            for(int x=0;x<width;x++)
                mask[x,y] = copy.mask[x,y];
    }
        public ColorfulRestProperty(object json)
        {
            var colorData = (ColorfulJsonParser)json;

            HexValue = new hexvalue(colorData.Hex);
            RGB = new rgb(colorData.RGB);
            HSL = new hsl(colorData.HSL);
            HSV = new hsv(colorData.HSV);
            CMYK = new cmyk(colorData.CMYK);
            XYZ = new xyz(colorData.XYZ);
            Name = new name(colorData.Name);
            Image = new image(colorData.Image);
            Contrast = colorData.Contrast.value;
        }
Ejemplo n.º 40
0
    //-----------------------------------------------------
    void Start()
    {
        tex = new Texture2D(0,0,TextureFormat.RGB24, false);
        tex = (Texture2D) GameObject.Find("Background/backgroundImage").GetComponent<GUITexture>().texture;
        width = tex.width;
        height = tex.height;
        image = new image(width, height);
        image.setPixels(tex);

        // Générer le tableau
        mask = new bool[width,height];  // Note : les bool sont initialisés à false par défaut

        for(int i=0; i<m_inputMask.Count; i++)
            mask[m_inputMask[i].GetX(), m_inputMask[i].GetY()] = true;
        //      for(int y=0;y<height;y++)                           // Texture2D remplacée par une liste de MaskPix
        //          for(int x=0;x<width;x++)
        //              mask[x,y]=(masktex.GetPixel(x,y).r == 1);

        //		DestroyImmediate(masktex); // TODO libérer la mémoire de masktex

        //        for(int y=0;y<height;y++)     // KS : commenté, aucune différence apparente.
        //        {
        //			for(int x=0;x<width;x++)
        //            {
        //				if (mask[x,y])
        //                {
        //					image.set_r(255,x,y);
        //					image.set_g(0,x,y);
        //					image.set_b(0,x,y);
        //				}
        //			}
        //		}
        Debug.Log("mask created");

        // display input with red area
        //		GameObject.Find("/Background/backgroundImage").guiTexture.texture = image.getTexture(); // KS : utile pour debug seulement

        inpainting = new Inpaint(image, mask, 2);         // initialisation inpainting

        scaleLevel = inpainting.maxlevel-1;
        Debug.Log(scaleLevel+" levels");
    }
Ejemplo n.º 41
0
    //-----------------------------------------------------
    public static void SynthesizeFromBaseTex(Texture2D baseTex)
    {
        image i = new image(c_sampleSize, c_sampleSize);
        i.setPixels(baseTex);

        // -- Synthétisation de la texture à partir de l'échantillon --
        TextureSynthesizer ts = new TextureSynthesizer(128, 128);
        i = ts.synthesize(i);
        s_synthTex = i.getTextureRGB();
        s_synthTex.Apply();
        //            byte[] bytes = m_synthTex.EncodeToPNG();   // Sauvegarde en fichier
        //            System.IO.File.WriteAllBytes(Application.dataPath+"/Resources/grass/synth/grassSynth0.png", bytes);

        // -- Enregistrer la texture et l'appliquer aux plans de gazon --
        GameObject.Find("grassSkybox").GetComponent<GrassHandler>().AddSynthTex(s_synthTex,
                                                                                     baseTex, true);
        // -- Modifier l'interface (devrait être fait dans le contrôleur) --
        //          GameObject.Find("MainScene").GetComponent<GUIMenuMain>().SetHideAll(false);
        //        GameObject.Find("mainCam").transform.camera.cullingMask = m_camMaskBk;
        GameObject.Find("MainScene").GetComponent<PleaseWaitUI>().SetDisplayIcon(false);
    }
Ejemplo n.º 42
0
    //-----------------------------------------------------
    // Copie d'une sous-matrice:
    public image(image nouveau, int xOffset, int yOffset, int w, int h)
    {
        //image im = new image(nouveau);
        this.width = w;
        this.height = h;
        this.r = new int[w,h];
        this.g = new int[w,h];
        this.b = new int[w,h];
        this.a = new int[w,h];

        tex = null;
        tex = new Texture2D(w, h);

        for(int x = xOffset ; x < xOffset+w ; x++)
        {
            for(int y = yOffset ; y < yOffset+h ; y++)
            {
                r[x-xOffset,y-yOffset] = nouveau.r[x,y];
                g[x-xOffset,y-yOffset] = nouveau.g[x,y];
                b[x-xOffset,y-yOffset] = nouveau.b[x,y];
                a[x-xOffset,y-yOffset] = nouveau.a[x,y];
            }
        }
    }
Ejemplo n.º 43
0
    //-----------------------------------------------------
    // Copie d'une autre matrice:
    public image(image nouveau)
    {
        //image im = new image(nouveau);
        this.width = nouveau.width;
        this.height = nouveau.height;
        this.r = new int[width,height];
        this.g = new int[width,height];
        this.b = new int[width,height];
        this.a = new int[width,height];

        tex = null;
        tex = new Texture2D(width, height);

        for(int x=0; x<width; x++)
        {
            for(int y=0; y<height; y++)
            {
                r[x,y]= nouveau.r[x,y];
                g[x,y]= nouveau.g[x,y];
                b[x,y]= nouveau.b[x,y];
                a[x,y]= nouveau.a[x,y];
            }
        }
    }
Ejemplo n.º 44
0
    /**
      * Les lignes suivantes
      * @param in
      * @param out
      */
    private void otherLine(image imgIn, image imgOut)
    {
        int[] rgbOutH = new int[_widthBorder*_heightBorder];
        //Pour les bords du haut
        int[] rgbOutW = new int[_widthBorder*_heightBorder];

        int[] rgbOutHD = new int[_widthBorder*_heightBorder];

        //Tableau qui contiendra toutes les distances (en se positionnant en chaque point de In)
        float[] tabDistanceH = new float[_widthAnalysis*_heightAnalysis];
        float[] tabDistanceW = new float[_widthAnalysis*_heightAnalysis];

        float[] tabDistanceHD = new float[_widthAnalysis*_heightAnalysis];
        //Liste qui contiendra les index (numeros de pixels) dont la distance avec le dernier patch collé est
        //inferieure à la distance max
        float[] tabDistInf  = new float[200];
        int[] tabDistInfIndex  = new int[tabDistInf.Length];

        for (int i = 0; i < tabDistInf.Length; i++)
        {
            tabDistInf[i] = float.MaxValue;
            tabDistInfIndex[i] = -1;
        }

        //Les valeurs rgb du bord de _out (à droite)

        //        out.getRGB(((_nbPatchPasted)*(_patchSize-_widthBorder)),  nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder, rgbOutH, 0, _widthBorder);
        imgOut.getRGB(rgbOutH, ((_nbPatchPasted)*(_patchSize-_widthBorder)),
                      nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder);
        //        out.getRGB(0,  nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder, rgbOutHD, 0, _widthBorder);
        imgOut.getRGB(rgbOutHD, 0,  nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder);

        //Les valeurs rgb du bord de out (en bas)
        //        out.getRGB((_nbPatchPasted)*(_patchSize-_widthBorder), nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder, rgbOutW, 0, _heightBorder);
        imgOut.getRGB(rgbOutW, (_nbPatchPasted)*(_patchSize-_widthBorder),
                      nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder);

        float dMax = 0;
        if(_nbPatchPasted == _nbPatchPerLine-1)
            dMax = get_dMax(rgbOutH) + get_dMax(rgbOutW) + get_dMax(rgbOutHD);
        else
            dMax = get_dMax(rgbOutH) + get_dMax(rgbOutW);

        int index = 0;
        int distMin = int.MaxValue;
        int indexMin = int.MaxValue;

        //Parcours de l image (moins les deux bords en bas et à droite)
        for (int i=0; i<_widthAnalysis*_heightAnalysis; i+=_pasBalayage)
        {
            //L ensemble des distances en positionnant le patch sur chaque pixel de l image
            tabDistanceH[index]  = distance(_tabInH[index], rgbOutH);

            tabDistanceHD[index] = distance(_tabInHD[index], rgbOutHD);

            tabDistanceW[index]  = distance(_tabInW[index], rgbOutW);

            //On fait la somme des deux distances
            tabDistanceW[index] += tabDistanceH[index];

            if(_nbPatchPasted == _nbPatchPerLine-1)
                tabDistanceW[index] += tabDistanceHD[index];

            if(tabDistanceW[index] < dMax)
            {
                float distmax = -1;
                int indexTabdistInf = -1;

                for(int k=0; k<tabDistInf.Length; k++)
                {
                    if(tabDistanceW[index] < tabDistInf[k])
                    {
                        if(tabDistInf[k] > distmax)
                        {
                            distmax = tabDistInf[k];
                            indexTabdistInf = k;
                        }
                    }
                }
                if(indexTabdistInf!=-1)
                {
                    tabDistInfIndex[indexTabdistInf] = index;
                    tabDistInf[indexTabdistInf] = tabDistanceW[index];
                }
            }

            //Distance min
            if(tabDistanceW[index]<distMin)
            {
                distMin = (int)tabDistanceW[index];
                indexMin = index;
            }
            index=index+_pasBalayage;
        }

        //On ajoute la plus petite distance si aucune n etait inférieure à  dMax
        int l = 0;
        while(l<tabDistInf.Length && tabDistInfIndex[l]!=-1) l++;

        if(tabDistInf[0]==float.MaxValue)   //tableau vide
        {
            tabDistInf[0] = distMin;
            tabDistInfIndex[0] = indexMin;
            l = 1;
        }

        //Un index dans la liste des distance inférieures au seuil (aleatoirement)
        System.Random r = new System.Random();
        int random = r.Next(l);

        //On copie le patch choisi aleatoirement dans l image out
        //        Graphics2D g2d = (Graphics2D)out.getGraphics();
        //Le patch qu on colle dans Out
        image patch = null;

        patch = imgIn.getSubImage((tabDistInfIndex[random]%_widthAnalysis),
                                tabDistInfIndex[random]/_widthAnalysis, _patchSize, _patchSize);

        //Le tableau de pix du bord du patch
        int[] rgbPatchBorderH = new int[_patchSize*_patchSize];
        int[] rgbPatchBorderW = new int[_patchSize*_patchSize];
        //        patch.getRGB(0, 0, _widthBorder, _heightBorder, rgbPatchBorderH, 0, _widthBorder);
        patch.getRGB(rgbPatchBorderH, 0, 0, _widthBorder, _heightBorder);
        //        patch.getRGB(0, 0, _heightBorder, _widthBorder, rgbPatchBorderW, 0, _heightBorder);
        patch.getRGB(rgbPatchBorderW, 0, 0, _heightBorder, _widthBorder);

        //On colle le patch par dessus le dernier patch collé dans Out
        //        g2d.drawImage(patch,_nbPatchPasted*(_patchSize-_widthBorder),  nbLinesDone*(_patchSize-_widthBorder), null);
        imgOut.setPixels(patch, _nbPatchPasted*(_patchSize-_widthBorder), nbLinesDone*(_patchSize-_widthBorder));

        //On arrange la liaison entre les deux patch
        //        out = borderH(rgbOutH, rgbPatchBorderH, out);
        imgOut = borderH(rgbOutH, rgbPatchBorderH, imgOut);
        //        out = borderW(rgbOutW, rgbPatchBorderW, out, false);
        imgOut = borderW(rgbOutW, rgbPatchBorderW, imgOut, false);

        _nbPatchPasted++;
    }
Ejemplo n.º 45
0
 object get_value(string path, image img)
 {
     TreeNode result = FindByFullPath(path, img.node);
     if (result == null) { return null; }
     else { return result.Tag; }
 }
Ejemplo n.º 46
0
    /**
      *
      * @param rgb1 patch deja collé dans out
      * @param rgb2 patch de in
      * @param out
      * @return out
      */
    private image borderH(int[] rgb1, int[] rgb2, image imgOut)
    {
        int[] rgbRes = new int [_widthBorder*_heightBorder];
        for(int i=0; i<rgb1.Length-3; i++)
        {
            rgbRes[i] = (  (int)(0.75*((rgb1[i] >> 16) & 0xff ) + 0.25*((rgb2[i] >> 16) & 0xff))<<16  //1ere colonne
                         | (int)(0.75*((rgb1[i] >> 8)  & 0xff ) + 0.25*((rgb2[i] >> 8)  & 0xff))<<8
                         | (int)(0.75*( rgb1[i]        & 0xff ) + 0.25*( rgb2[i]        & 0xff))
                         | (int)((rgb1[i] >> 24) & 0xff )<<24);
            i++;
            rgbRes[i] = (  (int)(0.5*((rgb1[i] >> 16) & 0xff ) + 0.5*((rgb2[i] >> 16) & 0xff))<<16
                         | (int)(0.5*((rgb1[i] >> 8)  & 0xff ) + 0.5*((rgb2[i] >> 8)  & 0xff))<<8
                         | (int)(0.5*( rgb1[i]        & 0xff ) + 0.5*( rgb2[i]        & 0xff))
                         | (int)((rgb1[i] >> 24) & 0xff )<<24);
            i++;
            rgbRes[i] = (  (int)(0.5*((rgb1[i] >> 16) & 0xff ) + 0.5*((rgb2[i] >> 16) & 0xff))<<16
                         | (int)(0.5*((rgb1[i] >> 8)  & 0xff ) + 0.5*((rgb2[i] >> 8)  & 0xff))<<8
                         | (int)(0.5*( rgb1[i]        & 0xff ) + 0.5*( rgb2[i]        & 0xff))
                         | (int)((rgb1[i] >> 24) & 0xff )<<24);
            i++;
            rgbRes[i] = (  (int)(0.25*((rgb1[i] >> 16) & 0xff ) + 0.75*((rgb2[i] >> 16) & 0xff))<<16
                         | (int)(0.25*((rgb1[i] >> 8)  & 0xff ) + 0.75*((rgb2[i] >> 8)  & 0xff))<<8
                         | (int)(0.25*( rgb1[i]        & 0xff ) + 0.75*( rgb2[i]        & 0xff))
                         | (int)((rgb1[i] >> 24) & 0xff )<<24);
        }

        //        out.setRGB(_nbPatchPasted*(_patchSize-_widthBorder), nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder, rgbRes, 0, _widthBorder);
        imgOut.setRGB(rgbRes, _nbPatchPasted*(_patchSize-_widthBorder),
                      nbLinesDone*(_patchSize-_widthBorder), _widthBorder, _heightBorder, _widthBorder);

        return imgOut;
    }
Ejemplo n.º 47
0
        Bitmap render_layer(TreeNode layer_node, int height, int width, int centerX, int centerY, wz_file f, image map_img)
        {
            TreeNode t_node, t_node2;
            int x = 0, y = 0, z = 0, i = 0;
            vector v		= new vector(0, 0);
            bool flipped	= false;
            SortedList<int, List<tile>> z_layer_objects	= new SortedList<int, List<tile>>();
            SortedList<int, List<tile>> z_layer_tiles	= new SortedList<int, List<tile>>();
            Bitmap bMap		= new Bitmap(width, height);
            Graphics gMap	= Graphics.FromImage(bMap);
            image tile_img, obj_img;
            string tS_tile	= "";
            TreeNode		found_node;

            toolStripStatusLabel1.Text = "Getting Objects...";

            t_node = FindNode(layer_node, "obj");
            for (i = 0; i < t_node.Nodes.Count; i++) {
                t_node2 = FindNode(t_node, i.ToString());

                if (t_node2 != null) {
                    found_node		= FindNode(t_node2, "x"); if (found_node != null) { x = (int)found_node.Tag; }
                    found_node		= FindNode(t_node2, "y"); if (found_node != null) { y = (int)found_node.Tag; }
                    found_node		= FindNode(t_node2, "z"); if (found_node != null) { z = (int)found_node.Tag; }
                    found_node		= FindNode(t_node2, "f"); if (found_node != null) { flipped = System.Convert.ToBoolean(found_node.Tag); }
                    string oS_obj	= (string)(FindNode(t_node2, "oS").Tag);
                    string l0_obj	= (string)(FindNode(t_node2, "l0").Tag);
                    string l1_obj	= (string)(FindNode(t_node2, "l1").Tag);
                    string l2_obj	= (string)(FindNode(t_node2, "l2").Tag);

                    obj_img			= FindImage("Map\\Obj\\" + oS_obj + ".img",treeView1.Nodes[0]);
                    object png_uol	= get_value(l0_obj + "\\" + l1_obj + "\\" + l2_obj + "\\0", obj_img);

                    PNG png;
                    if (png_uol.GetType().Name == "UOL") {
                        MessageBox.Show("UOL obj");
                        TreeNode uol_node		= FindNode(FindNode(FindNode(FindNode(obj_img.node, l0_obj), l1_obj), l2_obj), "0");
                        png						= (PNG)resolve_UOL((UOL)png_uol, uol_node).Tag;
                    }
                    else { png = (PNG)png_uol; }

                    found_node	= FindByFullPath(l0_obj + "\\" + l1_obj + "\\" + l2_obj + "\\0", obj_img.node);
                    found_node	= FindNode(found_node, "origin"); if (found_node != null) { v = (vector)found_node.Tag; }

                    if (z_layer_objects.ContainsKey(z)) {
                        z_layer_objects[z].Add(new tile(extract_png(png, f), x, y, v.x, v.y, flipped));
                    } else {
                        z_layer_objects.Add(z, new List<tile>());
                        z_layer_objects[z].Add(new tile(extract_png(png, f), x, y, v.x, v.y, flipped));
                    }
                }
            }

            toolStripStatusLabel1.Text = "Getting Tiles...";
            t_node = FindNode(layer_node, "info");
            if (t_node.Nodes.Count > 0) { tS_tile = (string)(FindNode(t_node, "tS").Tag); }

            t_node = FindNode(layer_node, "tile");
            if ((t_node.Nodes.Count > 0)) {
                for (i = 0; i < t_node.Nodes.Count; i++) {
                    t_node2 = FindNode(t_node, i.ToString());
                    if (t_node2 != null) {
                        found_node	= FindNode(t_node2, "x");	if (found_node != null) { x = (int)found_node.Tag; }
                        found_node	= FindNode(t_node2, "y");	if (found_node != null) { y = (int)found_node.Tag; }
                        found_node	= FindNode(t_node2, "zM");	if (found_node != null) { z = (int)found_node.Tag; }

                        string u_tile = "", no_tile = "";

                        found_node	= FindNode(t_node2, "u");	if (found_node != null) { u_tile	= (string)(found_node.Tag); }
                        found_node	= FindNode(t_node2, "no");	if (found_node != null) { no_tile	= found_node.Tag.ToString();}

                        tile_img	= FindImage("Map\\Tile\\" + tS_tile + ".img", treeView1.Nodes[0]);
                        PNG png		= (PNG)get_value(u_tile + "\\" + no_tile, tile_img);
                        found_node	= FindByFullPath(u_tile + "\\" + no_tile , tile_img.node);
                        found_node 	= FindNode(found_node, "origin"); if (found_node != null) { v = (vector)found_node.Tag; }

                        found_node	= FindByFullPath(u_tile + "\\" + no_tile, tile_img.node);
                        found_node 	= FindNode(found_node, "z");
                        if (found_node != null) { z += (int)found_node.Tag; }

                        if (z_layer_tiles.ContainsKey(z)) {
                            z_layer_tiles[z].Add(new tile(extract_png(png, f), x, y, v.x, v.y, flipped));
                        } else {
                            z_layer_tiles.Add(z, new List<tile>());
                            z_layer_tiles[z].Add(new tile(extract_png(png, f), x, y, v.x, v.y, flipped));
                        }
                    }
                }
            }

            toolStripStatusLabel1.Text = "Adding Objects";
            foreach (KeyValuePair<int, List<tile>> z_layer in z_layer_objects) {
                foreach (tile t in z_layer.Value) {
                    if (!t.flip) {
                        gMap.DrawImage(t.pic, t.x + centerX - t.ox, t.y + centerY - t.oy);
                    } else {
                        Bitmap flippedBmp = t.pic;
                        flippedBmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        gMap.DrawImage(flippedBmp, t.x + centerX + t.ox - flippedBmp.Width, t.y + centerY - t.oy);
                    }
                }
            }

            toolStripStatusLabel1.Text = "Adding Tiles...";
            foreach (KeyValuePair<int, List<tile>> z_layer in z_layer_tiles) {
                foreach (tile t in z_layer.Value) {
                    if (!t.flip) {
                        gMap.DrawImage(t.pic, t.x + centerX - t.ox, t.y + centerY - t.oy);
                        Console.WriteLine(String.Format("set position X {0} {1}",t.x,t.ox));
                        Console.WriteLine(String.Format("set position Y {0} {1}", t.y, t.oy));
                        Console.WriteLine(String.Format("set map {0} {1}", centerX, centerY));
                    } else {
                        Bitmap flippedBmp = t.pic;
                        flippedBmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                        gMap.DrawImage(flippedBmp, t.x + centerX + t.ox - flippedBmp.Width, t.y + centerY - t.oy);
                    }
                }
            }

            return bMap;
        }
Ejemplo n.º 48
0
 public ImageFullInfo(image imgEntity, double position)
     : this(imgEntity)
 {
     this.Position = position;
 }
Ejemplo n.º 49
0
 public ImageFullInfo(image imgEntity)
 {
     Contract.Requires(imgEntity != null);
     this.imgEntity = imgEntity;
     ComputeFilePath();
 }
Ejemplo n.º 50
0
    //-----------------------------------------------------
    // Fonction qui génère une image 4 fois plus grande que l image d entrée
    // en effectuant des miroirs par rapport à l image d entrée
    //  @param image L'image d entrée
    //  @return duplicateImage L'image dupliquée
    //    private BufferedImage duplicateSample(BufferedImage image)
    private image duplicateSample(image img)
    {
        int[] rgb  = new int[(_sampleSize/2)*(_sampleSize/2)];
        //        rgb = image.getRGB(_sampleSize/2, _sampleSize/2, rgb, 0, _sampleSize/2);
        rgb = img.getRGB(rgb);

        rgb = removeArtifacts(rgb);         // enlève les pixels trop eloignés de la moyenne du sample

        //        image.setRGB(0, 0, _sampleSize/2, _sampleSize/2, rgb, 0, _sampleSize/2);
        img.setRGB(rgb);                  // image sans artefacts

        // -- Miroir par rap à Y --
        //        BufferedImage _inYmirror = new BufferedImage(_sampleSize/2, _sampleSize/2, BufferedImage.TYPE_INT_ARGB);
        image _inYmirror = new image(img); // Copie
        _inYmirror.MirrorY();

        //        BufferedImage _in4 = new BufferedImage(2*image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        image _in4 = new image(2*img.Width(), img.Height());
        //        _in4.getGraphics().drawImage(image, 0, 0, null);
        _in4.setPixels(img);
        //        _in4.getGraphics().drawImage(_inYmirror, _in4.getWidth()/2, 0, null);
        _in4.setPixels(_inYmirror, _in4.Width()/2, 0);        // TODO Vérifier si le résultat est correct

        // -- Miroir par rap à X --
        //        BufferedImage in5 = new BufferedImage(_sampleSize, _sampleSize/2, BufferedImage.TYPE_INT_ARGB);
        image in5 = new image(_in4);
        in5.MirrorX();

        //        BufferedImage duplicateImage = new BufferedImage(_sampleSize, _sampleSize, BufferedImage.TYPE_INT_ARGB);
        image duplicateImage = new image(_sampleSize, _sampleSize);
        //        duplicateImage.getGraphics().drawImage(_in4, 0, 0, null);
        duplicateImage.setPixels(_in4);
        //        duplicateImage.getGraphics().drawImage(in5, 0, _sampleSize/2, null);
        duplicateImage.setPixels(in5, 0, _sampleSize/2);

        return duplicateImage;
    }
Ejemplo n.º 51
0
        void full_extract_img(image img, TreeNode node, string path)
        {
            foreach(TreeNode child in node.Nodes) {
                StringBuilder name = new StringBuilder(path);
                name.Append(child.Text);
                if(child.Tag == null) { full_extract_img(img, child, name.Append(".").ToString()); continue; }

                switch(child.Tag.GetType().Name) {
                    case "PNG":
                        name.Append(".png");
                        name.Replace(":", "_", 3, name.Length-3);
                        Directory.CreateDirectory(Path.GetDirectoryName(name.ToString()));
                        extract_png((PNG)child.Tag, WZ.wz_files[img.wz_f]).Save(name.ToString());
                        break;

                    case "MP3":
                        name.Append(".mp3");
                        name.Replace(":", "_", 3, name.Length-3);
                        saveMP3((MP3)child.Tag, name.ToString(), WZ.wz_files[img.wz_f]);
                        break;

                    default:
                        full_extract_img(img, child, name.Append('.').ToString());
                        break;
                }
            }
        }
Ejemplo n.º 52
0
    public void setPixels(image tab, int xOffset, int yOffset)
    {
        int h, w;       // Détecter les plus petites dimensions entre l'image donnée et "this", pour
        //        if(tab.height >= this.height && tab.width >= this.width) // éviter les "out of array exception"
        //             { h = this.height;
        //               w = this.width; }
        //        else if(tab.height >= this.height && tab.width < this.width)
        //             { h = this.height;
        //               w = tab.width;  }
        //        else if(tab.height < this.height && tab.width >= this.width)
        //             { h = tab.height;
        //               w = this.width; }
        //        else { h = tab.height;
        //               w = tab.width;  }

        for(int x = 0 ; x < tab.width ; x++)
        {
            for(int y = 0 ; y < tab.height ; y++)
            {
                this.set_r(tab.get_r(x,y), x+xOffset, y+yOffset);
                this.set_g(tab.get_g(x,y), x+xOffset, y+yOffset);
                this.set_b(tab.get_b(x,y), x+xOffset, y+yOffset);
            }
        }
    }
Ejemplo n.º 53
0
 public void setPixels(image tab)
 {
     setPixels(tab, 0, 0);
 }
Ejemplo n.º 54
0
 /* Différence maximum entre toutes les composantes de tous les pixels des images T1 et T2 */
 public static int DistanceMax(image T1, image T2, image mask)
 {
     int max = 0;
     int diff;
     for (int x = 0; x < T1.width; x++)
     {
         for(int y=0; y < T1.height;y++)
         {
             if(mask.get_r(x,y) < 0.5f)
             {
                     diff = Mathf.Abs(T1.get_r(x,y) - T2.get_r(x,y));
                 if(diff > max) max = diff;
                     diff = Mathf.Abs(T1.get_g(x,y) - T2.get_g(x,y));
                 if(diff > max) max = diff;
                     diff = Mathf.Abs(T1.get_b(x,y) - T2.get_b(x,y));
                 if(diff > max) max = diff;
             }
         }
     }
     return max;
 }
Ejemplo n.º 55
0
        /*************
        MAP RENDERER
        *************/
        bool render_map(image map_img, wz_file f)
        {
            Application.DoEvents();

            int map_width = 0, map_height = 0, map_centerX = 0, map_centerY = 0;
            List<Bitmap> layers = new List<Bitmap>();
            TreeNode found_node;
            image t_img;

            toolStripStatusLabel1.Text = "Getting map size...";
            try {
                map_width	= (int)get_value("miniMap\\width",		map_img);
                map_height	= (int)get_value("miniMap\\height",		map_img);
                map_centerX	= (int)get_value("miniMap\\centerX",	map_img);
                map_centerY	= (int)get_value("miniMap\\centerY", 	map_img);
            } catch {
                int map_top = 0, map_bottom = 0, map_left = 0, map_right = 0;

                try {
                    map_top		= (int)get_value("info\\VRTop",		map_img);
                    map_bottom	= (int)get_value("info\\VRBottom",	map_img);
                    map_left	= (int)get_value("info\\VRLeft",	map_img);
                    map_right	= (int)get_value("info\\VRRight",	map_img);

                    map_width	= map_right		- map_left;
                    map_height	= map_bottom	- map_top;
                    map_centerX	= -map_left;
                    map_centerY	= -map_top;
                } catch {
                    MessageBox.Show("Sorry, but this map cannot be rendered due to size information lacking. Maybe this map might be rendered in the future.", "Impossible to render this map", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return false;
                }
            }

            foreach (TreeNode n in map_img.node.Nodes) {
                if ("0123456789".IndexOf(n.Text.Substring(0), 0) != -1) {
                    layers.Add(render_layer(n, map_height, map_width, map_centerX, map_centerY, f, map_img));
                    Application.DoEvents();
                }
            }

            Bitmap		finalMap	= new Bitmap(map_width, map_height);
            Graphics	fMap		= Graphics.FromImage(finalMap);

            toolStripStatusLabel1.Text = "Creating picture...";
            switch (lstRenders.SelectedIndex) {
                case 0:
                    fMap.FillRectangle(Brushes.Transparent, 0, 0, map_width, map_height);
                    break;

                case 1:
                    fMap.FillRectangle(Brushes.Black, 0, 0, map_width, map_height);
                    break;

                case 2:
                    fMap.FillRectangle(Brushes.White, 0, 0, map_width, map_height);
                    break;
            }

            foreach (Bitmap bmp in layers) { fMap.DrawImage(bmp, 0, 0); }

            //Portals
            if (chkPortalr.Checked == true) {
                toolStripStatusLabel1.Text = "Adding portals";
                TreeNode portals = FindNode(map_img.node, "portal");

                if (portals != null) {
                    image	MapHelper		= FindImage("Map\\MapHelper.img", treeView1.Nodes[0]);
                    Bitmap	portal_picture	= extract_png((PNG)get_value("portal\\game\\pv\\0", MapHelper), f);
                    foreach (TreeNode node in portals.Nodes) {
                        if ((int)FindNode(node, "pt").Tag == 2 && Convert.ToString(FindNode(node, "pn").Tag).Substring(0, 2) != "in") {
                            fMap.DrawImage(portal_picture, (int)FindNode(node, "x").Tag + map_centerX - 43, (int)FindNode(node, "y").Tag + map_centerY - 173);
                        }
                        Application.DoEvents();
                    }
                }
            }

            //Reactors
            if (chkReactorr.Checked == true) {
                toolStripStatusLabel1.Text = "Adding reactors";
                TreeNode reactors = FindNode(map_img.node, "reactor");
                if (reactors != null) {
                    if (reactors.Nodes.Count > 0){
                        foreach (TreeNode reactor in reactors.Nodes){
                            found_node = FindNode(reactor, "id");
                            if (found_node != null){
                                t_img = FindImage("Reactor\\" + (string)found_node.Tag + ".img", treeView1.Nodes[0]);
                                if (t_img != null){
                                    string link = (string)get_value("info\\link", t_img);
                                    if (link != null){
                                        t_img = FindImage("Reactor\\" + link + ".img", treeView1.Nodes[0]);
                                    }

                                    vector v = (vector)get_value("0\\0\\origin", t_img);
                                    bool flip = Convert.ToBoolean(FindNode(reactor, "f").Tag);
                                    if (!flip){
                                        fMap.DrawImage(extract_png((PNG)get_value("0\\0", t_img), WZ.wz_files[t_img.wz_f]), (int)FindNode(reactor, "x").Tag + map_centerX - v.x, (int)FindNode(reactor, "y").Tag + map_centerY - v.y);
                                    }else{
                                        Bitmap flippedBmp = extract_png((PNG)get_value("0\\0", t_img), WZ.wz_files[t_img.wz_f]);
                                        flippedBmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                        fMap.DrawImage(flippedBmp, (int)FindNode(reactor, "x").Tag + map_centerX + v.x - flippedBmp.Width, (int)FindNode(reactor, "y").Tag + map_centerY - v.y);
                                    }
                                    Application.DoEvents();
                                }
                            }
                        }
                    }
                }
            }

            //Monsters
            if (chkMobr.Checked == true) {
                toolStripStatusLabel1.Text = "Adding monsters...";
                TreeNode monsters = FindNode(map_img.node, "life");
                if (monsters != null) {
                    if (monsters.Nodes.Count > 0) {
                        string stand_fly = "stand";
                        foreach (TreeNode life in monsters.Nodes) {
                            if ((string)FindNode(life, "type").Tag == "m") {
                                t_img = FindImage("Mob\\" + (string)FindNode(life, "id").Tag + ".img", treeView1.Nodes[0]);
                                string link = (string)get_value("info\\link", t_img);
                                while(link != null) {
                                    t_img = FindImage("Mob\\" + link + ".img", treeView1.Nodes[0]);
                                    link = (string)get_value("info\\link", t_img);
                                }

                                if (FindNode(t_img.node, "stand") == null){ stand_fly = "fly"; }

                                vector	v		= (vector)get_value(stand_fly + "\\0\\origin", t_img);
                                bool	flip	= Convert.ToBoolean(FindNode(life, "f").Tag);

                                if (!flip) {
                                    object mob_picture = get_value(stand_fly + "\\0", t_img);
                                    if (mob_picture != null) {
                                        PNG png_mob;
                                        if (mob_picture.GetType().Name == "UOL") {
                                            TreeNode uol_node = FindNode(FindNode(t_img.node, stand_fly), "0");
                                            png_mob = (PNG)(resolve_UOL((UOL)mob_picture, uol_node).Tag);
                                            TreeNode resolved_node = resolve_UOL((UOL)mob_picture, uol_node);
                                            resolved_node = FindNode(resolved_node, "origin");

                                            v = (vector)resolved_node.Tag;
                                        }
                                        else { png_mob = (PNG)mob_picture; }
                                        Bitmap bitmap_mob = extract_png(png_mob, WZ.wz_files[t_img.wz_f]);
                                        int x_mob = (int)FindNode(life, "x").Tag + map_centerX - v.x;
                                        int y_mob = (int)FindNode(life, "cy").Tag + map_centerY - v.y;
                                        fMap.DrawImage(bitmap_mob, x_mob, y_mob);
                                    }
                                }
                                else
                                {
                                    object mob_picture = get_value(stand_fly + "\\0", t_img);

                                    if (mob_picture != null)
                                    {
                                        PNG png_mob;
                                        if (mob_picture.GetType().Name == "UOL") {
                                            TreeNode uol_node = FindNode(FindNode(t_img.node, stand_fly), "0");
                                            png_mob = (PNG)(resolve_UOL((UOL)mob_picture, uol_node).Tag);
                                            TreeNode resolved_node = resolve_UOL((UOL)mob_picture, uol_node);
                                            resolved_node = FindNode(resolved_node, "origin");
                                            v = (vector)resolved_node.Tag;
                                        } else { png_mob = (PNG)mob_picture; }

                                        Bitmap flippedBmp = extract_png(png_mob, WZ.wz_files[t_img.wz_f]);
                                        flippedBmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                        fMap.DrawImage(flippedBmp, (int)FindNode(life, "x").Tag + map_centerX + v.x - flippedBmp.Width, (int)FindNode(life, "cy").Tag + map_centerY - v.y);
                                    }
                                }
                            } else { continue; }
                            Application.DoEvents();
                        }
                    }
                }
            }

            //NPC
            if (chkNPCr.Checked == true) {
                toolStripStatusLabel1.Text = "Adding NPCs...";
                TreeNode npcs = FindNode(map_img.node, "life");
                if (npcs != null) {
                    if (npcs.Nodes.Count > 0) {
                        foreach (TreeNode life in npcs.Nodes) {
                            if ((string)FindNode(life, "type").Tag == "n") {
                                t_img		= FindImage("Npc\\" + (string)FindNode(life, "id").Tag + ".img", treeView1.Nodes[0]);
                                vector v	= (vector)get_value("stand\\0\\origin", t_img);
                                found_node	= FindNode(life, "f");

                                if (found_node != null) {
                                    bool flip = Convert.ToBoolean(FindNode(life, "f").Tag);
                                    if (!flip) {
                                        object npc_picture = get_value("stand\\0", t_img);
                                        if (npc_picture != null) {
                                            PNG png_npc;
                                            if (npc_picture.GetType().Name == "UOL") {
                                                TreeNode uol_node = FindNode(FindNode(t_img.node, "stand"), "0");
                                                png_npc = (PNG)(resolve_UOL((UOL)npc_picture, uol_node).Tag);
                                                TreeNode resolved_node = resolve_UOL((UOL)npc_picture, uol_node);
                                                resolved_node = FindNode(resolved_node, "origin");
                                                v = (vector)resolved_node.Tag;
                                            } else { png_npc = (PNG)npc_picture; }

                                            fMap.DrawImage(extract_png(png_npc, WZ.wz_files[t_img.wz_f]), (int)FindNode(life, "x").Tag + map_centerX - v.x, (int)FindNode(life, "cy").Tag + map_centerY - v.y);
                                        }
                                    } else {
                                        object npc_picture = get_value("stand\\0", t_img);
                                        if (npc_picture != null) {
                                            PNG png_npc;
                                            if (npc_picture.GetType().Name == "UOL") {
                                                TreeNode uol_node = FindNode(FindNode(t_img.node, "stand"), "0");
                                                png_npc = (PNG)(resolve_UOL((UOL)npc_picture, uol_node).Tag);
                                                TreeNode resolved_node = resolve_UOL((UOL)npc_picture, uol_node);
                                                resolved_node = FindNode(resolved_node, "origin");
                                                v = (vector)resolved_node.Tag;
                                            } else { png_npc = (PNG)npc_picture; }

                                            Bitmap flippedBmp = extract_png(png_npc, WZ.wz_files[t_img.wz_f]);
                                            flippedBmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                            fMap.DrawImage(flippedBmp, (int)FindNode(life, "x").Tag + map_centerX + v.x - flippedBmp.Width, (int)FindNode(life, "cy").Tag + map_centerY - v.y);
                                        }
                                    }
                                } else {
                                    fMap.DrawImage(extract_png((PNG)get_value("stand\\0", t_img), WZ.wz_files[t_img.wz_f]), (int)FindNode(life, "x").Tag + map_centerX - v.x, (int)FindNode(life, "cy").Tag + map_centerY - v.y);
                                }
                            } else { continue; }
                            Application.DoEvents();
                        }
                    }
                }
            }

            toolStripStatusLabel1.Text = "Ending process...";
            picRender.Image	= finalMap;
            picRender.Size	= finalMap.Size;
            return true;
        }
Ejemplo n.º 56
0
    /**
      * Pour arranger les bords du haut
      * @param rgb1
      * @param rgb2
      * @param out
      * @param startLine
      * @return out
      */
    private image borderW(int[] rgb1, int[] rgb2, image imgOut, bool startLine)
    {
        int[] rgbRes = new int[_widthBorder*_heightBorder];

        for(int i=0; i<rgb1.Length/4; i++)
        {
            rgbRes[i] = ((int)(0.75*((rgb1[i] >> 16) & 0xff ) + 0.25*((rgb2[i] >> 16) & 0xff))<<16  //1ere colonne
                          | (int)(0.75*((rgb1[i] >> 8)  & 0xff ) + 0.25*((rgb2[i] >> 8)  & 0xff))<<8
                          | (int)(0.75*( rgb1[i]        & 0xff ) + 0.25*( rgb2[i]        & 0xff))
                          | (int)((rgb1[i] >> 24) & 0xff )<<24);
        }
        for(int i=rgb1.Length/4; i<2*rgb1.Length/4; i++)
        {
            rgbRes[i] = ((int)(0.5*((rgb1[i] >> 16) & 0xff ) + 0.5*((rgb2[i] >> 16) & 0xff))<<16
                          | (int)(0.5*((rgb1[i] >> 8)  & 0xff ) + 0.5*((rgb2[i] >> 8)  & 0xff))<<8
                          | (int)(0.5*( rgb1[i]        & 0xff ) + 0.5*( rgb2[i]        & 0xff))
                          | (int)((rgb1[i] >> 24) & 0xff )<<24);
        }
        for(int i=2*rgb1.Length/4; i<3*rgb1.Length/4; i++)
        {
            rgbRes[i] = ((int)(0.5*((rgb1[i] >> 16) & 0xff ) + 0.5*((rgb2[i] >> 16) & 0xff))<<16
                          | (int)(0.5*((rgb1[i] >> 8)  & 0xff ) + 0.5*((rgb2[i] >> 8)  & 0xff))<<8
                          | (int)(0.5*( rgb1[i]        & 0xff ) + 0.5*( rgb2[i]        & 0xff))
                          | (int)((rgb1[i] >> 24) & 0xff )<<24);
        }
        for(int i=3*rgb1.Length/4; i<rgb1.Length; i++)
        {
            rgbRes[i] = ((int)(0.25*((rgb1[i] >> 16) & 0xff ) + 0.75*((rgb2[i] >> 16) & 0xff))<<16
                          | (int)(0.25*((rgb1[i] >> 8)  & 0xff ) + 0.75*((rgb2[i] >> 8)  & 0xff))<<8
                          | (int)(0.25*( rgb1[i]        & 0xff ) + 0.75*( rgb2[i]        & 0xff))
                          | (int)((rgb1[i] >> 24) & 0xff )<<24);
        }

        if(startLine)
        //            imgOut.setRGB(0, nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder, rgbRes, 0, _heightBorder);
            imgOut.setRGB(rgbRes, 0, nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder, _heightBorder);
        else
        //            imgOut.setRGB(_nbPatchPasted*(_patchSize-_widthBorder), nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder, rgbRes, 0, _heightBorder);
            imgOut.setRGB(rgbRes, _nbPatchPasted*(_patchSize-_widthBorder),
                          nbLinesDone*(_patchSize-_widthBorder), _heightBorder, _widthBorder, _heightBorder);
        return imgOut;
    }
Ejemplo n.º 57
0
    /**
     * @param image
     * @return out3
     */
    public image synthesize(image img)
    {
        //        BufferedImage copie = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
        //        copie = CubeImage.getAsCopy(image);
        image copie = new image(img);

        _in = duplicateSample(copie);

        //Nb de patch par ligne et par colonne
        _nbPatchPerLine   = _widthFinalTexture  / (_patchSize-_widthBorder) +1;
        _nbPatchPerColumn = _heightFinalTexture / (_patchSize-_widthBorder) +1;

        _nbPatchPasted = 1;
        nbLinesDone    = 0;

        _widthAnalysis  = _in.Width()  - _patchSize;
        _heightAnalysis = _in.Height() - _patchSize;

        //Initialisation de Out
        //        BufferedImage out = new BufferedImage((_nbPatchPerLine)*(_patchSize-_widthBorder)+_widthBorder, (_nbPatchPerColumn)*(_patchSize-_widthBorder)+_widthBorder, BufferedImage.TYPE_INT_ARGB);
        image outImg = new image((_nbPatchPerLine)*(_patchSize-_widthBorder)+_widthBorder,
                                 (_nbPatchPerColumn)*(_patchSize-_widthBorder)+_widthBorder);
        System.Random r = new System.Random();
        //        int x = r.nextInt(_widthAnalysis);
        //        int y = r.nextInt(_heightAnalysis);
        int x = r.Next(_widthAnalysis);
        int y = r.Next(_heightAnalysis);

        //        BufferedImage firstPatch = _in.getSubimage(x, y, _patchSize, _patchSize);
        image first_patch = _in.getSubImage(x, y, _patchSize, _patchSize);

        //        out.getGraphics().drawImage(firstPatch, 0, 0, null);
        outImg.setPixels(first_patch);

        analyseIn(_in);

        for(int i=0; i<_nbPatchPerLine-1; i++)
            firstLine(_in, outImg);

        for(int i=0; i<_nbPatchPerColumn-1; i++)
        {
            nbLinesDone++;
            firstPatch(_in, outImg);
            _nbPatchPasted = 1;

            for(int k=0; k<_nbPatchPerLine-1; k++)
                otherLine(_in, outImg);
        }
        //        out = out.getSubimage(0, 0, _widthFinalTexture, _heightFinalTexture);
        outImg = outImg.getSubImage(0, 0, _widthFinalTexture, _heightFinalTexture);

        //        BufferedImage out2 = new BufferedImage(2*_widthFinalTexture, 2*_heightFinalTexture, BufferedImage.TYPE_INT_ARGB);
        image out2 = new image(2*_widthFinalTexture, 2*_heightFinalTexture);
        //        out2.getGraphics().drawImage(out, 0, 0, null);
        out2.setPixels(outImg);
        //        out2.getGraphics().drawImage(out, _widthFinalTexture, 0, null);
        out2.setPixels(outImg, _widthFinalTexture, 0);
        //        out2.getGraphics().drawImage(out, 0, _heightFinalTexture, null);
        out2.setPixels(outImg, 0, _heightFinalTexture);
        //        out2.getGraphics().drawImage(out, _widthFinalTexture, _heightFinalTexture, null);
        out2.setPixels(outImg, _widthFinalTexture, _heightFinalTexture);

        //        BufferedImage out3 = new BufferedImage(4*_widthFinalTexture, 4*_heightFinalTexture, BufferedImage.TYPE_INT_ARGB);
        image out3 = new image(4*_widthFinalTexture, 4*_heightFinalTexture);
        //        out3.getGraphics().drawImage(out2, 0, 0, null);//out2
        out3.setPixels(out2, 0, 0);//out2
        //        out3.getGraphics().drawImage(out2, 2*_widthFinalTexture, 0, null);
        out3.setPixels(out2, 2*_widthFinalTexture, 0);
        //        out3.getGraphics().drawImage(out2, 0, 2*_heightFinalTexture, null);
        out3.setPixels(out2, 0, 2*_heightFinalTexture);
        //        out3.getGraphics().drawImage(out2, 2*_widthFinalTexture, 2*_heightFinalTexture, null);
        out3.setPixels(out2, 2*_widthFinalTexture, 2*_heightFinalTexture);
        return out3;
    }
Ejemplo n.º 58
0
 private static PlayListItem CreatePlayListItem(image img)
 {
     return new PlayListItem(new ImageId(img.id), img.name);
 }
Ejemplo n.º 59
0
 bool check_if_extracted(image img)
 {
     if(!img.extr) {
         wz_file w			= WZ.wz_files[img.wz_f];
         w.stream.Position	= img.offs;
         if(!img.chec) {
             int cs = 0;
             for(int i = 0; i < img.size; i++) {
                 cs += w.stream.ReadByte();
             }
             if(cs != img.cs32) {
                 MessageBox.Show("Checksum test failed! You could run into problems when running MapleStory with this file!", "Integrity Check failed");
                 return false;
             }
             img.chec			= true;
             w.stream.Position	= img.offs;
         }
         extract_img(img.offs, img.node, 0, w, img.on_list);
         img.extr				= true;
     }
     return true;
 }
Ejemplo n.º 60
0
 private void initEmpty()
 {
     HexValue = new hexvalue();
     RGB = new rgb();
     HSL = new hsl();
     HSV = new hsv();
     CMYK = new cmyk();
     XYZ = new xyz();
     Name = new name();
     Image = new image();
     Contrast = string.Empty;
 }