Example #1
0
        static ThumbnailHeader LoadHeader(BinaryReader reader)
        {
            var header = new ThumbnailHeader();
            header.Type = ScummHelper.SwapBytes(reader.ReadUInt32());
            // We also accept the bad 'BMHT' header here, for the sake of compatibility
            // with some older savegames which were written incorrectly due to a bug in
            // ScummVM which wrote the thumb header type incorrectly on LE systems.
            if (header.Type != ScummHelper.MakeTag('T', 'H', 'M', 'B') && header.Type != ScummHelper.MakeTag('B', 'M', 'H', 'T'))
            {
                //if (outputWarnings)
                //    warning("couldn't find thumbnail header type");
                return null;
            }

            header.Size = ScummHelper.SwapBytes(reader.ReadUInt32());
            header.Version = reader.ReadByte();

            if (header.Version > TumbnailVersion)
            {
                //if (outputWarnings)
                //    warning("trying to load a newer thumbnail version: %d instead of %d", header.version, THMB_VERSION);
                return null;
            }

            header.Width = ScummHelper.SwapBytes(reader.ReadUInt16());
            header.Height = ScummHelper.SwapBytes(reader.ReadUInt16());
            header.Bpp = reader.ReadByte();

            return header;
        }
Example #2
0
        void SaveThumbnail(BinaryWriter output, Surface thumb)
        {
            var bpp = Surface.GetBytesPerPixel(thumb.PixelFormat);
            if (bpp != 2 && bpp != 4)
            {
                // TODO: warning("trying to save thumbnail with bpp %u", bpp);
                return;
            }

            ThumbnailHeader header = new ThumbnailHeader();
            header.Type = ScummHelper.MakeTag('T', 'H', 'M', 'B');
            header.Size = (uint)(ThumbnailHeaderSize + thumb.Width * thumb.Height * bpp);
            header.Version = THMB_VERSION;
            header.Width = (ushort)thumb.Width;
            header.Height = (ushort)thumb.Height;

            output.WriteUInt32BigEndian(header.Type);
            output.WriteUInt32BigEndian(header.Size);
            output.WriteByte(header.Version);
            output.WriteUInt16BigEndian(header.Width);
            output.WriteUInt16BigEndian(header.Height);

            // Serialize the PixelFormat
            output.WriteByte(bpp);
            output.WriteByte(3);
            output.WriteByte(2);
            output.WriteByte(3);
            output.WriteByte(8);
            output.WriteByte(11);
            output.WriteByte(5);
            output.WriteByte(0);
            output.WriteByte(0);

            // Serialize the pixel data
            for (uint y = 0; y < thumb.Height; ++y)
            {
                switch (bpp)
                {
                    case 2:
                        {
                            var pixels = new UShortAccess(thumb.Pixels, (int)(y * thumb.Width * 2));
                            for (uint x = 0; x < thumb.Width; ++x)
                            {
                                output.WriteUInt16BigEndian(pixels[0]);
                                pixels.Offset += 2;
                            }
                        }
                        break;

                    case 4:
                        {
                            var pixels = new UIntAccess(thumb.Pixels, (int)(y * thumb.Width * 4));
                            for (var x = 0; x < thumb.Width; ++x)
                            {
                                output.WriteUInt32BigEndian(pixels[0]);
                                pixels.Offset += 4;
                            }
                        }
                        break;

                    default:
                        throw new NotSupportedException();
                }
            }
        }