Example #1
0
        public IEnumerable <Color> Process(ulong data)
        {
            // If color0 > color1, we can store 1 bit alpha
            // Otherwise no alpha

            var(color0, color1) = ((ushort)data, (ushort)(data >> 16));
            var(c0, c1)         = (Rgb565.GetColor(color0), Rgb565.GetColor(color1));

            for (var i = 0; i < 16; i++)
            {
                var code = (int)(data >> (32 + 2 * i)) & 3;

                if (color0 > color1)
                {
                    yield return(code == 0 ? c0 :
                                 code == 1 ? c1 :
                                 code == 2 ? InterpolateColor(c0, c1, 2, 3) :
                                 Color.Transparent);
                }
                else
                {
                    yield return(code == 0 ? c0 :
                                 code == 1 ? c1 :
                                 InterpolateColor(c0, c1, 4 - code, 3));
                }
            }
        }
Example #2
0
        /// <inheritdoc cref="Load"/>
        public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext)
        {
            var br = new BinaryReaderX(new MemoryStream(input), _byteOrder, _bitOrder, 1);

            return(ReadValues(br).AsParallel().AsOrdered()
                   .WithDegreeOfParallelism(loadContext.TaskCount)
                   .Select(v => _descriptor.GetColor(v)));
        }
Example #3
0
        /// <inheritdoc cref="Load"/>
        public IEnumerable <Color> Load(byte[] input, EncodingLoadContext loadContext)
        {
            var bits   = loadContext.Size.Width * loadContext.Size.Height * BitsPerValue;
            var length = bits / 8 + (bits % 8 > 0 ? 1 : 0);

            return(_readValuesDelegate(input, length).AsParallel().AsOrdered()
                   .WithDegreeOfParallelism(loadContext.TaskCount)
                   .Select(v => _descriptor.GetColor(v)));
        }
Example #4
0
        public IEnumerable <Color> Process(ulong data)
        {
            var(color0, color1) = ((ushort)data, (ushort)(data >> 16));
            var(c0, c1)         = (Rgb555.GetColor(color0), Rgb565.GetColor(color1));
            var method = color0 >> 15;

            for (var i = 0; i < 16; i++)
            {
                var code = (int)(data >> (32 + 2 * i)) & 3;

                if (method == 0)
                {
                    yield return(InterpolateColor0(c0, c1, code, 3));
                }
                else
                {
                    yield return(code == 0 ? Color.Black :
                                 code == 1 ? InterpolateColor1(c0, c1, 1, 4) :
                                 code == 2 ? c0 :
                                 c1);
                }
            }
        }
Example #5
0
 private ushort FromRgb565ToRgb555(ushort color0)
 {
     return((ushort)Rgb555.GetValue(Rgb565.GetColor(color0)));
 }