コード例 #1
0
        private byte[,] LoadSpriteType0(SpriteHeader sh, byte[] data, int offset)
        {
            var sw         = Stopwatch.StartNew();
            var imageBytes = new byte[sh.FullHeight, sh.FullWidth * 3];
            int padding    = ((4 - ((sh.FullWidth * 3) % 4)) % 4) * 3;

            int pos = offset;

            for (int i = 0; i < sh.SpriteHeight; i++)
            {
                int currentCol = 0;
                for (int j = 0; j < sh.SpriteWidth; j++)
                {
                    byte color = bytes[pos++];
                    imageBytes[i, currentCol++] = palette[color, 2];
                    imageBytes[i, currentCol++] = palette[color, 1];
                    imageBytes[i, currentCol++] = palette[color, 0];
                }

                for (int j = 0; j < padding; j++)
                {
                    imageBytes[i, currentCol++] = palette[0, 2];
                    imageBytes[i, currentCol++] = palette[0, 1];
                    imageBytes[i, currentCol++] = palette[0, 0];
                }
            }
            double result = sw.ElapsedTicks / (double)Stopwatch.Frequency;

            Debug.WriteLine("LoadSpriteType0: " + result);
            return(imageBytes);
        }
コード例 #2
0
        private unsafe void LoadSpriteType0(SpriteHeader sh, BitmapData data, int offset)
        {
            var watch = Stopwatch.StartNew();

            byte *currentRow = (byte *)data.Scan0.ToPointer();

            int padding = (4 - ((sh.FullWidth * 3) % 4)) % 4;
            int pos     = offset;

            for (int i = 0; i < sh.SpriteHeight; i++)
            {
                for (int j = 0; j < sh.SpriteWidth; j++)
                {
                    byte color      = bytes[pos++];
                    *    currentRow = palette[color, 2];
                    currentRow++;
                    *currentRow = palette[color, 1];
                    currentRow++;
                    *currentRow = palette[color, 0];
                    currentRow++;
                }
                currentRow += 3 * padding;
            }
            double result = watch.ElapsedTicks / (double)Stopwatch.Frequency;
            //Debug.WriteLine("t0: " + result);
        }
コード例 #3
0
        private unsafe void LoadSpriteType3(SpriteHeader sh, BitmapData data, int offset)
        {
            var watch = Stopwatch.StartNew();
            int len   = sh.SpriteHeight;

            int[] ffsets = new int[len];
            for (int i = 0; i < len; i++)
            {
                ffsets[i] = BitConverter.ToUInt16(bytes, offset + i * 2 * (sh.SpriteWidth / 32));
            }

            byte *ptr = (byte *)data.Scan0.ToPointer();
            byte *currentRow;
            byte  type;
            int   blength;

            for (int i = 0; i < len; i++)
            {
                int pos = ffsets[i] + offset;
                currentRow = ptr + (sh.TopMargin + i) * data.Stride + sh.LeftMargin * 3;

                int bound;
                if (i < len - 1)
                {
                    bound = offset + ffsets[i + 1];
                }
                else
                {
                    bound = Math.Min(offset + ffsets[i] - sh.SpriteWidth, bytes.Length);
                }

                while (pos < bound)
                {
                    blength = (bytes[pos] & 0x1f) + 1;
                    type    = (byte)(bytes[pos] >> 5);
                    pos++;
                    if (type == 0)
                    {
                        currentRow += 3 * blength;
                    }
                    else if (type == 7)
                    {
                        for (int j = 0; j < blength; j++)
                        {
                            byte color      = bytes[pos];
                            *    currentRow = palette[color, 2];
                            currentRow++;
                            *currentRow = palette[color, 1];
                            currentRow++;
                            *currentRow = palette[color, 0];
                            currentRow++;
                            pos++;
                        }
                    }
                    else
                    {
                        int pIndex = 0;
                        if (type == 1)
                        {
                            pIndex = 1;
                        }
                        else if (type == 4 || type == 2)
                        {
                            pIndex = 2;
                        }
                        else if (type == 5)
                        {
                            pIndex = 5;
                        }
                        else
                        {
                            pIndex = type;
                        }

                        for (int j = 0; j < blength; j++)
                        {
                            *currentRow = palette[pIndex, 2];
                            currentRow++;
                            *currentRow = palette[pIndex, 1];
                            currentRow++;
                            *currentRow = palette[pIndex, 0];
                            currentRow++;
                        }
                    }
                }
            }
            double result = watch.ElapsedTicks / (double)System.Diagnostics.Stopwatch.Frequency;
            //Debug.WriteLine("t3: " + result);
        }
コード例 #4
0
        private unsafe byte[] LoadSpriteType12(SpriteHeader sh, byte[] data, int offset)
        {
            int len = sh.SpriteHeight;
            int tm  = sh.TopMargin;
            int lm  = sh.LeftMargin;
            int sw  = sh.SpriteWidth;

            if (sh.SpriteHeight > sh.FullHeight)
            {
                len     = sh.FullHeight;
                tm      = 0;
                lm      = 0;
                sw      = 0;
                offset -= 16;
            }

            int type, blength;
            int bWidth = sh.FullWidth * 3;

            if (bWidth % 4 != 0)
            {
                bWidth += 4 - bWidth % 4;
            }


            int bw4 = bWidth / 4;

            var imageBytes = new byte[sh.FullHeight * bWidth];

            int[] ffsets = new int[len];
            for (int i = 0; i < len; i++)
            {
                ffsets[i] = BitConverter.ToInt32(bytes, offset + i * 4);
            }

            int currentCol = 0;
            int boundary   = imageBytes.Length / 3;


            fixed(byte *ptr = imageBytes)
            {
                /* for (int i = 0; i < len; i++)
                 * {
                 *   int pos = ffsets[i] + offset;
                 *   currentCol = (tm+i) * bWidth + lm * 3;
                 *
                 *   int bound;
                 *   if (i < len - 1)
                 *       bound = offset + ffsets[i + 1];
                 *   else
                 *       bound = Math.Min(offset + ffsets[i] + sw, bytes.Length);
                 *
                 *   while (pos < bound)
                 *   {
                 *       type = bytes[pos++];
                 *       blength = (bytes[pos++] + 1);
                 *       if (type == 0xff)
                 *       {
                 *           for (int j = 0; j < blength; j++)
                 *           {
                 *((int*)(ptr + currentCol)) = palette2[bytes[pos]];
                 *               currentCol += 3;
                 *               pos++;
                 *           }
                 *       }
                 *       else
                 *       {
                 *           for (int j = 0; j < blength; j++)
                 *           {
                 *((int*)(ptr + currentCol)) = palette2[type];
                 *               currentCol += 3;
                 *           }
                 *       }
                 *   }
                 * }*/

                int pos;

                for (int i = 0; i < len - 1; i++)
                {
                    pos        = ffsets[i] + offset;
                    currentCol = (tm + i) * bWidth + lm * 3;

                    int bound;
                    if (i < len - 1)
                    {
                        bound = offset + ffsets[i + 1];
                    }
                    else
                    {
                        bound = Math.Min(offset + ffsets[i] + sw, bytes.Length);
                    }

                    while (pos < bound)
                    {
                        type    = bytes[pos++];
                        blength = (bytes[pos++] + 1);
                        if (type == 0xff)
                        {
                            for (int j = 0; j < blength; j++)
                            {
                                *((int *)(ptr + currentCol)) = palette2[bytes[pos]];
                                currentCol += 3;
                                pos++;
                            }
                        }
                        else
                        {
                            for (int j = 0; j < blength; j++)
                            {
                                *((int *)(ptr + currentCol)) = palette2[type];
                                currentCol += 3;
                            }
                        }
                    }
                }
                // last row

                pos = ffsets[len - 1] + offset;
                byte *cb = ptr + (tm + len - 1) * bWidth + lm * 3;

                int currentWidth = 0;

                while (currentWidth < sw)
                {
                    type    = bytes[pos++];
                    blength = (bytes[pos++] + 1);
                    if (type == 0xff)
                    {
                        for (int j = 0; j < blength; j++)
                        {
                            byte color = bytes[pos];
                            *    cb    = palette[color, 2];
                            cb++;
                            *cb = palette[color, 1];
                            cb++;
                            *cb = palette[color, 0];
                            cb++;
                            pos++;
                        }
                    }
                    else
                    {
                        for (int j = 0; j < blength; j++)
                        {
                            *cb = palette[type, 2];
                            cb++;
                            *cb = palette[type, 1];
                            cb++;
                            *cb = palette[type, 0];
                            cb++;
                        }
                    }
                    currentWidth += blength;
                }
            }

            return(imageBytes);
        }
コード例 #5
0
        private unsafe void LoadSpriteType1(SpriteHeader sh, BitmapData data, int offset)
        {
            var watch = Stopwatch.StartNew();
            int len   = sh.SpriteHeight;
            int tm    = sh.TopMargin;
            int lm    = sh.LeftMargin;
            int sw    = sh.SpriteWidth;

            if (sh.SpriteHeight > sh.FullHeight)
            {
                len     = sh.FullHeight;
                tm      = 0;
                lm      = 0;
                sw      = sh.FullWidth;
                offset -= 16;
            }

            int[] offB = new int[len];
            for (int i = 0; i < len; i++)
            {
                offB[i] = BitConverter.ToInt32(bytes, offset + i * 4);
            }

            byte *ptr = (byte *)data.Scan0.ToPointer();
            byte *currentRow;
            byte  type;
            int   blength;

            for (int i = 0; i < len; i++)
            {
                int pos = offB[i] + offset;
                currentRow = ptr + (tm + i) * data.Stride + lm * 3;

                int currentWidth = 0;
                while (currentWidth < sw)
                {
                    type    = bytes[pos++];
                    blength = (bytes[pos++] + 1);
                    if (type == 0xff)
                    {
                        for (int j = 0; j < blength; j++)
                        {
                            byte color      = bytes[pos];
                            *    currentRow = palette[color, 2];
                            currentRow++;
                            *currentRow = palette[color, 1];
                            currentRow++;
                            *currentRow = palette[color, 0];
                            currentRow++;
                            pos++;
                        }
                    }
                    else
                    {
                        for (int j = 0; j < blength; j++)
                        {
                            *currentRow = palette[type, 2];
                            currentRow++;
                            *currentRow = palette[type, 1];
                            currentRow++;
                            *currentRow = palette[type, 0];
                            currentRow++;
                        }
                    }
                    currentWidth += blength;
                }
            }
            double result = watch.ElapsedTicks / (double)Stopwatch.Frequency;
            // Debug.WriteLine("t1: " + result);
        }