Beispiel #1
0
        public Palette(BitDepth bitDepth)
        {
            this.BitDepth = bitDepth;

            switch (this.BitDepth)
            {
            case BitDepth.OneBpp:
                this.colors = new Color[2];
                break;

            case BitDepth.TwoBpp:
                this.colors = new Color[4];
                break;

            case BitDepth.FourBpp:
                this.colors = new Color[16];
                break;

            case BitDepth.EightBpp:
                this.colors = new Color[256];
                break;

            default:
                throw new Exception(String.Format("Invalid bit depth {0}.", bitDepth.ToString()));
            }

            this.colors.Length.Times(i => this.colors[i] = Color.Black); // oh, this is nice.

            if (!hasAssignedPalettes)
            {
                this.AssignPalettes();
            }
        }
Beispiel #2
0
        public Palette(BitDepth bitDepth)
        {
            this.BitDepth = bitDepth;

            switch (this.BitDepth)
            {
                case BitDepth.OneBpp:
                    this.colors = new Color[2];
                    break;
                case BitDepth.TwoBpp:
                    this.colors = new Color[4];
                    break;
                case BitDepth.FourBpp:
                    this.colors = new Color[16];
                    break;
                case BitDepth.EightBpp:
                    this.colors = new Color[256];
                    break;
                default:
                    throw new Exception(String.Format("Invalid bit depth {0}.", bitDepth.ToString()));
            }

            this.colors.Length.Times(i => this.colors[i] = Color.Black); // oh, this is nice.

            if (!hasAssignedPalettes)
            {
                this.AssignPalettes();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns a string that represents the current object.
        /// </summary>
        /// <returns>A string that represents the current object.</returns>
        /// <since_tizen> 3 </since_tizen>
        public override string ToString()
        {
            var toString = $@"MimeType={ MimeType.ToString() }, Channel={ Channel.ToString() }, SampleRate={ SampleRate },
                Bit={ Bit.ToString() }, BitRate={ BitRate.ToString() }, BitDepth={ BitDepth.ToString() }, AacType={ AacType.ToString()}";

            if (AudioChannelMap != null)
            {
                toString += ", AudioChannelMap=" + $"{string.Join(",", AudioChannelMap)}";
            }

            return(toString);
        }
Beispiel #4
0
        protected void CopyFromNoClipping(IImageByte sourceImage, RectangleInt clippedSourceImageRect, int destXOffset, int destYOffset)
        {
            if (GetBytesBetweenPixelsInclusive() != BitDepth / 8 ||
                sourceImage.GetBytesBetweenPixelsInclusive() != sourceImage.BitDepth / 8)
            {
                throw new Exception("WIP we only support packed pixel formats at this time.");
            }

            if (BitDepth == sourceImage.BitDepth)
            {
                int lengthInBytes = clippedSourceImageRect.Width * GetBytesBetweenPixelsInclusive();

                int    sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);
                byte[] sourceBuffer = sourceImage.GetBuffer();
                int    destOffset;
                byte[] destBuffer = GetPixelPointerXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset, out destOffset);

                for (int i = 0; i < clippedSourceImageRect.Height; i++)
                {
                    agg_basics.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes);
                    sourceOffset += sourceImage.StrideInBytes();
                    destOffset   += StrideInBytes();
                }
            }
            else
            {
                bool haveConversion = true;
                switch (sourceImage.BitDepth)
                {
                case 24:
                    switch (BitDepth)
                    {
                    case 32:
                    {
                        int numPixelsToCopy = clippedSourceImageRect.Width;
                        for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++)
                        {
                            int    sourceOffset = sourceImage.GetBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);
                            byte[] sourceBuffer = sourceImage.GetBuffer();
                            int    destOffset;
                            byte[] destBuffer = GetPixelPointerXY(
                                clippedSourceImageRect.Left + destXOffset,
                                clippedSourceImageRect.Bottom + i + destYOffset,
                                out destOffset);
                            for (int x = 0; x < numPixelsToCopy; x++)
                            {
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                destBuffer[destOffset++] = 255;
                            }
                        }
                    }
                    break;

                    default:
                        haveConversion = false;
                        break;
                    }
                    break;

                default:
                    haveConversion = false;
                    break;
                }

                if (!haveConversion)
                {
                    throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion");
                }
            }
        }
Beispiel #5
0
        public void SetAlpha(byte value)
        {
            if (BitDepth != 32)
            {
                throw new Exception("You don't have alpha channel to set.  Your image has a bit depth of " + BitDepth.ToString() + ".");
            }
            int numPixels = Width * Height;
            int offset;

            byte[] buffer = GetBuffer(out offset);
            for (int i = 0; i < numPixels; i++)
            {
                buffer[offset + i * 4 + 3] = value;
            }
        }
        void CopyFromNoClipping(IImageReaderWriter sourceImage, RectInt clippedSourceImageRect, int destXOffset, int destYOffset)
        {
            if (BytesBetweenPixelsInclusive != BitDepth / 8 ||
                sourceImage.BytesBetweenPixelsInclusive != sourceImage.BitDepth / 8)
            {
                throw new Exception("WIP we only support packed pixel formats at this time.");
            }

            if (BitDepth == sourceImage.BitDepth)
            {
                int lengthInBytes = clippedSourceImageRect.Width * BytesBetweenPixelsInclusive;
                int sourceOffset  = sourceImage.GetByteBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom);

                unsafe
                {
                    TempMemPtr memPtr  = sourceImage.GetBufferPtr();
                    TempMemPtr destPtr = this.GetBufferPtr();

                    byte *sourceBuffer = (byte *)memPtr.Ptr;
                    byte *destBuffer   = (byte *)destPtr.Ptr;
                    int   destOffset   = GetByteBufferOffsetXY(clippedSourceImageRect.Left + destXOffset, clippedSourceImageRect.Bottom + destYOffset);
                    for (int i = 0; i < clippedSourceImageRect.Height; i++)
                    {
                        AggMemMx.memmove(destBuffer, destOffset, sourceBuffer, sourceOffset, lengthInBytes);
                        sourceOffset += sourceImage.Stride;
                        destOffset   += Stride;
                    }

                    memPtr.Release();
                    destPtr.Release();
                }
            }
            else
            {
                bool haveConversion = true;
                switch (sourceImage.BitDepth)
                {
                case 24:
                    switch (BitDepth)
                    {
                    case 32:
                    {
                        //TODO: review here, this may not correct
                        int numPixelsToCopy = clippedSourceImageRect.Width;
                        for (int i = clippedSourceImageRect.Bottom; i < clippedSourceImageRect.Top; i++)
                        {
                            int sourceOffset = sourceImage.GetByteBufferOffsetXY(clippedSourceImageRect.Left, clippedSourceImageRect.Bottom + i);

                            //byte[] sourceBuffer = sourceImage.GetBuffer();
                            //byte[] destBuffer = GetBuffer();

                            TempMemPtr srcMemPtr     = sourceImage.GetBufferPtr();
                            TempMemPtr destBufferPtr = this.GetBufferPtr();

                            int destOffset = GetByteBufferOffsetXY(
                                clippedSourceImageRect.Left + destXOffset,
                                clippedSourceImageRect.Bottom + i + destYOffset);
                            unsafe
                            {
                                byte *destBuffer   = (byte *)destBufferPtr.Ptr;
                                byte *sourceBuffer = (byte *)srcMemPtr.Ptr;
                                for (int x = 0; x < numPixelsToCopy; x++)
                                {
                                    destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                    destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                    destBuffer[destOffset++] = sourceBuffer[sourceOffset++];
                                    destBuffer[destOffset++] = 255;
                                }
                            }


                            srcMemPtr.Release();
                            destBufferPtr.Release();
                        }
                    }
                    break;

                    default:
                        haveConversion = false;
                        break;
                    }
                    break;

                default:
                    haveConversion = false;
                    break;
                }

                if (!haveConversion)
                {
                    throw new NotImplementedException("You need to write the " + sourceImage.BitDepth.ToString() + " to " + BitDepth.ToString() + " conversion");
                }
            }
        }