Ejemplo n.º 1
0
        override protected Image Load()
        {
            ReadBytes(2);
            var bitmap = ReadBytes(8000);

            _mcolor     = ReadBytes(1000);
            _color      = ReadBytes(1000);
            _background = ReadByte();

            var image = NewImage(KOALA_WIDTH, KOALA_HEIGHT,
                                 ImageBaseType.Indexed, ImageType.Indexed,
                                 Filename);

            image.Colormap = GetColormap();

            var rgn = new PixelRgn(image.Layers[0], true, false);

            var buf  = new byte[KOALA_WIDTH * KOALA_HEIGHT];
            int bufp = 8;

            for (int row = 0; row < KOALA_HEIGHT; row++)
            {
                for (int col = 0; col < KOALA_WIDTH / 8; col++)
                {
                    byte p = bitmap[(row / 8) * KOALA_WIDTH + row % 8 + col * 8];

                    for (int i = 0; i < 4; i++)
                    {
                        byte index = GetColor(row / 8, col, p & 3);
                        buf[--bufp] = index;
                        buf[--bufp] = index;
                        p         >>= 2;
                    }
                    bufp += 16;
                }
            }

            rgn.SetRect(buf, 0, 0, KOALA_WIDTH, KOALA_HEIGHT);

            return(image);
        }
Ejemplo n.º 2
0
        protected override Image Load()
        {
            ReadBytes(2);
              var bitmap = ReadBytes(8000);
              _mcolor = ReadBytes(1000);
              _color = ReadBytes(1000);
              _background = ReadByte();

              var image = NewImage(KOALA_WIDTH, KOALA_HEIGHT,
               ImageBaseType.Indexed, ImageType.Indexed,
               Filename);
              image.Colormap = GetColormap();

              var rgn = new PixelRgn(image.Layers[0], true, false);

              var buf = new byte[KOALA_WIDTH * KOALA_HEIGHT];
              int bufp = 8;

              for (int row = 0; row < KOALA_HEIGHT; row++)
            {
              for (int col = 0; col < KOALA_WIDTH / 8; col++)
            {
              byte p = bitmap[(row / 8) * KOALA_WIDTH + row % 8 + col * 8];

              for (int i = 0; i < 4; i++)
            {
              byte index = GetColor(row / 8, col, p & 3);
              buf[--bufp] = index;
              buf[--bufp] = index;
              p >>= 2;
            }
              bufp += 16;
            }
            }

              rgn.SetRect(buf, 0, 0, KOALA_WIDTH, KOALA_HEIGHT);

              return image;
        }
Ejemplo n.º 3
0
        protected override Image Load()
        {
            int layerPosition = 0;
              int colorOffset = 0;

              var document = Document.FromStream(Reader.BaseStream);

              Console.WriteLine("Width  : " + document.Width);
              Console.WriteLine("height : " + document.Height);

              var image = new Image(document.Width, document.Height,
                ImageBaseType.Rgb); // Is it the best type ?
              image.Filename = Filename;

              PaintDotNet.LayerList layers = document.Layers;
              Console.WriteLine("#layers: " + layers.Count);

              foreach (PaintDotNet.Layer readLayer in layers)
            {
              try
            {
              Console.WriteLine(readLayer.Name);

              var layer = new Layer(image, readLayer.Name,
                    document.Width, document.Height,
                    ImageType.Rgba,
                    (readLayer.Opacity / 255) * 100, // 100 what means ?
                    LayerModeEffects.Normal);
              Console.WriteLine("11");
              image.AddLayer(layer, layerPosition++);

              Console.WriteLine("1");

              var rgn = new PixelRgn(layer, 0, 0,
                     document.Width, document.Height,
                     true, false);

              var buf = new byte[document.Width * document.Height * 4];
              var color_conv_ary = new byte[4];
              int lastPixelConverted = 0;
              colorOffset = 0;
              var surf = (readLayer as BitmapLayer).Surface;

              for (int row = 0; row < document.Height; row++)
            {
              var memory = surf.GetRow(row);
              var bitmapBytes = memory.ToByteArray();
              lastPixelConverted = 0;
              colorOffset = 0;
              for (int col = 0; col < document.Width * 4; col++)
            {
              color_conv_ary[colorOffset++] = bitmapBytes[col];
              //							Console.WriteLine("ColorOffset = " + colorOffset);

              if (colorOffset >= 4)
            {
              var tmpArray = FromBGRAToRGBA(color_conv_ary);

              for (int j = 0; j < colorOffset; j++)
                {
                  //									buf[row * document.Height + (lastPixelConverted++)] = tmpArray[j];
                  buf[(row * document.Width * 4) + (lastPixelConverted++)] = tmpArray[j];

                  /*										Console.WriteLine("Scritto il byte[" + ((row *
                                                        document.Width * 4) + (lastPixelConverted-1)) + "] : " +
                                                        tmpArray[j]);*/
                }
              colorOffset = 0;
            }

              //							buf[row * document.Height + col] =  bitmapBytes[col]; //0x7F;
            }
              //						Console.WriteLine(memory.Length);
            }
              //					Console.ReadLine();

              rgn.SetRect(buf, 0, 0,
              document.Width, document.Height);
              layer.Flush();
            }
              catch (Exception e)
            {
              Console.WriteLine("Exception : " + e.Message + " - " +
                e.StackTrace);
            }
            }
              // missing colormap, mcolor and background

              Console.WriteLine("2");

              /* var surface = (layers[0] as BitmapLayer).Surface;
             var memory1 = surface.GetRow(13);
             var bytes = memory1.ToByteArray();
             Console.WriteLine("length: " + bytes.Length);*/

              return image;
        }
Ejemplo n.º 4
0
        override protected Image Load()
        {
            int layerPosition = 0;
            int colorOffset   = 0;

            var document = Document.FromStream(Reader.BaseStream);

            Console.WriteLine("Width  : " + document.Width);
            Console.WriteLine("height : " + document.Height);

            var image = new Image(document.Width, document.Height,
                                  ImageBaseType.Rgb); // Is it the best type ?

            image.Filename = Filename;

            PaintDotNet.LayerList layers = document.Layers;
            Console.WriteLine("#layers: " + layers.Count);

            foreach (PaintDotNet.Layer readLayer in layers)
            {
                try
                {
                    Console.WriteLine(readLayer.Name);

                    var layer = new Layer(image, readLayer.Name,
                                          document.Width, document.Height,
                                          ImageType.Rgba,
                                          (readLayer.Opacity / 255) * 100, // 100 what means ?
                                          LayerModeEffects.Normal);
                    Console.WriteLine("11");
                    image.AddLayer(layer, layerPosition++);

                    Console.WriteLine("1");

                    var rgn = new PixelRgn(layer, 0, 0,
                                           document.Width, document.Height,
                                           true, false);

                    var buf                = new byte[document.Width * document.Height * 4];
                    var color_conv_ary     = new byte[4];
                    int lastPixelConverted = 0;
                    colorOffset = 0;
                    var surf = (readLayer as BitmapLayer).Surface;

                    for (int row = 0; row < document.Height; row++)
                    {
                        var memory      = surf.GetRow(row);
                        var bitmapBytes = memory.ToByteArray();
                        lastPixelConverted = 0;
                        colorOffset        = 0;
                        for (int col = 0; col < document.Width * 4; col++)
                        {
                            color_conv_ary[colorOffset++] = bitmapBytes[col];
                            //							Console.WriteLine("ColorOffset = " + colorOffset);

                            if (colorOffset >= 4)
                            {
                                var tmpArray = FromBGRAToRGBA(color_conv_ary);

                                for (int j = 0; j < colorOffset; j++)
                                {
                                    //									buf[row * document.Height + (lastPixelConverted++)] = tmpArray[j];
                                    buf[(row * document.Width * 4) + (lastPixelConverted++)] = tmpArray[j];

                                    /*										Console.WriteLine("Scritto il byte[" + ((row *
                                     *                                                                                document.Width * 4) + (lastPixelConverted-1)) + "] : " +
                                     *                                                                                tmpArray[j]);*/
                                }
                                colorOffset = 0;
                            }

                            //							buf[row * document.Height + col] =  bitmapBytes[col]; //0x7F;
                        }
                        //						Console.WriteLine(memory.Length);
                    }
                    //					Console.ReadLine();

                    rgn.SetRect(buf, 0, 0,
                                document.Width, document.Height);
                    layer.Flush();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception : " + e.Message + " - " +
                                      e.StackTrace);
                }
            }
            // missing colormap, mcolor and background

            Console.WriteLine("2");

            /* var surface = (layers[0] as BitmapLayer).Surface;
             * var memory1 = surface.GetRow(13);
             * var bytes = memory1.ToByteArray();
             * Console.WriteLine("length: " + bytes.Length);*/

            return(image);
        }