Exemplo n.º 1
0
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var reader = new PgdReader(stream, (PgdGeMetaData)info))
     {
         var pixels = reader.UnpackGE();
         return(ImageData.Create(info, reader.Format, null, pixels));
     }
 }
Exemplo n.º 2
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var           meta     = (PgdIncMetaData)info;
            string        dir_name = VFS.GetDirectoryName(meta.FileName);
            string        name     = VFS.CombinePath(dir_name, meta.BaseName);
            PgdGeMetaData base_info;

            byte[]      image, overlay;
            PixelFormat format;

            using (var base_file = VFS.OpenBinaryStream(name))
            {
                base_info = PalFormat.Value.ReadMetaData(base_file) as PgdGeMetaData;
                if (null == base_info)
                {
                    throw new InvalidFormatException("Invalid baseline image format");
                }
                if (meta.OffsetX + meta.Width > base_info.Width ||
                    meta.OffsetY + meta.Height > base_info.Height)
                {
                    throw new InvalidFormatException("Incompatible baseline image dimensions");
                }
                base_info.FileName = name;
                using (var reader = new PgdReader(base_file, base_info))
                {
                    image  = reader.UnpackGE();
                    format = reader.Format;
                }
            }
            using (var reader = new PgdReader(stream, meta))
                overlay = reader.UnpackOverlay();

            int  overlay_bpp = meta.BPP / 8;
            int  base_bpp    = format.BitsPerPixel / 8;
            int  dst         = (meta.OffsetY * (int)base_info.Width + meta.OffsetX) * base_bpp;
            int  gap         = (int)(base_info.Width - meta.Width) * base_bpp;
            int  src         = 0;
            bool apply_alpha = overlay_bpp == 4 && base_bpp == 4;

            for (uint y = 0; y < meta.Height; ++y)
            {
                for (uint x = 0; x < meta.Width; ++x)
                {
                    image[dst]     ^= overlay[src];
                    image[dst + 1] ^= overlay[src + 1];
                    image[dst + 2] ^= overlay[src + 2];
                    if (apply_alpha)
                    {
                        image[dst + 3] ^= overlay[src + 3];
                    }
                    dst += base_bpp;
                    src += overlay_bpp;
                }
                dst += gap;
            }
            base_info.FileName = meta.FileName;
            return(ImageData.Create(base_info, format, null, image));
        }
Exemplo n.º 3
0
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var reader = new PgdReader(stream, 0x1C))
     {
         var data = reader.Unpack00();
         using (var tga = new BinMemoryStream(data, stream.Name))
         {
             var tga_info = Tga.ReadMetaData(tga);
             if (null == tga_info)
             {
                 throw new InvalidFormatException();
             }
             tga.Position = 0;
             return(Tga.Read(tga, tga_info));
         }
     }
 }
Exemplo n.º 4
0
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var reader = new PgdReader(stream, 0x20))
     {
         var planes     = reader.Unpack11();
         var pixels     = new byte[planes.Length];
         int plane_size = (int)info.Width * (int)info.Height;
         int b_src      = 0;
         int g_src      = b_src + plane_size;
         int r_src      = g_src + plane_size;
         int alpha_src  = r_src + plane_size;
         int dst        = 0;
         while (dst < pixels.Length)
         {
             pixels[dst++] = planes[b_src++];
             pixels[dst++] = planes[g_src++];
             pixels[dst++] = planes[r_src++];
             pixels[dst++] = planes[alpha_src++];
         }
         return(ImageData.Create(info, PixelFormats.Bgra32, null, pixels));
     }
 }