bool vmsSwfFileHeader::isSwfCompressed(LPBYTE pbData, UINT uSize) { if (!isValidHeader (pbData, uSize)) return false; m_bCompressed = pbData [0] == 'C'; m_uVersion = pbData [3]; m_uFileLength = * (UINT32*)(pbData + 4); return m_bCompressed; }
bool ImageReader::readDDS( wxSize& po_size, BGR*& po_colors, uint8*& po_alphas ) const { Assert( isValidHeader( m_data.GetPointer( ), m_data.GetSize( ) ) ); // Get header if ( m_data.GetSize( ) < sizeof( DDSHeader ) ) { return false; } auto header = reinterpret_cast<const DDSHeader*>( m_data.GetPointer( ) ); // Ensure some of the values are correct if ( header->magic != FCC_DDS || header->size != sizeof( DDSHeader ) -4 || header->pixelFormat.size != sizeof( DDSPixelFormat ) ) { return false; } po_colors = nullptr; po_alphas = nullptr; // Determine the pixel format if ( header->pixelFormat.flags & 0x40 ) { // 0x40 = DDPF_RGB, uncompressed data if ( !this->processUncompressedDDS( header, reinterpret_cast<RGB*&>( po_colors ), po_alphas ) ) { return false; } } else if ( header->pixelFormat.flags & 0x4 ) { // 0x4 = DDPF_FOURCC, compressed const BGRA* data = reinterpret_cast<const BGRA*>( &m_data[sizeof( *header )] ); switch ( header->pixelFormat.fourCC ) { case FCC_DXT1: this->processDXT1( data, header->width, header->height, po_colors, po_alphas ); break; case FCC_DXT2: case FCC_DXT3: this->processDXT3( data, header->width, header->height, po_colors, po_alphas ); break; case FCC_DXT4: case FCC_DXT5: this->processDXT5( data, header->width, header->height, po_colors, po_alphas ); break; case FCC_R32F: break; } } else if ( header->pixelFormat.flags & 0x20000 ) { // 0x20000 = DDPF_LUMINANCE, single-byte color if ( !this->processLuminanceDDS( header, reinterpret_cast<RGB*&>( po_colors ) ) ) { return false; } } if ( !!po_colors ) { po_size.Set( header->width, header->height ); } return !!po_colors; }
Ur5State Ur5MessageDecoder::setState(QByteArray data) { Ur5State state(false); for(int i=0;i<data.size();i++) { if(isValidHeader(getHeader(data,i))) { pushState(slicePacket(data,i,headerLength(getHeader(data,i))),state); } } setTransformationMatrix(state); state.updated = true; return state; }
bool ImageReader::readATEX( wxSize& po_size, BGR*& po_colors, uint8*& po_alphas ) const { Assert( isValidHeader( m_data.GetPointer( ), m_data.GetSize( ) ) ); auto atex = reinterpret_cast<const ANetAtexHeader*>( m_data.GetPointer( ) ); // Determine mipmap0 size and bail if the file is too small if ( m_data.GetSize( ) >= sizeof( ANetAtexHeader ) +sizeof( uint32 ) ) { auto mipMap0Size = *reinterpret_cast<const uint32*>( &m_data[sizeof( ANetAtexHeader )] ); if ( mipMap0Size + sizeof( ANetAtexHeader ) > m_data.GetSize( ) ) { po_size.Set( 0, 0 ); return false; } } else { po_size.Set( 0, 0 ); return false; } // Init some fields auto data = reinterpret_cast<const uint8_t*>( m_data.GetPointer( ) ); po_colors = nullptr; po_alphas = nullptr; uint16 width = atex->width; uint16 height = atex->height; // Hack for read 126x64 ATEX if ( width == 126 && height == 64 ) { width = 128; } // Allocate output auto output = allocate<BGRA>( width * height ); uint32_t outputBufferSize; // Uncompress switch ( atex->formatInteger ) { case FCC_DXT1: if ( gw2dt::compression::inflateTextureFileBuffer( m_data.GetSize( ), data, outputBufferSize, reinterpret_cast<uint8_t*>( output ) ) ) { this->processDXT1( output, width, height, po_colors, po_alphas ); } break; case FCC_DXT2: case FCC_DXT3: case FCC_DXTN: if ( gw2dt::compression::inflateTextureFileBuffer( m_data.GetSize( ), data, outputBufferSize, reinterpret_cast< uint8_t* >( output ) ) ) { this->processDXT3( output, width, height, po_colors, po_alphas ); } break; case FCC_DXT4: case FCC_DXT5: if ( gw2dt::compression::inflateTextureFileBuffer( m_data.GetSize( ), data, outputBufferSize, reinterpret_cast< uint8_t* >( output ) ) ) { this->processDXT5( output, width, height, po_colors, po_alphas ); } break; case FCC_DXTA: if ( gw2dt::compression::inflateTextureFileBuffer( m_data.GetSize( ), data, outputBufferSize, reinterpret_cast< uint8_t* >( output ) ) ) { this->processDXTA( reinterpret_cast< uint64* >( output ), width, height, po_colors ); } break; case FCC_DXTL: if ( gw2dt::compression::inflateTextureFileBuffer( m_data.GetSize( ), data, outputBufferSize, reinterpret_cast<uint8_t*>( output ) ) ) { this->processDXT5( output, width, height, po_colors, po_alphas ); for ( uint i = 0; i < ( static_cast<uint>( width ) * static_cast<uint>( height ) ); i++ ) { po_colors[i].r = ( po_colors[i].r * po_alphas[i] ) / 0xff; po_colors[i].g = ( po_colors[i].g * po_alphas[i] ) / 0xff; po_colors[i].b = ( po_colors[i].b * po_alphas[i] ) / 0xff; } } break; case FCC_3DCX: if ( gw2dt::compression::inflateTextureFileBuffer( m_data.GetSize( ), data, outputBufferSize, reinterpret_cast< uint8_t* >( output ) ) ) { this->process3DCX( reinterpret_cast<RGBA*>( output ), width, height, po_colors, po_alphas ); } break; default: freePointer( output ); return false; } freePointer( output ); if ( po_colors ) { po_size.Set( width, height ); return true; } return false; }