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); }
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); }
public void PixelGetPixelFormat() { tlog.Debug(tag, $"PixelGetPixelFormat START"); byte[] buffer = new byte[10]; var testingTarget = new PixelData(buffer, 10, 1, 2, PixelFormat.BGR8888, PixelData.ReleaseFunction.Free); Assert.IsNotNull(testingTarget, "Can't create success object PixelData"); Assert.IsInstanceOf <PixelData>(testingTarget, "Should be an instance of PixelData type."); var result = testingTarget.GetPixelFormat(); Assert.AreEqual(PixelFormat.BGR8888, result, "Should be equal!"); buffer = null; testingTarget.Dispose(); tlog.Debug(tag, $"PixelGetPixelFormat END (OK)"); }
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); }
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(); }
/// <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); }
private void AddManyViews() { Random rand = new Random(); for (int i = 0; i < MaxObject; i++) { int viewSize = 150; var view = new View() { Size = new Size(viewSize, viewSize, viewSize), Position = new Position(rand.Next(10, 600), rand.Next(10, 600)), }; 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); } for (int i = 0; i < MaxObject; i++) { int viewSize = 150; var view = new View() { Size = new Size(viewSize, viewSize, viewSize), Position = new Position(rand.Next(10, 600), rand.Next(10, 600)), }; 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); } }