Ejemplo n.º 1
0
        public void ImageLoadingLoadImageFromFileWithFittingMode()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromFileWithFittingMode START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                var testingTarget = ImageLoading.LoadImageFromFile(image_path, size2d, FittingModeType.ScaleToFill);
                Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer.");
                Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should return PixelBuffer instance.");

                testingTarget.Dispose();
            }

            // size is null
            try
            {
                var testingTarget = ImageLoading.LoadImageFromFile(image_path, null, FittingModeType.ScaleToFill);
            }
            catch (ArgumentNullException e)
            {
                Assert.Pass("Catch ArgumentNullException, Pass!");
            }

            tlog.Debug(tag, $"ImageLoadingLoadImageFromFileWithFittingMode END (OK)");
        }
Ejemplo n.º 2
0
        public Palette ImageGenerate(int idx)
        {
            PixelBuffer imgBitmap = ImageLoading.LoadImageFromFile(imagePath[idx]);
            Palette     palette   = Palette.generate(imgBitmap);

            return(palette);
        }
Ejemplo n.º 3
0
        void ReleaseDesignerOutlets()
        {
            if (ImageLoading != null)
            {
                ImageLoading.Dispose();
                ImageLoading = null;
            }

            if (AuthorLabel != null)
            {
                AuthorLabel.Dispose();
                AuthorLabel = null;
            }

            if (TitleLabel != null)
            {
                TitleLabel.Dispose();
                TitleLabel = null;
            }

            if (CoverImage != null)
            {
                CoverImage.Dispose();
                CoverImage = null;
            }
        }
Ejemplo n.º 4
0
        void ReleaseDesignerOutlets()
        {
            if (SynopsisLoading != null)
            {
                SynopsisLoading.Dispose();
                SynopsisLoading = null;
            }

            if (AuthorLabel != null)
            {
                AuthorLabel.Dispose();
                AuthorLabel = null;
            }

            if (CoverImage != null)
            {
                CoverImage.Dispose();
                CoverImage = null;
            }

            if (GenreLabel != null)
            {
                GenreLabel.Dispose();
                GenreLabel = null;
            }

            if (ImageLoading != null)
            {
                ImageLoading.Dispose();
                ImageLoading = null;
            }

            if (OverviewRoot != null)
            {
                OverviewRoot.Dispose();
                OverviewRoot = null;
            }

            if (PublishDateLabel != null)
            {
                PublishDateLabel.Dispose();
                PublishDateLabel = null;
            }

            if (SynopsisLabel != null)
            {
                SynopsisLabel.Dispose();
                SynopsisLabel = null;
            }

            if (TitleLabel != null)
            {
                TitleLabel.Dispose();
                TitleLabel = null;
            }
        }
Ejemplo n.º 5
0
 private void Awake()
 {
     if (instance)
     {
         Destroy(gameObject);
     }
     else
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
 }
Ejemplo n.º 6
0
        private Texture LoadStageFillingTexture(string filepath)
        {
            Size2D      dimensions = new Size2D(Window.Instance.WindowSize.Width, Window.Instance.WindowSize.Height);
            PixelBuffer pb         = ImageLoading.LoadImageFromFile(filepath, dimensions, FittingModeType.ScaleToFill);
            PixelData   pd         = PixelBuffer.Convert(pb);

            Texture texture = new Texture(TextureType.TEXTURE_2D, pd.GetPixelFormat(), pd.GetWidth(), pd.GetHeight());

            texture.Upload(pd);

            return(texture);
        }
Ejemplo n.º 7
0
        public void ImageLoadingLoadImageFromFile()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromFile START");

            var testingTarget = ImageLoading.LoadImageFromFile(imageurl);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer.");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should return PixelBuffer instance.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"ImageLoadingLoadImageFromFile END (OK)");
        }
Ejemplo n.º 8
0
        public void ImageLoadingGetClosestImageSize()
        {
            tlog.Debug(tag, $"ImageLoadingGetClosestImageSize START");

            var testingTarget = ImageLoading.GetClosestImageSize("picture");

            Assert.IsNotNull(testingTarget, "Can't create success object Size2D.");
            Assert.IsInstanceOf <Size2D>(testingTarget, "Should return Size2D instance.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"ImageLoadingGetClosestImageSize END (OK)");
        }
Ejemplo n.º 9
0
        public void ImageLoadingDownloadImageSynchronously()
        {
            tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronously START");


            var testingTarget = ImageLoading.DownloadImageSynchronously(bmp_path);

            Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer.");
            Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should return PixelBuffer instance.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronously END (OK)");
        }
Ejemplo n.º 10
0
        public void ImageLoadingDownloadImageSynchronouslyWithOrientationCorrection()
        {
            tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronouslyWithOrientationCorrection START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                var testingTarget = ImageLoading.DownloadImageSynchronously(bmp_path, size2d, FittingModeType.Center, SamplingModeType.DontCare, true);
                Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer.");
                Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should return PixelBuffer instance.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronouslyWithOrientationCorrection END (OK)");
        }
Ejemplo n.º 11
0
        public void ImageLoadingGetClosestImageSizeWithOrientationCorrection()
        {
            tlog.Debug(tag, $"ImageLoadingGetClosestImageSizeWithOrientationCorrection START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                var testingTarget = ImageLoading.GetClosestImageSize(file_name, size2d, FittingModeType.ShrinkToFit, SamplingModeType.Box, true);
                Assert.IsNotNull(testingTarget, "Can't create success object Size2D.");
                Assert.IsInstanceOf <Size2D>(testingTarget, "Should return Size2D instance.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"ImageLoadingGetClosestImageSizeWithOrientationCorrection END (OK)");
        }
Ejemplo n.º 12
0
        public void ImageLoadingGetClosestImageSizeWithSize()
        {
            tlog.Debug(tag, $"ImageLoadingGetClosestImageSizeWithSize START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                var testingTarget = ImageLoading.GetClosestImageSize(file_name, size2d);
                Assert.IsNotNull(testingTarget, "Can't create success object Size2D.");
                Assert.IsInstanceOf <Size2D>(testingTarget, "Should return Size2D instance.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"ImageLoadingGetClosestImageSizeWithSize END (OK)");
        }
Ejemplo n.º 13
0
        public void ImageLoadingLoadImageFromFileWithOrientationCorrection()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromFileWithOrientationCorrection START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                var testingTarget = ImageLoading.LoadImageFromFile(image_path, size2d, FittingModeType.ScaleToFill, SamplingModeType.Linear, true);
                Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer.");
                Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should return PixelBuffer instance.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"ImageLoadingLoadImageFromFileWithOrientationCorrection END (OK)");
        }
Ejemplo n.º 14
0
        public void ImageLoadingLoadImageFromBufferWithNullBuffer()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithNullBuffer START");

            try
            {
                ImageLoading.LoadImageFromBuffer(null);
            }
            catch (ArgumentNullException e)
            {
                tlog.Debug(tag, e.Message.ToString());
                tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithNullBuffer END (OK)");
                Assert.Pass("Caught ArgumentNullException :  Passed!");
            }
        }
Ejemplo n.º 15
0
        public void ImageLoadingLoadImageFromFileWithOrientationCorrectionAndNullSize()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromFileWithOrientationCorrectionAndNullSize START");

            try
            {
                ImageLoading.LoadImageFromFile(image_path, null, FittingModeType.ScaleToFill, SamplingModeType.Linear, true);
            }
            catch (ArgumentNullException e)
            {
                tlog.Debug(tag, e.Message.ToString());
                tlog.Debug(tag, $"ImageLoadingLoadImageFromFileWithOrientationCorrectionAndNullSize END (OK)");
                Assert.Pass("Caught ArgumentNullException :  Passed!");
            }
        }
Ejemplo n.º 16
0
        protected override void OnCreate()
        {
            base.OnCreate();
            Window window = NUIApplication.GetDefaultWindow();

            window.BackgroundColor = Color.Black;

            View view = new View()
            {
                Size = new Size(window.WindowSize)
            };

            window.Add(view);


            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            VertexBuffer vertexBuffer = new VertexBuffer(vertexFormat);

            vertexBuffer.SetData(Quad());
            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);
            Shader shader = new Shader(VERTEX_SHADER, FRAGMENT_SHADER);

            PixelData pixelData = PixelBuffer.Convert(ImageLoading.LoadImageFromFile(
                                                          "./res/background_image.jpg",
                                                          new Size2D(),
                                                          FittingModeType.ScaleToFill
                                                          ));
            Texture texture = new Texture(
                TextureType.TEXTURE_2D,
                pixelData.GetPixelFormat(),
                pixelData.GetWidth(),
                pixelData.GetHeight()
                );

            texture.Upload(pixelData);
            TextureSet textureSet = new TextureSet();

            textureSet.SetTexture(0u, texture);
            Renderer renderer = new Renderer(geometry, shader);

            renderer.SetTextures(textureSet);
            view.AddRenderer(renderer);
        }
Ejemplo n.º 17
0
        public void ImageLoadingLoadImageFromBufferWithSize()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithSize  START");

            var stream = FileToStream(image_path);

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                var testingTarget = ImageLoading.LoadImageFromBuffer(stream, size2d);
                Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer.");
                Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should return PixelBuffer instance.");

                testingTarget.Dispose();
            }

            tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithSize  END (OK)");
        }
Ejemplo n.º 18
0
        public void ImageLoadingLoadImageFromBufferWithSizeNullSize()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithSizeNullSize START");

            var stream = FileToStream(image_path);

            try
            {
                ImageLoading.LoadImageFromBuffer(stream, null);
            }
            catch (ArgumentNullException e)
            {
                tlog.Debug(tag, e.Message.ToString());
                tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithSizeNullSize END (OK)");
                Assert.Pass("Caught ArgumentNullException :  Passed!");
            }
        }
Ejemplo n.º 19
0
        public void ImageLoadingLoadImageFromBufferWithSizeNullBuffer()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithSizeNullBuffer START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                try
                {
                    ImageLoading.LoadImageFromBuffer(null, size2d);
                }
                catch (ArgumentNullException e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithSizeNullBuffer END (OK)");
                    Assert.Pass("Caught ArgumentNullException :  Passed!");
                }
            }
        }
Ejemplo n.º 20
0
        public void ImageLoadingDownloadImageSynchronouslyByNullUrl()
        {
            tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronouslyByNullUrl START");

            try
            {
                using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
                {
                    Uri uri = null;
                    ImageLoading.DownloadImageSynchronously(uri, size2d, FittingModeType.Center);
                }
            }
            catch (ArgumentNullException)
            {
                tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronouslyByNullUrl END (OK)");
                Assert.Pass("Caught ArgumentNullException : Passed!");
            }
        }
Ejemplo n.º 21
0
        public bool Bake(PipelineBakeContext context)
        {
            Console.WriteLine("Texture.Bake: " + context.ContentPath);

            //I dont know... I dont know...
            var path = context.RawContentDiskPath;

            if (!File.Exists(path))
            {
                return(false);
            }

            var img = ImageLoading.LoadImage(path);

            img.Serialize(context.BakedWriter);

            return(true);
        }
Ejemplo n.º 22
0
        public void ImageLoadingLoadImageFromBufferWithOrientationCorrectionNullBuffer()
        {
            tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithOrientationCorrectionNullBuffer START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                try
                {
                    ImageLoading.LoadImageFromBuffer(null, size2d, FittingModeType.ScaleToFill, SamplingModeType.Linear, true);
                }
                catch (ArgumentNullException e)
                {
                    tlog.Debug(tag, e.Message.ToString());
                    tlog.Debug(tag, $"ImageLoadingLoadImageFromBufferWithOrientationCorrectionNullBuffer END (OK)");
                    Assert.Pass("Caught ArgumentNullException :  Passed!");
                }
            }
        }
Ejemplo n.º 23
0
        protected override void OnCreate()
        {
            base.OnCreate();
            win = Window.Instance;
            win.BackgroundColor = Color.Cyan;
            View v1 = new View();

            v1.Size2D          = new Size2D(100, 100);
            v1.BackgroundColor = Color.Blue;
            win.GetDefaultLayer().Add(v1);

            ImageView iv = new ImageView();

            iv.ResourceUrl = mypath.DirectoryInfo.Resource + @"/images/Dali/DaliDemo/Logo-for-demo.png";
            iv.Position2D  = new Position2D(50, 200);
            win.GetDefaultLayer().Add(iv);

            Size2D    imageSize = ImageLoading.GetOriginalImageSize(iv.ResourceUrl);
            TextLabel tl        = new TextLabel();

            tl.Position2D = new Position2D(iv.Position2D.X, iv.Position2D.Y + imageSize.Height);
            tl.MultiLine  = true;
            tl.Text       = $"ResourceUrl: {iv.ResourceUrl} \nOriginalImageSize: W({imageSize.Width}), H({imageSize.Height})";
            win.GetDefaultLayer().Add(tl);

            //==================
            iv             = new ImageView();
            iv.ResourceUrl = mypath.DirectoryInfo.Resource + @"/images/Dali/DaliDemo/demo-tile-texture.9.png";
            iv.Position2D  = new Position2D(50, 600);
            win.GetDefaultLayer().Add(iv);

            imageSize     = ImageLoading.GetOriginalImageSize(iv.ResourceUrl);
            tl            = new TextLabel();
            tl.Position2D = new Position2D(iv.Position2D.X, iv.Position2D.Y + imageSize.Height);
            tl.MultiLine  = true;
            tl.Text       = $"ResourceUrl: {iv.ResourceUrl} \nOriginalImageSize: W({imageSize.Width}), H({imageSize.Height})";
            win.GetDefaultLayer().Add(tl);
        }
Ejemplo n.º 24
0
        public void ImageLoadingDownloadImageSynchronouslyByUrl()
        {
            tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronouslyByUrl START");

            using (Size2D size2d = new Size2D(NUIApplication.GetDefaultWindow().WindowSize.Width, NUIApplication.GetDefaultWindow().WindowSize.Height))
            {
                var testingTarget = ImageLoading.DownloadImageSynchronously(new Uri(bmp_path), size2d, FittingModeType.Center);
                Assert.IsNotNull(testingTarget, "Can't create success object PixelBuffer.");
                Assert.IsInstanceOf <PixelBuffer>(testingTarget, "Should return PixelBuffer instance.");

                testingTarget.Dispose();
            }

            try
            {
                ImageLoading.DownloadImageSynchronously(new Uri(bmp_path), null, FittingModeType.FitHeight);
            }
            catch (ArgumentNullException)
            {
                tlog.Debug(tag, $"ImageLoadingDownloadImageSynchronouslyByUrl END (OK)");
                Assert.Pass("Caught ArgumentNullException : Passed!");
            }
        }
Ejemplo n.º 25
0
        protected virtual void OnFileChanged()
        {
            controlNumber++;

            fileNameLabel.Text = DriveFile.Name;
            fileSizeLabel.Text = Common.NumberOfBytesToString(DriveFile.Size);
            lblID.Text         = DriveFile.StorageFileId;

            label3.Visible = false;
            widthAndHeightLabel.Visible = false;

            if (!DriveFile.IsImage)
            {
                lock (pictureCancellationTokenSourceLoker)
                {
                    pictureCancellationTokenSource?.Cancel();
                    pictureCancellationTokenSource = new CancellationTokenSource();
                }
                ImageLoaded?.Invoke(this, new EventArgs());
                pictureBox1.BackgroundImage = Resources.no_image;
                Picture = null;
                return;
            }

            // Image preview async loading
            ImageLoading?.Invoke(this, new EventArgs());
            Task.Run(async delegate
            {
                try
                {
                    lock (pictureCancellationTokenSourceLoker)
                    {
                        if (pictureCancellationTokenSource != null)
                        {
                            pictureCancellationTokenSource.Cancel();
                        }
                        pictureCancellationTokenSource = new CancellationTokenSource();
                    }

                    pictureBox1.BackgroundImage = Resources.loading;
                    Picture = null;
                    int cn  = controlNumber;
                    Image image;
                    try
                    {
                        image = await DriveFile.Drive.GetImageAsync(DriveFile, pictureCancellationTokenSource.Token);
                        if (cn != controlNumber)
                        {
                            return;
                        }
                        Invoke(new MethodInvoker(() =>
                        {
                            label3.Visible = true;
                            widthAndHeightLabel.Visible = true;
                            widthAndHeightLabel.Text    = string.Format("{0} x {1}", DriveFile.ImageWidth, DriveFile.ImageHeight);
                            pictureBox1.BackgroundImage = image;
                            Picture = image;
                            Invoke(new MethodInvoker(() =>
                            {
                                ImageLoaded?.Invoke(this, new EventArgs());
                            }));
                            if (widthAndHeightLabel.Text == "0 x 0")
                            {
                                widthAndHeightLabel.Text = string.Format("{0} x {1}", image.Width, image.Height);
                            }
                        }));
                    }
                    catch (System.IO.FileNotFoundException) { }
                    catch (OperationCanceledException) { }
                    catch (BadImageFormatException)
                    {
                        pictureBox1.BackgroundImage = Resources.no_image;
                        Invoke(new MethodInvoker(() =>
                        {
                            ImageLoaded?.Invoke(this, new EventArgs());
                        }));
                    }
                }
                catch (Exception ex)
                {
                    OnError(ex);
                }
            });
        }
Ejemplo n.º 26
0
        TextureSet CreateTextureSet(RendererParameters textParameters, List <string> embeddedItems)
        {
            EmbeddedItemInfo[] embeddedItemLayout = new EmbeddedItemInfo[0];
            PixelBuffer        pixelBuffer        = TextUtils.Render(textParameters, ref embeddedItemLayout);

            uint dstWidth  = pixelBuffer.GetWidth();
            uint dstHeight = pixelBuffer.GetHeight();

            int index  = 0;
            int length = embeddedItemLayout.Length;

            for (int i = 0; i < length; i++)
            {
                EmbeddedItemInfo itemLayout = embeddedItemLayout[i];
                int width  = (int)itemLayout.Size.Width;
                int height = (int)itemLayout.Size.Height;

                int x = (int)itemLayout.Position.X;
                int y = (int)itemLayout.Position.Y;

                PixelBuffer itemPixelBuffer = ImageLoading.LoadImageFromFile(embeddedItems[index++]);

                if (itemPixelBuffer == null)
                {
                    continue;
                }

                itemPixelBuffer.Resize((ushort)width, (ushort)height);
                itemPixelBuffer.Rotate(itemLayout.Angle);


                width  = (int)itemPixelBuffer.GetWidth();
                height = (int)itemPixelBuffer.GetHeight();

                PixelFormat itemPixelFormat = itemPixelBuffer.GetPixelFormat();

                // Check if the item is out of the buffer.
                if ((x + width < 0) ||
                    (x > dstWidth) ||
                    (y < 0) ||
                    (y - height > dstHeight))
                {
                    // The embedded item is completely out of the buffer.
                    continue;
                }

                // Crop if it exceeds the boundaries of the destination buffer.
                int layoutX   = 0;
                int layoutY   = 0;
                int cropX     = 0;
                int cropY     = 0;
                int newWidth  = width;
                int newHeight = height;

                bool crop = false;

                if (0 > x)
                {
                    newWidth += x;
                    cropX     = Math.Abs(x);
                    crop      = true;
                }
                else
                {
                    layoutX = x;
                }

                if (cropX + newWidth > dstWidth)
                {
                    crop      = true;
                    newWidth -= (int)((cropX + newWidth) - dstWidth);
                }

                layoutY = y;
                if (0 > layoutY)
                {
                    newHeight += layoutY;
                    cropY      = Math.Abs(layoutY);
                    crop       = true;
                }

                if (cropY + newHeight > dstHeight)
                {
                    crop       = true;
                    newHeight -= (int)((cropY + newHeight) - dstHeight);
                }

                int uiCropX     = cropX;
                int uiCropY     = cropY;
                int uiNewWidth  = newWidth;
                int uiNewHeight = newHeight;

                if (crop)
                {
                    itemPixelBuffer.Crop((ushort)uiCropX, (ushort)uiCropY, (ushort)uiNewWidth, (ushort)uiNewHeight);
                }

                // Blend the item pixel buffer with the text's color according its blending mode.
                if (ColorBlendingMode.Multiply == itemLayout.ColorBlendingMode)
                {
                    PixelBuffer buffer = new PixelBuffer((uint)uiNewWidth, (uint)uiNewHeight, itemPixelFormat);

                    IntPtr bufferIntPtr     = buffer.GetBuffer();
                    IntPtr itemBufferIntPtr = itemPixelBuffer.GetBuffer();

                    uint bytesPerPixel = GetBytesPerPixel(itemPixelFormat);
                    uint size          = (uint)(uiNewWidth * uiNewHeight * bytesPerPixel);


                    unsafe {
                        byte *bufferPtr     = (byte *)bufferIntPtr.ToPointer();
                        byte *itemBufferPtr = (byte *)itemBufferIntPtr.ToPointer();

                        for (uint j = 0; j < size; j += bytesPerPixel)
                        {
                            *(bufferPtr + 0) = (byte)((*(itemBufferPtr + 0u)) * textParameters.TextColor.R);
                            *(bufferPtr + 1) = (byte)((*(itemBufferPtr + 1u)) * textParameters.TextColor.G);
                            *(bufferPtr + 2) = (byte)((*(itemBufferPtr + 2u)) * textParameters.TextColor.B);
                            *(bufferPtr + 3) = (byte)((*(itemBufferPtr + 3u)) * textParameters.TextColor.A);

                            itemBufferPtr += bytesPerPixel;
                            bufferPtr     += bytesPerPixel;
                        }
                    }

                    itemPixelBuffer = buffer;
                }

                TextUtils.UpdateBuffer(itemPixelBuffer, pixelBuffer, (uint)layoutX, (uint)layoutY, true);
            }

            PixelData pixelData = PixelBuffer.Convert(pixelBuffer);

            Texture texture = new Texture(TextureType.TEXTURE_2D,
                                          pixelData.GetPixelFormat(),
                                          pixelData.GetWidth(),
                                          pixelData.GetHeight());

            texture.Upload(pixelData);

            TextureSet textureSet = new TextureSet();

            textureSet.SetTexture(0u, texture);

            return(textureSet);
        }
Ejemplo n.º 27
0
        private void UpdateImage(int key, PropertyValue value)
        {
            PropertyMap temp = new PropertyMap();

            if (_alphaMaskUrl != null)
            {
                temp.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(_alphaMaskUrl));
            }

            if (_resourceUrl == "")
            {
                temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl));
                SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp));
                return;
            }

            if (_border == null)
            {
                temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
            }
            else
            {
                temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch));
                temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border));
            }

            temp.Insert(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(_synchronosLoading));

            if (backgroundExtraData != null && backgroundExtraData.CornerRadius > 0)
            {
                temp.Insert(Visual.Property.CornerRadius, new PropertyValue(backgroundExtraData.CornerRadius));
            }

            if (value != null)
            {
                temp.Insert(key, value);
            }

            // Do Fitting Buffer when desired dimension is set
            if (_desired_width != -1 && _desired_height != -1)
            {
                if (_resourceUrl != null)
                {
                    Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl);

                    int ret_width, ret_height;
                    if (imageSize.Width > imageSize.Height)
                    {
                        ret_width  = _desired_width;
                        ret_height = imageSize.Height * _desired_height / (imageSize.Width);
                    }
                    else
                    {
                        ret_width  = imageSize.Width * _desired_width / (imageSize.Height);
                        ret_height = _desired_height;
                    }
                    temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue((int)ret_width));
                    temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue((int)ret_height));
                    temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)FittingModeType.ShrinkToFit));
                }
            }

            UpdateImageMap(temp);

            temp.Dispose();
            temp = null;
        }
Ejemplo n.º 28
0
        private void AddManyViews()
        {
            Random rand = new Random();

            for (int i = 0; i < AutoDisposedObjectCount; i++)
            {
                int viewSize = 150;
                var view     = new Custom3DView()
                {
                    Size     = new Size(viewSize, viewSize, viewSize),
                    Position = new Position(
                        rand.Next(10, win.WindowSize.Width - 10),
                        rand.Next(10, win.WindowSize.Height - 10),
                        rand.Next(-3 * viewSize, 3 * viewSize)
                        ),
                };
                root.Add(view);

                PixelData pixelData = PixelBuffer.Convert(ImageLoading.LoadImageFromFile(
                                                              resource + "/images/PopupTest/circle.jpg",
                                                              new Size2D(),
                                                              FittingModeType.ScaleToFill
                                                              ));
                Texture texture = new Texture(
                    TextureType.TEXTURE_2D,
                    pixelData.GetPixelFormat(),
                    pixelData.GetWidth(),
                    pixelData.GetHeight()
                    );
                texture.Upload(pixelData);
                TextureSet textureSet = new TextureSet();
                textureSet.SetTexture(0u, texture);
                Renderer renderer = new Renderer(GenerateGeometry(), new Shader(VERTEX_SHADER, FRAGMENT_SHADER));
                renderer.SetTextures(textureSet);
                view.AddRenderer(renderer);

                rotateAnimation.AnimateBy(view, "Orientation", new Rotation(new Radian(new Degree(360.0f)), Vector3.YAxis));
            }

            for (int i = 0; i < ManualDisposedObjectCount; i++)
            {
                int viewSize = 150;
                var view     = new Custom3DView()
                {
                    Size     = new Size(viewSize, viewSize, viewSize),
                    Position = new Position(
                        rand.Next(10, win.WindowSize.Width - 10),
                        rand.Next(10, win.WindowSize.Height - 10),
                        rand.Next(-3 * viewSize, 3 * viewSize)
                        ),
                };
                root.Add(view);
                views.Add(view);

                PixelData pixelData = PixelBuffer.Convert(ImageLoading.LoadImageFromFile(
                                                              resource + "/images/PaletteTest/red2.jpg",
                                                              new Size2D(),
                                                              FittingModeType.ScaleToFill
                                                              ));
                Texture texture = new Texture(
                    TextureType.TEXTURE_2D,
                    pixelData.GetPixelFormat(),
                    pixelData.GetWidth(),
                    pixelData.GetHeight()
                    );
                texture.Upload(pixelData);
                TextureSet textureSet = new TextureSet();
                textureSet.SetTexture(0u, texture);
                Renderer renderer = new Renderer(GenerateGeometry(), new Shader(VERTEX_SHADER, FRAGMENT_SHADER));
                renderer.SetTextures(textureSet);
                view.AddRenderer(renderer);

                rotateAnimation.AnimateBy(view, "Orientation", new Rotation(new Radian(new Degree(-360.0f)), Vector3.YAxis));
            }
            rotateAnimation.Looping = true;
            rotateAnimation.Play();
        }
Ejemplo n.º 29
0
        /// <summary>
        /// View which is clipping image and applying mask
        /// </summary>
        /// <param name="resourceImageUrl">Image which will be cripped</param>
        /// <param name="maskImageUrl">Image for masking</param>
        public ClippingMaskView(string resourceImageUrl, string maskImageUrl)
        {
            // Load mask image file and make PixelData
            PixelData pixelData = PixelBuffer.Convert(
                ImageLoading.LoadImageFromFile(
                    maskImageUrl,
                    new Size2D(),
                    FittingModeType.ScaleToFill
                    )
                );

            // Make mask image texture and upload.
            Texture maskTexture = new Texture(
                TextureType.TEXTURE_2D,
                pixelData.GetPixelFormat(),
                pixelData.GetWidth(),
                pixelData.GetHeight()
                );

            maskTexture.Upload(pixelData);

            Size maskImageSize = new Size(maskTexture.GetWidth(), maskTexture.GetHeight());

            // Background Image will be clipped
            BackgroundImage = new ImageView()
            {
                PositionUsesPivotPoint = true,
                PivotPoint             = Tizen.NUI.PivotPoint.Center,
                ParentOrigin           = Tizen.NUI.ParentOrigin.Center,
                Size        = maskImageSize,
                ResourceUrl = resourceImageUrl,
            };
            Add(BackgroundImage);

            // Set properties for render task
            Camera camera = new Camera(new Vector2(maskImageSize.Width, maskImageSize.Height))
            {
                PositionUsesPivotPoint = true,
                PivotPoint             = Tizen.NUI.PivotPoint.Center,
                ParentOrigin           = Tizen.NUI.ParentOrigin.Center,
            };

            camera.SetInvertYAxis(true);
            Add(camera);

            RenderTask task = NUIApplication.GetDefaultWindow().GetRenderTaskList().CreateTask();

            task.SetRefreshRate((uint)RenderTask.RefreshRate.REFRESH_ALWAYS);
            task.SetSourceView(BackgroundImage);
            task.SetExclusive(true);
            task.SetInputEnabled(false);
            task.SetClearColor(new Vector4(1.0f, 1.0f, 1.0f, 1.0f));
            task.SetClearEnabled(true);
            task.SetCamera(camera);

            // Clipped Texture
            Texture clippedTexture = new Texture(
                TextureType.TEXTURE_2D,
                PixelFormat.RGBA8888,
                (uint)maskImageSize.Width,
                (uint)maskImageSize.Height
                );

            FrameBuffer frameBuffer = new FrameBuffer(
                (uint)maskImageSize.Width,
                (uint)maskImageSize.Height,
                (uint)FrameBuffer.Attachment.Mask.NONE
                );

            frameBuffer.AttachColorTexture(clippedTexture);
            task.SetFrameBuffer(frameBuffer);

            /* Create Renderer to apply mask */
            PropertyMap vertexFormat = new PropertyMap();

            vertexFormat.Add("aPosition", new PropertyValue((int)PropertyType.Vector2));
            PropertyBuffer vertexBuffer = new PropertyBuffer(vertexFormat);

            vertexBuffer.SetData(RectangleDataPtr(), 4);

            /* Create geometry */
            Geometry geometry = new Geometry();

            geometry.AddVertexBuffer(vertexBuffer);
            geometry.SetType(Geometry.Type.TRIANGLE_STRIP);

            /* Create Shader */
            Shader shader = new Shader(VERTEX_SHADER, FRAGMENT_SHADER);

            TextureSet textureSet = new TextureSet();

            textureSet.SetTexture(0u, clippedTexture);
            textureSet.SetTexture(1u, maskTexture);

            Renderer renderer = new Renderer(geometry, shader);

            renderer.SetTextures(textureSet);

            AddRenderer(renderer);
        }
Ejemplo n.º 30
0
 void CompletedHandler(UIImage image, NSError error, SDImageCacheType cacheType, NSUrl url)
 {
     ImageLoading.StopAnimating();
     ImageLoading.Hidden = true;
     CoverImage.FadeIn();
 }