Exemple #1
0
        internal virtual void convertimage(int[][] picture, int width, int height)
        {
            this.bfOffset = 1078;
            int pad = (4 - width % 4) * height;

            if (4 - width % 4 == 4)
            {
                pad = 0;
            }
            this.biSizeImage = width * height + pad;
            this.bfSize      = this.biSizeImage + 14 + 40 + 1024;
            this.biWidth     = width;
            this.biHeight    = height;
            imagehandler img = new imagehandler();

            img.sampleused = this.sample;
            img.loadbitmap(this.sample, 1);
            this.colortable = img.returnaokpalette();
            int pad_line = 4 - width % 4;

            if (pad_line == 4)
            {
                pad_line = 0;
            }
            this.bitmap = new byte[(width + pad_line) * height];
            int count = 0;

            for (int i = height - 1; i >= 0; i--)
            {
                int j;
                for (j = 0; j < width; j++)
                {
                    int x = picture[i][j];
                    if (x == -1)
                    {
                        x = this.mask;
                    }
                    if (x == -2)
                    {
                        x = this.outline1;
                    }
                    if (x == -3)
                    {
                        x = this.outline2;
                    }
                    if (x == -4)
                    {
                        x = this.shadow;
                    }
                    this.bitmap[count] = (byte)x;
                    count++;
                }
                for (j = 0; j < pad_line; j++)
                {
                    this.bitmap[count] = 0;
                    count++;
                }
            }
        }
Exemple #2
0
        public void Writemasks(String inputfile, String outputfile, int choice)
        {
            int          i3, i2, i1, n, m, j, k;
            imagehandler img = new imagehandler();

            img.loadbitmap(inputfile, 0);
            byte[][] f      = img.returnrawpixels();
            int      width  = (f[0]).Length;
            int      height = f.Length;


            int[][] newframe = RectangularArrays.RectangularIntArray(height, width);
            for (int i = 0; i < height; i++)
            {
                for (int i4 = 0; i4 < width; i4++)
                {
                    newframe[i][i4] = f[i][i4] & 0xFF;
                }
            }
            int mask = newframe[height - 1][0];

            switch (choice)
            {
            case 1:
                for (i3 = 0; i3 < height; i3++)
                {
                    for (int i4 = 0; i4 < width; i4++)
                    {
                        if (newframe[i3][i4] == mask)
                        {
                            newframe[i3][i4] = this.outputmask;
                        }
                        else
                        {
                            newframe[i3][i4] = 255;
                        }
                    }
                }
                break;

            case 2:
                for (i3 = 0; i3 < height; i3++)
                {
                    int i4;
                    for (i4 = 0; i4 < width - 1; i4++)
                    {
                        if (newframe[i3][i4] == mask && newframe[i3][i4 + 1] != mask && i4 + 1 != width - 1)
                        {
                            newframe[i3][i4] = -2;
                        }
                    }

                    for (i4 = width - 1; i4 > 0; i4--)
                    {
                        if (newframe[i3][i4] == mask && newframe[i3][i4 - 1] != mask && i4 + 1 != width - 1)
                        {
                            newframe[i3][i4] = -2;
                        }
                    }
                }
                for (i2 = 0; i2 < width; i2++)
                {
                    int i4;
                    for (i4 = 0; i4 <= height - 2; i4++)
                    {
                        if (newframe[i4][i2] == mask && newframe[i4 + 1][i2] != mask && newframe[i4 + 1][i2] != -2)
                        {
                            newframe[i4][i2] = -2;
                        }
                    }
                    for (i4 = height - 1; i4 > 0; i4--)
                    {
                        if (newframe[i4][i2] == mask && newframe[i4 - 1][i2] != mask && newframe[i4 - 1][i2] != -2)
                        {
                            newframe[i4][i2] = -2;
                        }
                    }
                }
                for (i1 = 0; i1 < height; i1++)
                {
                    for (int i4 = 0; i4 < width; i4++)
                    {
                        if (newframe[i1][i4] != -2)
                        {
                            newframe[i1][i4] = this.outputmask;
                        }
                    }
                }
                break;

            case 3:
                for (i1 = 0; i1 < height; i1++)
                {
                    for (int i4 = 0; i4 < width; i4++)
                    {
                        if (newframe[i1][i4] < 16 || newframe[i1][i4] > 23)
                        {
                            newframe[i1][i4] = this.outputmask;
                        }
                    }
                }
                break;

            case 4:
                for (i1 = 0; i1 < height; i1++)
                {
                    for (int i4 = 0; i4 < width; i4++)
                    {
                        if (newframe[i1][i4] == 131)
                        {
                            newframe[i1][i4] = 131;
                        }
                        else
                        {
                            newframe[i1][i4] = this.outputmask;
                        }
                    }
                }
                break;

            case 5:
                for (i1 = 0; i1 < height; i1++)
                {
                    int i4;
                    for (i4 = 0; i4 < width - 1; i4++)
                    {
                        if (newframe[i1][i4] == mask && newframe[i1][i4 + 1] != mask && i4 + 1 != width - 1)
                        {
                            newframe[i1][i4] = -2;
                        }
                    }
                    for (i4 = width - 1; i4 > 0; i4--)
                    {
                        if (newframe[i1][i4] == mask && newframe[i1][i4 - 1] != mask && i4 + 1 != width - 1)
                        {
                            newframe[i1][i4] = -2;
                        }
                    }
                }
                for (n = 0; n < width; n++)
                {
                    int i4;
                    for (i4 = 0; i4 <= height - 2; i4++)
                    {
                        if (newframe[i4][n] == mask && newframe[i4 + 1][n] != mask && newframe[i4 + 1][n] != -2)
                        {
                            newframe[i4][n] = -2;
                        }
                    }

                    for (i4 = height - 2; i4 > 0; i4--)
                    {
                        if (newframe[i4][n] == mask && newframe[i4 - 1][n] != mask && newframe[i4 - 1][n] != -2)
                        {
                            newframe[i4][n] = -2;
                        }
                    }
                }
                for (m = 0; m < height; m++)
                {
                    int i4;
                    for (i4 = 0; i4 < width - 1; i4++)
                    {
                        if (newframe[m][i4] == mask && newframe[m][i4 + 1] != mask && i4 + 1 != width - 1)
                        {
                            newframe[m][i4] = -3;
                        }
                    }
                    for (i4 = width - 1; i4 > 0; i4--)
                    {
                        if (newframe[m][i4] == mask && newframe[m][i4 - 1] != mask && i4 + 1 != width - 1)
                        {
                            newframe[m][i4] = -3;
                        }
                    }
                }
                for (j = 0; j < width; j++)
                {
                    int i4;
                    for (i4 = 0; i4 <= height - 2; i4++)
                    {
                        if (newframe[i4][j] == mask && newframe[i4 + 1][j] != mask && newframe[i4 + 1][j] != -3)
                        {
                            newframe[i4][j] = -3;
                        }
                    }

                    for (i4 = height - 2; i4 > 0; i4--)
                    {
                        if (newframe[i4][j] == mask && newframe[i4 - 1][j] != mask && newframe[i4 - 1][j] != -3)
                        {
                            newframe[i4][j] = -3;
                        }
                    }
                }
                for (k = 0; k < height; k++)
                {
                    for (int i4 = 0; i4 < width; i4++)
                    {
                        if (newframe[k][i4] != -3)
                        {
                            newframe[k][i4] = this.outputmask;
                        }
                    }
                }
                break;

            default:
                Console.WriteLine("Unrecognized command");
                break;
            }
            Aokbitmap b = new Aokbitmap(this.outputmask, this.outline1, this.outline2, this.shadow);

            b.Write(outputfile, newframe, f[0].Length, f.Length);
        }
Exemple #3
0
        public virtual void getframe(int num, string path, string filename, bool msk, bool o1, bool o2, bool pl, bool sh)
        {
            imagehandler img = new imagehandler();

            img.loadbitmap(path.ToString() + filename, 0);
            byte[][] f      = img.returnrawpixels();
            int      width  = (f[0]).Length;
            int      height = f.Length;

            int[][] newframe = RectangularArrays.RectangularIntArray(height, width);
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    newframe[i][j] = f[i][j] & 0xFF;
                }
            }

            if (msk)
            {
                string str = this.maskfile;
                if (File.Exists(str))
                {
                    img.loadbitmap(str, 0);
                }
                f = img.returnrawpixels();
                //replace black pixel by transparent pixel
                for (int j = 0; j < height; j++)
                {
                    for (int k = 0; k < width; k++)
                    {
                        int pixel = f[j][k] & 0xFF;
                        if (pixel == 0)
                        {
                            newframe[j][k] = -1;
                        }
                        //var test = newframe[1584][32];
                    }
                }
            }
            if (o1)
            {
                string str = path.ToString() + "U" + filename.Substring(1);
                img.loadbitmap(str, 0);
                f = img.returnrawpixels();

                for (int j = 0; j < height; j++)
                {
                    for (int k = 0; k < width; k++)
                    {
                        int pixel = f[j][k] & 0xFF;
                        if (pixel != 0)
                        {
                            newframe[j][k] = -2;
                        }
                    }
                }
            }
            if (o2)
            {
                string str = path.ToString() + "O" + filename.Substring(1);
                img.loadbitmap(str, 0);
                f = img.returnrawpixels();

                for (int j = 0; j < height; j++)
                {
                    for (int k = 0; k < width; k++)
                    {
                        int pixel = f[j][k] & 0xFF;
                        if (pixel != 0)
                        {
                            newframe[j][k] = -3;
                        }
                    }
                }
            }
            if (pl)
            {
                string str = path.ToString() + "P" + filename.Substring(1);
                img.loadbitmap(str, 0);
                f = img.returnrawpixels();

                for (int j = 0; j < height; j++)
                {
                    for (int k = 0; k < width; k++)
                    {
                        int pixel = f[j][k] & 0xFF;
                        if (pixel != 0)
                        {
                            newframe[j][k] = pixel;
                        }
                    }
                }

                this.plcolorused = true;
            }

            if (sh)
            {
                string str = path.ToString() + "H" + filename.Substring(1);
                img.loadbitmap(str, 0);
                f = img.returnrawpixels();
                Console.WriteLine("Entering shadow stuff");

                for (int j = 0; j < height; j++)
                {
                    for (int k = 0; k < width; k++)
                    {
                        int pixel = f[j][k] & 0xFF;
                        if (pixel != 0)
                        {
                            newframe[j][k] = -4;
                        }
                    }
                }
            }
            if (this.frames == null)
            {
                this.frames = new frame[num + 1];
            }
            this.frames[num]           = new frame();
            (this.frames[num]).width   = width;
            (this.frames[num]).height  = height;
            (this.frames[num]).picture = newframe;

            if (this.cvtused)
            {
                this.frames[num].convertcvt(this.mapping);
            }
        }