示例#1
0
        /// <summary>
        /// Build iff chunk with id and data
        /// </summary>
        /// <param name="id"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static async Task <byte[]> BuildIffChunk(string id, byte[] data)
        {
            var chunk = new MemoryStream();

            var chunkLength = data.Length;

            var appendZero = false;

            if ((chunkLength & 1) == 1)
            {
                chunkLength++;
                appendZero = true;
            }

            await chunk.WriteBytes(Encoding.ASCII.GetBytes(id));

            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes(chunkLength));

            await chunk.WriteBytes(data);

            if (appendZero)
            {
                await chunk.WriteBytes(new byte[1]);
            }

            return(chunk.ToArray());
        }
示例#2
0
        /// <summary>
        /// Build bitmap header chunk containing information defining the metrics of the image data
        /// </summary>
        /// <param name="image"></param>
        /// <param name="depth"></param>
        /// <param name="pack"></param>
        /// <returns></returns>
        public static async Task <byte[]> BuildBitMapHeaderChunk(Image image, int depth, bool pack)
        {
            var chunk = new MemoryStream();

            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((ushort)image.Width));  // width

            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((ushort)image.Height)); // height

            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((ushort)0));            // x

            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((ushort)0));            // y

            chunk.WriteByte((byte)depth);                                                       // planes
            chunk.WriteByte(0);                                                                 // mask
            chunk.WriteByte((byte)(pack ? 1 : 0));                                              // tcomp
            chunk.WriteByte(0);                                                                 // pad1
            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((ushort)0));            // transparent color

            chunk.WriteByte(60);                                                                // xAspect
            chunk.WriteByte(60);                                                                // yAspect
            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((ushort)image.Width));  // Lpage

            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((ushort)image.Height)); // Hpage

            return(await BuildIffChunk(ChunkIdentifiers.BitmapHeader, chunk.ToArray()));
        }
示例#3
0
        // create camg chunk
        public static async Task <byte[]> CamgChunk(Image image, int depth)
        {
            var chunk = new MemoryStream();

            await chunk.WriteBytes(LittleEndianConverter.ConvertToBytes((uint)depth)); // y

            return(await BuildIffChunk(ChunkIdentifiers.Camg, chunk.ToArray()));

            /*
             * return ,$cmagStream.ToArray()
             *
             # if mode is not None:
             # camg = iff_chunk("CAMG", struct.pack(">L", mode))
             # else:
             # camg = ""
             # //    uint viewmodes = input.ReadBEUInt32();
             #
             # //    bytesloaded = size;
             # //    if ((viewmodes & 0x0800) > 0)
             # //        flagHAM = true;
             # //    if ((viewmodes & 0x0080) > 0)
             # //        flagEHB = true;
             # //}
             */
        }
示例#4
0
 public static async Task WriteLittleEndianUInt32(this Stream stream, uint value)
 {
     await stream.WriteBytes(LittleEndianConverter.ConvertToBytes(value));
 }