예제 #1
0
            public List <byte> ToOps(ColorTable colorTable)
            {
                var outbytes = new List <byte>();

                if (state == EncodingState.RepeatRun)
                {
                    outbytes.AddRange(SetRepeatRunLength(length));
                    var cindex = colorTable.GetColorIndex(colors[0]);
                    if (cindex >= 0x10000)
                    {
                        outbytes[0] |= (byte)0x6;
                        outbytes.AddRange(colors[0]);
                    }
                    else if (cindex >= 0x100)
                    {
                        outbytes[0] |= (byte)0x4;
                        outbytes.AddRange(BitConverter.GetBytes((ushort)cindex));
                    }
                    else
                    {
                        outbytes[0] |= (byte)0x2;
                        outbytes.Add((byte)cindex);
                    }
                    //  GetRepeatPixels(runLength, repeatIndex, opsList[mip], blockPixels);
                }
                else
                {
                    outbytes.AddRange(SetPixelRunLength(length));
                    List <int> indexes = new List <int>();
                    bool       overmax = false;
                    foreach (var item in colors)
                    {
                        var ind = colorTable.GetColorIndex(item);
                        if (ind >= 0x10000)
                        {
                            overmax = true;
                        }
                        indexes.Add(ind);
                    }
                    if (overmax)
                    {
                        outbytes[0] |= (byte)0x3;
                        foreach (var c in colors)
                        {
                            outbytes.AddRange(c);
                        }
                    }
                    else
                    {
                        outbytes[0] |= (byte)0x1;
                        foreach (var c in indexes)
                        {
                            outbytes.AddRange(SetColorIndex((uint)c));
                        }
                    }
                }
                return(outbytes);
            }