Exemple #1
0
        public override ImageData Read(IBinaryStream stream, ImageMetaData info)
        {
            var meta = (DwqMetaData)info;

            BitmapSource bitmap = null;

            using (var sreg = new StreamRegion(stream.AsStream, 0x40, meta.PackedSize, true))
                using (var input = new BinaryStream(sreg, stream.Name))
                {
                    switch (meta.PackType)
                    {
                    case 5: // JPEG
                        return(Jpeg.Read(input, info));

                    case 8: // PNG
                        return(Png.Read(input, info));

                    case 0: // BMP
                    case 2: // BMP+MASK
                        bitmap = ReadFuckedUpBmpImage(input, info);
                        break;

                    case 7: // JPEG+MASK
                    {
                        var decoder = new JpegBitmapDecoder(input, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                        bitmap = decoder.Frames[0];
                        break;
                    }

                    case 1:
                    case 3: // PACKBMP+MASK
                    {
                        var reader = new DwqBmpReader(input, meta);
                        reader.Unpack();
                        bitmap = BitmapSource.Create((int)info.Width, (int)info.Height,
                                                     ImageData.DefaultDpiX, ImageData.DefaultDpiY,
                                                     reader.Format, reader.Palette, reader.Data, reader.Stride);
                        break;
                    }
                    }
                }
            if (null == bitmap)
            {
                throw new NotImplementedException();
            }
            if (meta.HasAlpha)
            {
                int mask_offset = 0x40 + meta.PackedSize;
                if (mask_offset != stream.Length)
                {
                    using (var mask = new StreamRegion(stream.AsStream, mask_offset, true))
                    {
                        var reader = new DwqBmpReader(mask, meta);
                        if (8 == reader.Format.BitsPerPixel) // mask should be represented as 8bpp bitmap
                        {
                            reader.Unpack();
                            var alpha   = reader.Data;
                            var palette = reader.Palette.Colors;
                            for (int i = 0; i < alpha.Length; ++i)
                            {
                                int color_idx = alpha[i];
                                if (color_idx < palette.Count)
                                {
                                    var color = palette[color_idx];
                                    int A     = (color.R + color.G + color.B) / 3;
                                    alpha[i] = (byte)A;
                                }
                            }
                            bitmap = ApplyAlphaChannel(bitmap, alpha);
                        }
                    }
                }
            }
            bitmap.Freeze();
            return(new ImageData(bitmap, meta));
        }
Exemple #2
0
 public override ImageData Read(IBinaryStream stream, ImageMetaData info)
 {
     using (var input = OpenEncrypted(stream))
         return(Jpeg.Read(input, info));
 }
Exemple #3
0
 public override ImageData Read(IBinaryStream file, ImageMetaData info)
 {
     using (var jpeg = OpenJpegStream(file))
         return(Jpeg.Read(jpeg, info));
 }