Ejemplo n.º 1
0
        public void WriteImageToIsoInnerSpecific(System.IO.Stream iso, System.Drawing.Image image, bool isDest4bpp = false)
        {
            using (Bitmap bmp = new Bitmap(image))
            {
                Set <Color> colors = GetColors(bmp);
                if (colors.Count > 256)
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(256, 8);
                    using (var newBmp = q.Quantize(bmp))
                    {
                        WriteImageToIsoInner(iso, newBmp);
                    }
                }
                else
                {
                    PatcherLib.Iso.KnownPosition newPalettePosition = palettePosition.AddOffset(CurrentPalette * palettePosition.Length, 0);
                    byte[]      originalPaletteBytes = newPalettePosition.ReadIso(iso);
                    byte[]      imageBytes           = GetImageBytes(bmp, isDest4bpp);
                    List <Byte> paletteBytes         = GetPaletteBytes(image.Palette.Entries, originalPaletteBytes);

                    newPalettePosition.PatchIso(iso, paletteBytes);
                    //position.PatchIso(iso, imageBytes);
                    PatchIsoBytes(iso, imageBytes, isDest4bpp);
                }
            }
        }
Ejemplo n.º 2
0
        protected override void WriteImageToIsoInner(System.IO.Stream iso, System.Drawing.Image image)
        {
            if (ImportExport8bpp)
            {
                WriteImageToIsoInner8bpp(iso, image);
                return;
            }

            using (Bitmap bmp = new Bitmap(image))
            {
                Set <Color>   colors   = GetColors(bmp);
                IList <Color> myColors = new List <Color>(colors);
                if (myColors.Count > 16)
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(16, 8);
                    using (var newBmp = q.Quantize(bmp))
                    {
                        WriteImageToIsoInner(iso, newBmp);
                    }
                }
                else
                {
                    PatcherLib.Iso.KnownPosition newPalettePosition = palettePosition.AddOffset(CurrentPalette * palettePosition.Length, 0);
                    IList <Byte> originalPaletteBytes = newPalettePosition.ReadIso(iso);
                    byte[]       imageBytes           = GetImageBytes(bmp);
                    List <Byte>  paletteBytes         = GetPaletteBytes(image.Palette.Entries, originalPaletteBytes);

                    newPalettePosition.PatchIso(iso, paletteBytes);
                    PatchIsoBytes(iso, imageBytes);
                }
            }
        }
Ejemplo n.º 3
0
        public void WriteImageToIsoInnerSpecific(System.IO.Stream iso, System.Drawing.Image image, bool isDest4bpp = false)
        {
            using (System.Drawing.Bitmap sourceBitmap = new System.Drawing.Bitmap(image))
            {
                Set <System.Drawing.Color> colors = GetColors(sourceBitmap);
                if (colors.Count > NumColors)
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(NumColors, 8);
                    using (var newBmp = q.Quantize(sourceBitmap))
                    {
                        WriteImageToIsoInner(iso, newBmp);
                    }
                }
                else
                {
                    byte[]       imageBytes = GetImageBytes(sourceBitmap, isDest4bpp);
                    IList <byte> bytes      = PixelsToBytes(imageBytes);

                    byte[] originalPaletteBytes = PalettePosition.ReadIso(iso);
                    PalettePosition.PatchIso(iso, GetPaletteBytes(image.Palette.Entries, originalPaletteBytes));

                    int currentIndex = 0;
                    foreach (var kp in PixelPositions)
                    {
                        var bb = bytes.Sub(currentIndex, currentIndex + kp.Length - 1);
                        kp.PatchIso(iso, bb);
                        currentIndex += kp.Length;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        protected override void WriteImageToIsoInner(System.IO.Stream iso, System.Drawing.Image image)
        {
            using (System.Drawing.Bitmap sourceBitmap = new System.Drawing.Bitmap(image))
            {
                Set <System.Drawing.Color> colors = GetColors(sourceBitmap);
                if (colors.Count > 256)
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(255, 8);
                    using (var newBmp = q.Quantize(sourceBitmap))
                    {
                        WriteImageToIsoInner(iso, newBmp);
                    }
                }
                else
                {
                    byte[] totalBytes = GetImageBytes(sourceBitmap);
                    List <List <byte> > quadrantBytes = new List <List <byte> >();
                    for (int i = 0; i < 4; i++)
                    {
                        quadrantBytes.Add(new List <byte>());
                    }

                    for (int rowIndex = 0; rowIndex < 368; rowIndex++)
                    {
                        int byteIndex = rowIndex * 496;

                        if (rowIndex < 240)
                        {
                            quadrantBytes[0].AddRange(totalBytes.Sub(byteIndex, byteIndex + 239));
                            quadrantBytes[1].AddRange(totalBytes.Sub(byteIndex + 240, byteIndex + 495));
                        }
                        else
                        {
                            quadrantBytes[2].AddRange(totalBytes.Sub(byteIndex, byteIndex + 239));
                            quadrantBytes[3].AddRange(totalBytes.Sub(byteIndex + 240, byteIndex + 495));
                        }
                    }

                    //var palBytes = GetPaletteBytes( colors, Palette.ColorDepth._16bit );
                    byte[]      originalPaletteBytes = palettePositions[0].ReadIso(iso);
                    List <byte> palBytes             = GetPaletteBytes(image.Palette.Entries, originalPaletteBytes);
                    palettePositions.ForEach(pp => pp.PatchIso(iso, palBytes));

                    for (int i = 0; i < 4; i++)
                    {
                        List <byte> bytes = quadrantBytes[i];

                        int currentIndex = 0;
                        foreach (PatcherLib.Iso.PsxIso.KnownPosition kp in isoPositions[i])
                        {
                            kp.PatchIso(iso, bytes.Sub(currentIndex, currentIndex + kp.Length - 1));
                            currentIndex += kp.Length;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected string ImageToData(System.Drawing.Image image)
        {
            using (var memStream = new System.IO.MemoryStream())
            {
                var quantizer = new ImageQuantization.OctreeQuantizer(255, 8);
                using (var quantized = quantizer.Quantize(image))
                {
                    quantized.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);
                }

                //image.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);

                return("base64:" + System.Convert.ToBase64String(memStream.ToArray()));
            }
        }
 protected override void WriteImageToIsoInner(System.IO.Stream iso, System.Drawing.Image image)
 {
     using (Bitmap bmp = new Bitmap(image))
     {
         Set <Color> colors = GetColors(bmp);
         if (colors.Count > 16)
         {
             ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(16, 8);
             using (var newBmp = q.Quantize(bmp))
             {
                 WriteImageToIsoInner(iso, newBmp);
             }
         }
         else
         {
             var paletteBytes = GetPaletteBytes(colors);
             var imageBytes   = GetImageBytes(bmp, colors);
             position.PatchIso(iso, imageBytes);
             palettePosition.PatchIso(iso, paletteBytes);
         }
     }
 }
Ejemplo n.º 7
0
        protected override void WriteImageToIsoInner( System.IO.Stream iso, System.Drawing.Image image )
        {
            using ( System.Drawing.Bitmap sourceBitmap = new System.Drawing.Bitmap( image ) )
            {
                Set<System.Drawing.Color> colors = GetColors( sourceBitmap );
                if ( colors.Count > 256 )
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer( 255, 8 );
                    using ( var newBmp = q.Quantize( sourceBitmap ) )
                    {
                        WriteImageToIsoInner( iso, newBmp );
                    }
                }
                else
                {
                    byte[] totalBytes = GetImageBytes(sourceBitmap);
                    List<List<byte>> quadrantBytes = new List<List<byte>>();
                    for (int i = 0; i < 4; i++)
                        quadrantBytes.Add(new List<byte>());

                    for (int rowIndex = 0; rowIndex < 368; rowIndex++)
                    {
                        int byteIndex = rowIndex * 496;

                        if (rowIndex < 240)
                        {
                            quadrantBytes[0].AddRange(totalBytes.Sub(byteIndex, byteIndex + 239));
                            quadrantBytes[1].AddRange(totalBytes.Sub(byteIndex + 240, byteIndex + 495));
                        }
                        else
                        {
                            quadrantBytes[2].AddRange(totalBytes.Sub(byteIndex, byteIndex + 239));
                            quadrantBytes[3].AddRange(totalBytes.Sub(byteIndex + 240, byteIndex + 495));
                        }
                    }

                    //var palBytes = GetPaletteBytes( colors, Palette.ColorDepth._16bit );
                    byte[] originalPaletteBytes = palettePositions[0].ReadIso(iso);
                    List<byte> palBytes = GetPaletteBytes(image.Palette.Entries, originalPaletteBytes);
                    palettePositions.ForEach(pp => pp.PatchIso(iso, palBytes));

                    for ( int i = 0; i < 4; i++ )
                    {
                        List<byte> bytes = quadrantBytes[i];

                        int currentIndex = 0;
                        foreach ( PatcherLib.Iso.PsxIso.KnownPosition kp in isoPositions[i] )
                        {
                            kp.PatchIso( iso, bytes.Sub( currentIndex, currentIndex + kp.Length - 1 ) );
                            currentIndex += kp.Length;
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected override void WriteImageToIsoInner(System.IO.Stream iso, System.Drawing.Image image)
        {
            if (ImportExport8bpp)
            {
                WriteImageToIsoInner8bpp(iso, image);
                return;
            }

            using (Bitmap bmp = new Bitmap(image))
            {
                Set<Color> colors = GetColors(bmp);
                IList<Color> myColors = new List<Color>(colors);
                if (myColors.Count > 16)
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer(16, 8);
                    using (var newBmp = q.Quantize(bmp))
                    {
                        WriteImageToIsoInner(iso, newBmp);
                    }
                }
                else
                {
                    PatcherLib.Iso.KnownPosition newPalettePosition = PalettePosition.AddOffset(CurrentPalette * PalettePosition.Length, 0);
                    IList<Byte> originalPaletteBytes = newPalettePosition.ReadIso(iso);
                    byte[] imageBytes = GetImageBytes(bmp);
                    List<Byte> paletteBytes = GetPaletteBytes(image.Palette.Entries, originalPaletteBytes);

                    newPalettePosition.PatchIso(iso, paletteBytes);

                    int currentIndex = 0;
                    foreach (PatcherLib.Iso.KnownPosition kp in PixelPositions)
                    {
                        IList<byte> bb = imageBytes.Sub(currentIndex, currentIndex + kp.Length - 1);
                        kp.PatchIso(iso, bb);
                        currentIndex += kp.Length;
                    }

                    //PatchIsoBytes(iso, imageBytes);
                }
            }
        }
 protected override void WriteImageToIsoInner( System.IO.Stream iso, System.Drawing.Image image )
 {
     using ( Bitmap bmp = new Bitmap( image ) )
     {
         Set<Color> colors = GetColors( bmp );
         if ( colors.Count > 16 )
         {
             ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer( 16, 8 );
             using ( var newBmp = q.Quantize( bmp ) )
             {
                 WriteImageToIsoInner( iso, newBmp );
             }
         }
         else
         {
             var paletteBytes = GetPaletteBytes( colors );
             var imageBytes = GetImageBytes( bmp, colors );
             position.PatchIso( iso, imageBytes );
             palettePosition.PatchIso( iso, paletteBytes );
         }
     }
 }
Ejemplo n.º 10
0
        public void WriteImageToIsoInnerSpecific(System.IO.Stream iso, System.Drawing.Image image, bool isDest4bpp = false)
        {
            using ( System.Drawing.Bitmap sourceBitmap = new System.Drawing.Bitmap( image ) )
            {
                Set<System.Drawing.Color> colors = GetColors( sourceBitmap );
                if ( colors.Count > NumColors )
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer( NumColors, 8 );
                    using ( var newBmp = q.Quantize( sourceBitmap ) )
                    {
                        WriteImageToIsoInner( iso, newBmp );
                    }
                }
                else
                {
                    byte[] imageBytes = GetImageBytes(sourceBitmap, isDest4bpp);
                    IList<byte> bytes = PixelsToBytes(imageBytes);

                    byte[] originalPaletteBytes = PalettePosition.ReadIso(iso);
                    PalettePosition.PatchIso(iso, GetPaletteBytes(image.Palette.Entries, originalPaletteBytes));

                    int currentIndex = 0;
                    foreach ( var kp in PixelPositions )
                    {
                        var bb = bytes.Sub( currentIndex, currentIndex + kp.Length - 1 );
                        kp.PatchIso( iso, bb );
                        currentIndex += kp.Length;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        protected string ImageToData(System.Drawing.Image image)
        {
            using (var memStream = new System.IO.MemoryStream())
            {
                var quantizer = new ImageQuantization.OctreeQuantizer(255, 8);
                using (var quantized = quantizer.Quantize(image))
                {
                    quantized.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);
                }

                //image.Save(memStream, System.Drawing.Imaging.ImageFormat.Gif);

                return "base64:" + System.Convert.ToBase64String(memStream.ToArray());
            }
        }
Ejemplo n.º 12
0
        public void WriteImageToIsoInnerSpecific(System.IO.Stream iso, System.Drawing.Image image, bool isDest4bpp = false)
        {
            using ( Bitmap bmp = new Bitmap( image ) )
            {
                Set<Color> colors = GetColors( bmp );
                if ( colors.Count > 256 )
                {
                    ImageQuantization.OctreeQuantizer q = new ImageQuantization.OctreeQuantizer( 256,  8 );
                    using ( var newBmp = q.Quantize( bmp ) )
                    {
                        WriteImageToIsoInner( iso, newBmp );
                    }
                }
                else
                {
                    PatcherLib.Iso.KnownPosition newPalettePosition = palettePosition.AddOffset(CurrentPalette * palettePosition.Length, 0);
                    byte[] originalPaletteBytes = newPalettePosition.ReadIso(iso);
                    byte[] imageBytes = GetImageBytes(bmp, isDest4bpp);
                    List<Byte> paletteBytes = GetPaletteBytes(image.Palette.Entries, originalPaletteBytes);

                    newPalettePosition.PatchIso(iso, paletteBytes);
                    //position.PatchIso(iso, imageBytes);
                    PatchIsoBytes(iso, imageBytes, isDest4bpp);
                }
            }
        }