コード例 #1
0
        private static async Task <Palette> AsyncTask(PixelBuffer pixelBuffer, Rectangle region, PaletteGeneratedEventHandler paletteGeneratedEventHandler)
        {
            if (paletteGeneratedEventHandler == null)
            {
                throw new ArgumentNullException(nameof(paletteGeneratedEventHandler), "PaletteGeneratedEventHandlergate should not be null.");
            }

            var GenerateTask = Task.Run(() =>
            {
                return(Generate(pixelBuffer, region));
            }).ConfigureAwait(false);

            Palette ret = await GenerateTask;

            paletteGeneratedEventHandler(ret);

            return(null);;
        }
コード例 #2
0
        public static PixelBuffer LoadImageFromBuffer(System.IO.Stream stream, Size2D size)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }
            if (size == null)
            {
                throw new ArgumentNullException(nameof(size));
            }
            long streamLength = stream.Length - stream.Position;

            if (streamLength <= 0)
            {
                throw new InvalidOperationException("stream lenght is <= 0");
            }

            // Read data from stream
            byte[] streamData = new byte[streamLength];
            stream.Read(streamData, 0, (int)streamLength);

            // Allocate buffer that internal DALi engine can read
            VectorUnsignedChar buffer = new VectorUnsignedChar();

            buffer.Resize((uint)streamLength);
            var bufferBegin = buffer.Begin();

            global::System.Runtime.InteropServices.HandleRef bufferRef = SWIGTYPE_p_unsigned_char.getCPtr(bufferBegin);

            // Copy data from stream to buffer
            System.Runtime.InteropServices.Marshal.Copy(streamData, 0, bufferRef.Handle, (int)streamLength);

            var         uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
            PixelBuffer ret   = new PixelBuffer(Interop.ImageLoading.LoadImageFromBuffer(VectorUnsignedChar.getCPtr(buffer), Uint16Pair.getCPtr(uSize)), true);

            uSize.Dispose();
            buffer.Dispose();
            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
コード例 #3
0
        /// <summary>
        /// Scale the bitmap down so that it's smallest dimension is
        /// calculateBitmapMinDimensionpx. If bitmap is smaller than this, than it
        /// is returned.
        /// </summary>
        private static bool ScaleBitmapDown(PixelBuffer pixelBuffer)
        {
            int minDimension = Math.Min((int)pixelBuffer.GetWidth(), (int)pixelBuffer.GetHeight());

            if (minDimension <= calculateBitmapMinDimension)
            {
                // If the bitmap is small enough already, just return it
                return(false);
            }

            float scaleRatio = calculateBitmapMinDimension / (float)minDimension;

            int width  = (int)Math.Round((int)pixelBuffer.GetWidth() * scaleRatio);
            int height = (int)Math.Round((int)pixelBuffer.GetHeight() * scaleRatio);

            Tizen.Log.Info("Palette", "pixelBuffer resize to  " + width + " " + height + "\n");
            pixelBuffer.Resize((ushort)width, (ushort)height);

            return(true);
        }
コード例 #4
0
        public static PixelBuffer DownloadImageSynchronously(Uri uri, Size2D size)
        {
            if (null == size)
            {
                throw new ArgumentNullException(nameof(size));
            }
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            var         uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
            PixelBuffer ret   = new PixelBuffer(Interop.ImageLoading.DownloadImageSynchronously(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize)), true);

            uSize.Dispose();
            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
コード例 #5
0
        public static PixelBuffer LoadImageFromFile(Uri uri, Size2D size, FittingModeType fittingMode, SamplingModeType samplingMode)
        {
            if (null == size)
            {
                throw new ArgumentNullException(nameof(size));
            }
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            var         uSize = new Uint16Pair((uint)size.Width, (uint)size.Height);
            PixelBuffer ret   = new PixelBuffer(Interop.ImageLoading.LoadImageFromFile(uri.AbsoluteUri, Uint16Pair.getCPtr(uSize), (int)fittingMode, (int)samplingMode), true);

            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }

            uSize.Dispose();
            return(ret);
        }
コード例 #6
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PixelBuffer obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
コード例 #7
0
        internal PixelBuffer Assign(PixelBuffer rhs)
        {
            PixelBuffer ret = new PixelBuffer(NDalicPINVOKE.PixelBuffer_Assign(swigCPtr, PixelBuffer.getCPtr(rhs)), false);

            if (NDalicPINVOKE.SWIGPendingException.Pending)
            {
                throw NDalicPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
コード例 #8
0
 internal PixelBuffer(PixelBuffer handle) : this(NDalicPINVOKE.new_PixelBuffer__SWIG_1(PixelBuffer.getCPtr(handle)), true)
 {
     if (NDalicPINVOKE.SWIGPendingException.Pending)
     {
         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
     }
 }
コード例 #9
0
 public static Palette generate(PixelBuffer pixelBuffer)
 {
     return(Generate(pixelBuffer, null));
 }
コード例 #10
0
 public static void GenerateAsync(PixelBuffer pixelBuffer, Tizen.NUI.Rectangle region, PaletteGeneratedEventHandler paletteGeneratedEventHandler)
 {
     _ = AsyncTask(pixelBuffer, region, paletteGeneratedEventHandler);
 }
コード例 #11
0
 public static void GenerateAsync(PixelBuffer pixelBuffer, PaletteGeneratedEventHandler paletteGeneratedEventHandler)
 {
     _ = AsyncTask(pixelBuffer, null, paletteGeneratedEventHandler);
 }