X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=plugins%2Fimageq2%2Fwal32.cpp;fp=plugins%2Fimageq2%2Fwal32.cpp;h=b202137affbd89cdbba5bf3ecb3b4100755350f8;hp=cadd845ea5308878e70a3c2baf77680274ee1f5c;hb=cd6613e5171544b68d4ae70546c90a15c99b22a5;hpb=cd7ff1a1798cfae5d14811a310f56d2f1908490b diff --git a/plugins/imageq2/wal32.cpp b/plugins/imageq2/wal32.cpp index cadd845e..b202137a 100644 --- a/plugins/imageq2/wal32.cpp +++ b/plugins/imageq2/wal32.cpp @@ -31,60 +31,59 @@ typedef unsigned char byte; const int M32_NAME_LENGTH = 128; const int M32_MIPMAP_COUNT = 16; -typedef struct m32_header_t { - int version; - char name[M32_NAME_LENGTH]; - char altname[M32_NAME_LENGTH]; // texture substitution - char animname[M32_NAME_LENGTH]; // next frame in animation chain - char damagename[M32_NAME_LENGTH]; // image that should be shown when damaged - unsigned width[M32_MIPMAP_COUNT], height[M32_MIPMAP_COUNT]; - unsigned offsets[M32_MIPMAP_COUNT]; - int flags; - int contents; - int value; - float scale_x, scale_y; - int mip_scale; - - // detail texturing info - char dt_name[M32_NAME_LENGTH]; // detailed texture name - float dt_scale_x, dt_scale_y; - float dt_u, dt_v; - float dt_alpha; - int dt_src_blend_mode, dt_dst_blend_mode; - - int unused[20]; // future expansion to maintain compatibility with h2 +typedef struct m32_header_t +{ + int version; + char name[M32_NAME_LENGTH]; + char altname[M32_NAME_LENGTH]; // texture substitution + char animname[M32_NAME_LENGTH]; // next frame in animation chain + char damagename[M32_NAME_LENGTH]; // image that should be shown when damaged + unsigned width[M32_MIPMAP_COUNT], height[M32_MIPMAP_COUNT]; + unsigned offsets[M32_MIPMAP_COUNT]; + int flags; + int contents; + int value; + float scale_x, scale_y; + int mip_scale; + + // detail texturing info + char dt_name[M32_NAME_LENGTH]; // detailed texture name + float dt_scale_x, dt_scale_y; + float dt_u, dt_v; + float dt_alpha; + int dt_src_blend_mode, dt_dst_blend_mode; + + int unused[20]; // future expansion to maintain compatibility with h2 } m32_header_t; -Image *LoadM32Buff(byte *buffer) -{ - PointerInputStream inputStream(buffer); - - inputStream.seek(4 // version - + M32_NAME_LENGTH // name - + M32_NAME_LENGTH // altname - + M32_NAME_LENGTH // animname - + M32_NAME_LENGTH); // damagename - int w = istream_read_uint32_le(inputStream); - inputStream.seek(4 * (M32_MIPMAP_COUNT - 1)); // remaining widths - int h = istream_read_uint32_le(inputStream); - inputStream.seek(4 * (M32_MIPMAP_COUNT - 1)); // remaining heights - int offset = istream_read_uint32_le(inputStream); - inputStream.seek(4 * (M32_MIPMAP_COUNT - 1)); // remaining offsets - int flags = istream_read_uint32_le(inputStream); - int contents = istream_read_uint32_le(inputStream); - int value = istream_read_uint32_le(inputStream); - - RGBAImageFlags *image = new RGBAImageFlags(w, h, flags, contents, value); - - const byte *source = buffer + offset; - std::copy(source, source + (w * h * 4), image->getRGBAPixels()); - - return image; +Image* LoadM32Buff( byte* buffer ){ + PointerInputStream inputStream( buffer ); + + inputStream.seek( 4 // version + + M32_NAME_LENGTH // name + + M32_NAME_LENGTH // altname + + M32_NAME_LENGTH // animname + + M32_NAME_LENGTH ); // damagename + int w = istream_read_uint32_le( inputStream ); + inputStream.seek( 4 * ( M32_MIPMAP_COUNT - 1 ) ); // remaining widths + int h = istream_read_uint32_le( inputStream ); + inputStream.seek( 4 * ( M32_MIPMAP_COUNT - 1 ) ); // remaining heights + int offset = istream_read_uint32_le( inputStream ); + inputStream.seek( 4 * ( M32_MIPMAP_COUNT - 1 ) ); // remaining offsets + int flags = istream_read_uint32_le( inputStream ); + int contents = istream_read_uint32_le( inputStream ); + int value = istream_read_uint32_le( inputStream ); + + RGBAImageFlags* image = new RGBAImageFlags( w, h, flags, contents, value ); + + const byte* source = buffer + offset; + std::copy( source, source + ( w * h * 4 ), image->getRGBAPixels() ); + + return image; } -Image *LoadM32(ArchiveFile &file) -{ - ScopedArchiveBuffer buffer(file); - return LoadM32Buff(buffer.buffer); +Image* LoadM32( ArchiveFile& file ){ + ScopedArchiveBuffer buffer( file ); + return LoadM32Buff( buffer.buffer ); }