Beispiel #1
0
        private static void RunAddGreenToBlueAndRedTest()
        {
            uint[] pixelData =
            {
                4284188659, 4284254193, 4284318702, 4284187883, 4284318441, 4284383470, 4284318700, 4284124392,
                4283799012, 4283864546, 4284581610, 4285163264, 4284891926, 4284497945, 4284761620, 4284893965,
                4284828428, 4284959500, 4284959755, 4284828426, 4284960520, 4285289733, 4285159937, 4285292030,
                4285358077, 4285228030, 4284966398, 4285097213, 4285227773, 4285096956, 4285097470, 4285228540,
                4285163516, 4285425149, 4285294332, 4285228540, 4285228543, 4285163261, 4285163516, 4285032701,
                4284835841, 4284835584, 4284966140, 4285228029, 4284770300, 4285097214, 4285293819, 4285228795,
                4285163259, 4285228287, 4284901886
            };

            uint[] expectedOutput =
            {
                4293035898, 4293101432, 4292903793, 4292838511, 4292837995, 4292771950, 4292903791, 4293299316,
                4293563769, 4293629303, 4293363312, 4291913575, 4289282905, 4288692313, 4289349210, 4289809240,
                4289743703, 4289874775, 4289940567, 4289743701, 4290137943, 4290860378, 4291058267, 4291386715,
                4291583836, 4291715937, 4291585379, 4291650657, 4291650143, 4291584863, 4291716451, 4291847521,
                4291913571, 4292044130, 4291978850, 4291847521, 4291847524, 4291847779, 4291913571, 4291848293,
                4291651689, 4291585895, 4291519584, 4291715936, 4291520355, 4291650658, 4291847263, 4291913313,
                4291847777, 4291781731, 4291783015
            };

            LosslessUtils.AddGreenToBlueAndRed(pixelData);

            Assert.Equal(expectedOutput, pixelData);
        }
Beispiel #2
0
        /// <summary>
        /// A Webp lossless image can go through four different types of transformation before being entropy encoded.
        /// This will reverse the transformations, if any are present.
        /// </summary>
        /// <param name="decoder">The decoder holding the transformation infos.</param>
        /// <param name="pixelData">The pixel data to apply the transformation.</param>
        /// <param name="memoryAllocator">The memory allocator is needed to allocate memory during the predictor transform.</param>
        public static void ApplyInverseTransforms(Vp8LDecoder decoder, Span <uint> pixelData, MemoryAllocator memoryAllocator)
        {
            List <Vp8LTransform> transforms = decoder.Transforms;

            for (int i = transforms.Count - 1; i >= 0; i--)
            {
                Vp8LTransform     transform     = transforms[i];
                Vp8LTransformType transformType = transform.TransformType;
                switch (transformType)
                {
                case Vp8LTransformType.PredictorTransform:
                    using (IMemoryOwner <uint> output = memoryAllocator.Allocate <uint>(pixelData.Length, AllocationOptions.Clean))
                    {
                        LosslessUtils.PredictorInverseTransform(transform, pixelData, output.GetSpan());
                    }

                    break;

                case Vp8LTransformType.SubtractGreen:
                    LosslessUtils.AddGreenToBlueAndRed(pixelData);
                    break;

                case Vp8LTransformType.CrossColorTransform:
                    LosslessUtils.ColorSpaceInverseTransform(transform, pixelData);
                    break;

                case Vp8LTransformType.ColorIndexingTransform:
                    LosslessUtils.ColorIndexInverseTransform(transform, pixelData);
                    break;
                }
            }
        }