Exemple #1
0
        private ImageID GenImage()
        {
            ImageID image = IL.GenerateImage();

            IL.BindImage(image);
            return(image);
        }
Exemple #2
0
        private ImageID GenImage()
        {
            ImageID id = IL.GenerateImage();

            IL.BindImage(id);
            return(id);
        }
Exemple #3
0
        private ManagedImage(ImageID imageID, int imageNum)
        {
            m_faces     = new MipMapChainCollection();
            m_animChain = new AnimationChainCollection();

            LoadFaces(imageID, imageNum);
        }
Exemple #4
0
        private MipMapChain CreateMipMapChain(ImageID imageID, int imageNum, int faceNum)
        {
            IL.BindImage(imageID);
            if (!IL.ActiveImage(imageNum))
            {
                return(null);
            }
            if (!IL.ActiveFace(faceNum))
            {
                return(null);
            }

            //Get total number of mipmaps (including base face)
            int         mipMapCount = IL.ilGetInteger(ILDefines.IL_NUM_MIPMAPS) + 1;
            MipMapChain mipMapChain = new MipMapChain();

            //Get the first mipmap and every other, when we hit a null, we break
            for (int i = 0; i < mipMapCount; i++)
            {
                ImageData data = ImageData.Load(new Subimage(imageID, imageNum, faceNum, 0, i));
                if (data == null)
                {
                    break;
                }
                mipMapChain.Add(data);
            }
            mipMapChain.TrimExcess();
            return(mipMapChain);
        }
Exemple #5
0
        private MipMapChain CreateMipMapChain(ImageID imageID, int imageNum, int faceNum)
        {
            IL.BindImage(imageID);
            if (!IL.ActiveImage(imageNum))
            {
                return((MipMapChain)null);
            }
            if (!IL.ActiveFace(faceNum))
            {
                return((MipMapChain)null);
            }
            int         num         = IL.ilGetInteger(3570U) + 1;
            MipMapChain mipMapChain = new MipMapChain();

            for (int mipMapIndex = 0; mipMapIndex < num; ++mipMapIndex)
            {
                ImageData imageData = ImageData.Load(new Subimage(imageID, imageNum, faceNum, 0, mipMapIndex));
                if (imageData != null)
                {
                    mipMapChain.Add(imageData);
                }
                else
                {
                    break;
                }
            }
            mipMapChain.TrimExcess();
            return(mipMapChain);
        }
Exemple #6
0
 public Subimage(ImageID rootImage, int imageIndex, int faceIndex, int layerIndex, int mipMapIndex)
 {
     this.m_rootImage   = rootImage;
     this.m_imageIndex  = imageIndex;
     this.m_faceIndex   = faceIndex;
     this.m_layerIndex  = layerIndex;
     this.m_mipMapIndex = mipMapIndex;
 }
Exemple #7
0
 public Subimage(ImageID rootImage)
 {
     this.m_rootImage   = rootImage;
     this.m_imageIndex  = 0;
     this.m_faceIndex   = 0;
     this.m_layerIndex  = 0;
     this.m_mipMapIndex = 0;
 }
Exemple #8
0
        public Image Clone()
        {
            ImageID newID = IL.GenerateImage();
            Image   clone = new Image(newID);

            IL.BindImage(newID);
            IL.CopyImage(m_id);
            return(clone);
        }
Exemple #9
0
        public Image Clone()
        {
            ImageID image1 = IL.GenerateImage();
            Image   image2 = new Image(image1);

            IL.BindImage(image1);
            IL.CopyImage(this.m_id);
            return(image2);
        }
Exemple #10
0
        public void HoverOverImage_ImageId_DiplaysCorrectSubHeaders(ImageID imageID)
        {
            _sut.HoversPage.NavigateToPage();

            _sut.HoversPage.HoverOverImage(imageID);
            var result = _sut.HoversPage.ReadSubHeaderTextForImage(imageID);

            Assert.That(result, Is.EqualTo("name: user" + (int)imageID));
        }
        public void IsImageBroken_ReturnsTrueIfImageIsBroken(
            ImageID imageID, bool expectedCondition)
        {
            _sut.BrokenImagesPage.NavigateToPage();

            var result = _sut.BrokenImagesPage.IsImageBroken(imageID);

            Assert.That(result, Is.EqualTo(expectedCondition));
        }
Exemple #12
0
        public void HoverOverImage_ImageId_DisplaysCorrectLinks(ImageID imageID)
        {
            _sut.HoversPage.NavigateToPage();

            _sut.HoversPage.HoverOverImage(imageID);
            _sut.HoversPage.ClickViewProfileLink();
            var result = _sut.Driver.Url;

            Assert.That(result, Is.EqualTo(
                            ConfigReader.Index + "users/" + (int)imageID));
        }
Exemple #13
0
        public ManagedImage(Image image)
        {
            this.m_faces     = new MipMapChainCollection();
            this.m_animChain = new AnimationChainCollection();
            if (!image.IsValid)
            {
                return;
            }
            ImageID imageId = image.ImageID;

            this.LoadFaces(imageId, 0);
            this.LoadAnimationChain(imageId);
        }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (obj == null || obj.ToString().Equals("{DisconnectedItem}"))
            {
                return(false);
            }
            var other = obj as ImageTagViewModel;

            return(ImageID.Equals(other.ImageID) && Tag.Equals(other.Tag));
        }
Exemple #15
0
        public Image LoadImage(ImageType imageType, string filename)
        {
            if (imageType == ImageType.Unknown || string.IsNullOrEmpty(filename))
            {
                throw new IOException("Failed to load image, invalid imagetype or file does not exist.");
            }
            this.CheckDisposed();
            ImageID id = this.GenImage();

            if (IL.LoadImage(imageType, filename))
            {
                return(new Image(id));
            }
            throw new IOException(string.Format("Failed to loade image: {0}", (object)IL.GetError()));
        }
Exemple #16
0
        public Image LoadImageFromStream(Stream stream)
        {
            if (stream == null || !stream.CanRead)
            {
                throw new IOException("Failed to load image, Stream is null or write-only");
            }
            this.CheckDisposed();
            ImageID id = this.GenImage();

            if (IL.LoadImageFromStream(stream))
            {
                return(new Image(id));
            }
            throw new IOException(string.Format("Failed to loade image: {0}", (object)IL.GetError()));
        }
Exemple #17
0
        public Image LoadImageFromStream(ImageType imageType, Stream stream)
        {
            if (imageType == ImageType.Unknown || stream == null || !stream.CanRead)
            {
                throw new IOException("Failed to load image, invalid imagetype or stream can't be read from.");
            }
            this.CheckDisposed();
            ImageID id = this.GenImage();

            if (IL.LoadImageFromStream(imageType, stream))
            {
                return(new Image(id));
            }
            throw new IOException(string.Format("Failed to load image: {0}", (object)IL.GetError()));
        }
Exemple #18
0
        public ManagedImage(Image image)
        {
            m_faces     = new MipMapChainCollection();
            m_animChain = new AnimationChainCollection();

            if (!image.IsValid)
            {
                return;
            }

            ImageID imageID = image.ImageID;

            LoadFaces(imageID, 0);
            LoadAnimationChain(imageID);
        }
Exemple #19
0
        private void LoadFaces(ImageID imageID, int imageNum) {
            IL.BindImage(imageID);
            if(!IL.ActiveImage(imageNum))
                return;

            //Get total number of faces (including base face)
            int faceCount = IL.ilGetInteger(ILDefines.IL_NUM_FACES) + 1;

            //Get the first face and every other as a mip map chain, when we hit a null, we break
            for(int i = 0; i < faceCount; i++) {
                MipMapChain mipMapChain = CreateMipMapChain(imageID, imageNum, i);
                if(mipMapChain == null)
                    break;
                m_faces.Add(mipMapChain);
            }
        }
Exemple #20
0
        private void LoadAnimationChain(ImageID imageID) {
            IL.BindImage(imageID);

            //Get total number of images in array (including first)
            int imageCount = IL.ilGetInteger(ILDefines.IL_NUM_IMAGES) + 1;

            //If just one image, we aren't really an animation chain
            if(imageCount > 1) {
                m_animChain.Add(this);
                for(int i = 1; i < imageCount; i++) {
                    ManagedImage image = new ManagedImage(imageID, i);
                    //If the image wasn't valid, don't add it
                    if(image.Faces.Count != 0)
                        m_animChain.Add(image);
                }
            }
        }
Exemple #21
0
 /// <summary>
 /// Compares this point to <paramref name="other"/>.
 /// </summary>
 /// <param name="other">Point to compare to</param>
 /// <returns>Positive if this point is greater, negative if this point is less than, zero if equal</returns>
 public int CompareTo(ImageDataPoint <T> other)
 {
     if (ImageID == other.ImageID)
     {
         if (_row == other._row)
         {
             return(_column.CompareTo(other._column));
         }
         else
         {
             return(_row.CompareTo(other._row));
         }
     }
     else
     {
         return(ImageID.CompareTo(other.ImageID));
     }
 }
Exemple #22
0
        private void LoadAnimationChain(ImageID imageID)
        {
            IL.BindImage(imageID);
            int num = IL.ilGetInteger(3569U) + 1;

            if (num <= 1)
            {
                return;
            }
            this.m_animChain.Add(this);
            for (int imageNum = 1; imageNum < num; ++imageNum)
            {
                ManagedImage managedImage = new ManagedImage(imageID, imageNum);
                if (managedImage.Faces.Count != 0)
                {
                    this.m_animChain.Add(managedImage);
                }
            }
        }
Exemple #23
0
        private void LoadFaces(ImageID imageID, int imageNum)
        {
            IL.BindImage(imageID);
            if (!IL.ActiveImage(imageNum))
            {
                return;
            }
            int num = IL.ilGetInteger(3553U) + 1;

            for (int faceNum = 0; faceNum < num; ++faceNum)
            {
                MipMapChain mipMapChain = this.CreateMipMapChain(imageID, imageNum, faceNum);
                if (mipMapChain == null)
                {
                    break;
                }
                this.m_faces.Add(mipMapChain);
            }
        }
Exemple #24
0
        /**
         * Returns the image for the specified id. If the ID does not exist returns null.
         *
         * @param id ID of the image to return.
         *
         * @return Image for that id.
         */
        public static Image LoadImage(ImageID id)
        {
            //check that id is correct
            if ((int)id >= images.Length)
            {
                return(null);
            }

            //image already loaded?
            if (images[(int)id] != null)
            {
                return(images[(int)id]);
            }

            //load image
            switch (id)
            {
            case ImageID.Empty:
                images[(int)id] = new Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                break;

            default:
                //check that id is correct
                if ((int)id >= imageNames.Length)
                {
                    return(null);
                }

                Assembly assembly    = Assembly.GetExecutingAssembly();
                Stream   imageStream = assembly.GetManifestResourceStream("crf.Resources." + imageNames[(int)id]);

                Bitmap bitmap = new Bitmap(imageStream);
                if (null != bitmap)
                {
                    bitmap.MakeTransparent(Color.White);
                }
                images[(int)id] = bitmap;
                break;
            }

            return(images[(int)id]);
        }
Exemple #25
0
        public void HoverOverImage(ImageID imageID)
        {
            Actions actions = new Actions(Driver);

            switch (imageID)
            {
            case ImageID.Image1:
                actions.MoveToElement(Image1);
                break;

            case ImageID.Image2:
                actions.MoveToElement(Image2);
                break;

            case ImageID.Image3:
                actions.MoveToElement(Image3);
                break;
            }
            actions.Perform();
        }
Exemple #26
0
        public string ReadSubHeaderTextForImage(ImageID imageID)
        {
            string headerText = null;

            switch (imageID)
            {
            case ImageID.Image1:
                headerText = PageSubHeader1.Text;
                break;

            case ImageID.Image2:
                headerText = PageSubHeader2.Text;
                break;

            case ImageID.Image3:
                headerText = PageSubHeader3.Text;
                break;
            }
            return(headerText);
        }
Exemple #27
0
        public Image LoadImage(ImageType imageType, String filename)
        {
            if (imageType == ImageType.Unknown || String.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                throw new IOException("Failed to load image, invalid imagetype or file does not exist.");
            }

            CheckDisposed();

            ImageID id = GenImage();

            if (IL.LoadImage(imageType, filename))
            {
                return(new Image(id));
            }
            else
            {
                throw new IOException(String.Format("Failed to loade image: {0}", IL.GetError()));
            }
        }
Exemple #28
0
        public bool IsImageBroken(ImageID imageID)
        {
            IWebElement image = null;

            switch (imageID)
            {
            case ImageID.Image1:
                image = Image1;
                break;

            case ImageID.Image2:
                image = Image2;
                break;

            case ImageID.Image3:
                image = Image3;
                break;
            }
            return(image.GetAttribute("naturalWidth").Equals("0"));
        }
Exemple #29
0
        public Image LoadImage(String filename)
        {
            if (String.IsNullOrEmpty(filename))
            {
                throw new IOException("Failed to load image, file does not exist.");
            }

            CheckDisposed();

            ImageID id = GenImage();

            if (IL.LoadImage(filename))
            {
                return(new Image(id));
            }
            else
            {
                throw new IOException(String.Format("Failed to loade image: {0}", IL.GetError()));
            }
        }
Exemple #30
0
        private void LoadFaces(ImageID imageID, int imageNum)
        {
            IL.BindImage(imageID);
            if (!IL.ActiveImage(imageNum))
            {
                return;
            }

            //Get total number of faces (including base face)
            int faceCount = IL.ilGetInteger(ILDefines.IL_NUM_FACES) + 1;

            //Get the first face and every other as a mip map chain, when we hit a null, we break
            for (int i = 0; i < faceCount; i++)
            {
                MipMapChain mipMapChain = CreateMipMapChain(imageID, imageNum, i);
                if (mipMapChain == null)
                {
                    break;
                }
                m_faces.Add(mipMapChain);
            }
        }
Exemple #31
0
        private void LoadAnimationChain(ImageID imageID)
        {
            IL.BindImage(imageID);

            //Get total number of images in array (including first)
            int imageCount = IL.ilGetInteger(ILDefines.IL_NUM_IMAGES) + 1;

            //If just one image, we aren't really an animation chain
            if (imageCount > 1)
            {
                m_animChain.Add(this);
                for (int i = 1; i < imageCount; i++)
                {
                    ManagedImage image = new ManagedImage(imageID, i);
                    //If the image wasn't valid, don't add it
                    if (image.Faces.Count != 0)
                    {
                        m_animChain.Add(image);
                    }
                }
            }
        }
Exemple #32
0
        /// <summary>
        /// Uploads a file
        /// </summary>
        /// <param name="filename">The filename we want to upload</param>
        /// <param name="MD5Checksum">The MD5 checksum of a file</param>
        /// <returns>An Image object that describes the image we uploaded</returns>
        public async Task <Image> UploadImageAsync(string filename, string MD5Checksum, CancellationToken token)
        {
            string uploadURL    = string.Format("http://upload.smugmug.com/{0}", filename);
            var    myFileInfo   = new FileInfo(filename);
            var    myWebRequest = (HttpWebRequest)WebRequest.Create(uploadURL);

            myWebRequest.UserAgent     = "YASMAPI v1.0";
            myWebRequest.ContentType   = "binary/octet-stream";
            myWebRequest.ContentLength = myFileInfo.Length;
            myWebRequest.Method        = WebRequestMethods.Http.Put;

            myWebRequest.Headers.Add("X-Smug-Version", Version);
            myWebRequest.Headers.Add("X-Smug-ResponseType", ResponseType);
            myWebRequest.Headers.Add("X-Smug-AlbumID", Album.id.ToString());
            myWebRequest.Headers.Add("Content-MD5", MD5Checksum);
            myWebRequest.Headers.Add("X-Smug-FileName", myFileInfo.Name);

            if (Altitude != null)
            {
                myWebRequest.Headers.Add("X-Smug-Altitude", Altitude.ToString());
            }
            if (Caption != null)
            {
                myWebRequest.Headers.Add("X-Smug-Caption", Caption);
            }
            if (Hidden == true)
            {
                myWebRequest.Headers.Add("X-Smug-Hidden", "true");
            }
            if (ImageID != null)
            {
                myWebRequest.Headers.Add("X-Smug-ImageID", ImageID.ToString());
            }
            if (Keywords != null)
            {
                myWebRequest.Headers.Add("X-Smug-Keywords", Keywords);
            }
            if (Latitude != null)
            {
                myWebRequest.Headers.Add("X-Smug-Latitude", Latitude.ToString());
            }
            if (Longitude != null)
            {
                myWebRequest.Headers.Add("X-Smug-Longitude", Longitude.ToString());
            }
            if (Pretty == true)
            {
                myWebRequest.Headers.Add("X-Smug-Pretty", "true");
            }


            // Add the authorization header
            myWebRequest.Headers.Add("Authorization", oAuthUtility.GetAuthorizationHeader(authentication.AccessToken, uploadURL));

            //we start reading from the file...

            //we have some elements to set
            //- request time out (compute this for 10 kb/sec speed)
            //- the chunk size to use when uploading (how much data to report after)
            if (UploadStarted != null)
            {
                UploadStarted(this, new UploadEventArgs()
                {
                    FileName = myFileInfo.FullName, PercentComplete = 0
                });
            }

            int timeOut = ((int)myFileInfo.Length / 1024) * 1000;

            myWebRequest.Timeout                   = timeOut;
            myWebRequest.ReadWriteTimeout          = timeOut;
            myWebRequest.AllowWriteStreamBuffering = AllowWriteStreamBuffering;

            long howMuchRead = 0;

            byte[] buffer    = new byte[chunkSize];
            int    readSoFar = 0;

            try
            {
                using (FileStream sr = new FileStream(myFileInfo.FullName, FileMode.Open, FileAccess.Read))
                {
                    using (var stream = await myWebRequest.GetRequestStreamAsync())
                    {
                        while (howMuchRead < myFileInfo.Length)
                        {
                            //we try to read a chunk from the file
                            readSoFar    = sr.Read(buffer, 0, chunkSize);
                            howMuchRead += readSoFar;

                            //we now write those files to the web.
                            await stream.WriteAsync(buffer, 0, readSoFar, token);

                            if (UploadProgress != null)
                            {
                                UploadProgress(this, new UploadEventArgs()
                                {
                                    FileName = myFileInfo.FullName, PercentComplete = (float)howMuchRead / (float)myFileInfo.Length
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //an error has occured...
                throw;
            }

            var resp = await myWebRequest.GetResponseAsync();

            string rez = string.Empty;

            using (StreamReader ns = new StreamReader(resp.GetResponseStream()))
            {
                rez = await ns.ReadToEndAsync();
            }

            if (UploadCompleted != null)
            {
                UploadCompleted(this, new UploadEventArgs()
                {
                    FileName = myFileInfo.FullName, PercentComplete = (float)howMuchRead / (float)myFileInfo.Length
                });
            }

            //we deserialize the image
            var response = JsonConvert.DeserializeObject <ImageResponse>(System.Uri.UnescapeDataString(rez));

            if (response.stat == "ok")
            {
                Image img = response.Image;
                img.basic = authentication;
                img.Album = Album;

                return(img);
            }
            else
            {
                throw new SmugMugException(response.code, response.message, response.method);
            }
        }
Exemple #33
0
        /// <summary>
        /// Overlays the source image, over the currently bound image at the offsets specified. This basically
        /// performs a blit behind the scenes, so set blit parameters accordingly.
        /// </summary>
        /// <param name="srcImageID">Source image id</param>
        /// <param name="destX">Destination x offset</param>
        /// <param name="destY">Destination y offset</param>
        /// <param name="destZ">Destination z offset</param>
        /// <returns></returns>
        public static bool OverlayImage(ImageID srcImageID, int destX, int destY, int destZ) {
            if(srcImageID.ID < 0) {
                return false;
            }

            return ilOverlayImage((uint) srcImageID.ID, destX, destY, destZ);
        }
Exemple #34
0
        /// <summary>
        /// Checks if the imageID is in fact an image.
        /// </summary>
        /// <param name="imageID">Image ID</param>
        /// <returns>True if an image, false otherwise</returns>
        public static bool IsImage(ImageID imageID) {
            if(imageID.ID < 0)
                return false;

            return ilIsImage((uint) imageID.ID);
        }
Exemple #35
0
        private MipMapChain CreateMipMapChain(ImageID imageID, int imageNum, int faceNum) {
            IL.BindImage(imageID);
            if(!IL.ActiveImage(imageNum))
                return null;
            if(!IL.ActiveFace(faceNum))
                return null;

            //Get total number of mipmaps (including base face)
            int mipMapCount = IL.ilGetInteger(ILDefines.IL_NUM_MIPMAPS) + 1;
            MipMapChain mipMapChain = new MipMapChain();

            //Get the first mipmap and every other, when we hit a null, we break
            for(int i = 0; i < mipMapCount; i++) {
                ImageData data = ImageData.Load(new Subimage(imageID, imageNum, faceNum, 0, i));
                if(data == null)
                    break;
                mipMapChain.Add(data);
            }
            mipMapChain.TrimExcess();
            return mipMapChain;
        }
Exemple #36
0
        /* TODO
        ///InProfile: char*
        ///OutProfile: char*
        [DllImportAttribute(ILDLL, EntryPoint = "ilApplyProfile", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.U1)]
        private static extern bool ilApplyProfile(IntPtr InProfile, IntPtr OutProfile);
        */

        public static void BindImage(ImageID imageID) {
            if(imageID.ID >= 0) {
                ilBindImage((uint) imageID.ID);
            }
        }
Exemple #37
0
        private ManagedImage(ImageID imageID, int imageNum) {
            m_faces = new MipMapChainCollection();
            m_animChain = new AnimationChainCollection();

            LoadFaces(imageID, imageNum);
        }
Exemple #38
0
 public static bool Blit(ImageID srcImageID, int destX, int destY, int destZ, int srcX, int srcY, int srcZ, int width, int height, int depth) {
     if(srcImageID.ID >= 0) {
         return ilBlit((uint) srcImageID.ID, destX, destY, destZ, (uint) srcX, (uint) srcY, (uint) srcZ, (uint) width, (uint) height, (uint) depth);
     }
     return false;
 }
Exemple #39
0
 public static bool CopyImage(ImageID srcImageID) {
     return ilCopyImage((uint) srcImageID.ID);
 }
Exemple #40
0
        public static void DeleteImage(ImageID imageID) {
            //Dont delete default, and valid images are non-negative
            if(imageID > 0)
                return;

            ilDeleteImage((uint) imageID.ID);
        }
Exemple #41
0
        public static void DeleteImages(ImageID[] imageIDs) {
            uint[] ids = new uint[imageIDs.Length];
            for(int i = 0; i < imageIDs.Length; i++) {
                ids[i] = (uint) imageIDs[i].ID;
            }

            UIntPtr size = new UIntPtr((uint) ids.Length);

            ilDeleteImages(size, ids);
        }
Exemple #42
0
        /// <summary>
        /// Batch generates images and returns an array of the generated image ids.
        /// </summary>
        /// <param name="count">Number of images to generate</param>
        /// <returns>Generated images</returns>
        public static ImageID[] GenerateImages(int count) {
            UIntPtr num = new UIntPtr((uint) count);
            uint[] images = new uint[count];
            ilGenImages(num, images);

            ImageID[] copy = new ImageID[count];
            for(int i = 0; i < count; i++) {
                copy[i] = new ImageID((int)images[i]);
            }

            return copy;
        }