Example #1
0
void MD2Model::Part::loadTextureFilenames(BinaryInput& b, int num, int offset) {

    _textureFilenames.resize(num);
    b.setPosition(offset);
    for (int t = 0; t < num; ++t) {
        _textureFilenames[t] = b.readString();
    }
}
Example #2
0
inline static void readBGR(uint8* byte, BinaryInput& bi) {
    int b = bi.readUInt8();
    int g = bi.readUInt8();
    int r = bi.readUInt8();

    byte[0] = r;
    byte[1] = g;
    byte[2] = b;
}
Example #3
0
void ServerDescription::deserialize(BinaryInput& b) {
    serverName      = b.readString();
    applicationAddress.deserialize(b);
    applicationName = b.readString();
    maxClients      = b.readInt32();
    debugAssert(maxClients >= 0);
    currentClients  = b.readInt32();
    data            = b.readString();
    lastUpdateTime  = System::time();
}
Example #4
0
void ParseOBJ::parse(BinaryInput& bi, const ParseOBJ::Options& options, const String& basePath) {
    m_filename = bi.getFilename();

    String bp = basePath;
    if (bp == "<AUTO>") {
        bp = FilePath::parent(FileSystem::resolve(m_filename));
    }    

    parse((const char*)bi.getCArray() + bi.getPosition(),
          size_t(bi.getLength() - bi.getPosition()), bp, options);
}
void ModulesManager::loadInput()
{
	// BinaryInput
	BinaryInput *binaryInput = new BinaryInput();
    m_inputModules[binaryInput->name()] = binaryInput;

	// BinaryInput
	PcapInput *pcapInput = new PcapInput();
    m_inputModules[pcapInput->name()] = pcapInput;

	// IndexFileInput
	IndexFileInput *indexFileInput = new IndexFileInput();
	m_inputModules[indexFileInput->name()] = indexFileInput;
}
Example #6
0
UniversalBSDF::Ref UniversalBSDF::speedCreate(BinaryInput& b) {
    UniversalBSDF::Ref s(new UniversalBSDF());
    
    SpeedLoad::readHeader(b, "UniversalBSDF");

    s->m_lambertian.speedDeserialize(b);
    s->m_glossy.speedDeserialize(b);
    s->m_transmissive.speedDeserialize(b);
    s->m_eta_t = b.readFloat32();
    s->m_extinction_t.deserialize(b);
    s->m_eta_r = b.readFloat32();
    s->m_extinction_r.deserialize(b);

    return s;
}
Example #7
0
void readHeader(BinaryInput& b, const String& expectedString) {

    const String header = b.readString(SpeedLoad::HEADER_LENGTH);

    (void)header;
    alwaysAssertM(header == expectedString, 
                  format("SpeedLoad expected to read chunk \"%s\" but found chunk \"%s\"",
                         expectedString.c_str(), header.c_str()));
}
Example #8
0
    void deserialize(BinaryInput& b) {
        magic               = b.readInt32();
        version             = b.readInt32(); 
        skinWidth           = b.readInt32(); 
        skinHeight          = b.readInt32(); 
        frameSize           = b.readInt32(); 
        numSkins            = b.readInt32(); 
        numVertices         = b.readInt32(); 
        numTexCoords        = b.readInt32(); 
        numTriangles        = b.readInt32(); 
        numGlCommands       = b.readInt32(); 
        numFrames           = b.readInt32(); 
        offsetSkins         = b.readInt32(); 
        offsetTexCoords     = b.readInt32(); 
        offsetTriangles     = b.readInt32(); 
        offsetFrames        = b.readInt32(); 
        offsetGlCommands    = b.readInt32(); 
        offsetEnd           = b.readInt32();

    }
Example #9
0
void Vector2::deserialize(BinaryInput& b) {
    x = b.readFloat32();
    y = b.readFloat32();
}
Example #10
0
void Color1::deserialize(BinaryInput& bi) {
    value = bi.readFloat32();
}
Example #11
0
	std::enable_if_t<std::is_arithmetic<T>::value, void>
	load(BinaryInput & a, T & t)
	{
		a.load_Data(std::addressof(t), sizeof(t));
	}
Example #12
0
void GImage::decodeTGA(
    BinaryInput&        input) {

    // This is a simple TGA loader that can handle uncompressed
    // truecolor TGA files (TGA type 2).
    // Verify this is a TGA file by looking for the TRUEVISION tag.
    int pos = input.getPosition();
    input.setPosition(input.size() - 18);
    std::string tag = input.readString(16);
    if (tag != "TRUEVISION-XFILE") {
        throw Error("Not a TGA file", input.getFilename());
    }

    input.setPosition(pos);

    int IDLength     = input.readUInt8();
    int colorMapType = input.readUInt8();
    int imageType    = input.readUInt8();

    (void)colorMapType;

    // 2 is the type supported by this routine.
    if (imageType != 2 && imageType != 10) {
        throw Error("TGA images must be type 2 (Uncompressed truecolor) or 10 (Run-length truecolor)", input.getFilename());
    }

    // Color map specification
    input.skip(5);

    // Image specification

    // Skip x and y offsets
    input.skip(4);

    m_width  = input.readInt16();
    m_height = input.readInt16();

    int colorDepth = input.readUInt8();

    if ((colorDepth != 24) && (colorDepth != 32)) {
        throw Error("TGA files must be 24 or 32 bit.", input.getFilename());
    }

    if (colorDepth == 32) {
        m_channels = 4;
    } else {
        m_channels = 3;
    }

    // Image descriptor contains overlay data as well
    // as data indicating where the origin is
    int imageDescriptor = input.readUInt8();
    (void)imageDescriptor;

    // Image ID
    input.skip(IDLength);

    m_byte = (uint8*)m_memMan->alloc(m_width * m_height * m_channels);
    debugAssert(m_byte);

    // Pixel data
    int x;
    int y;

    if (imageType == 2) {
        // Uncompressed
        if (m_channels == 3) {
            for (y = m_height - 1; y >= 0; --y) {
              for (x = 0; x < m_width; ++x) {
                int i = (x + y * m_width) * 3;
                readBGR(m_byte + i, input);
              }
            }
        } else {
            for (y = m_height - 1; y >= 0; --y) {
              for (x = 0; x < m_width; ++x) {
                 int i = (x + y * m_width) * 4;
                 readBGRA(m_byte + i, input);
              }
            }
        }
    } else if (imageType == 10) {

        // Run-length encoded
        for (y = m_height - 1; y >= 0; --y) {
            for (int x = 0; x < m_width; /* intentionally no x increment */) {
                // The specification guarantees that no packet will wrap past the end of a row
                const uint8 repetitionCount = input.readUInt8();
                const uint8 numValues = (repetitionCount & (~128)) + 1;
                int byteOffset = (x + y * m_width) * 3;

                if (repetitionCount & 128) {
                    // When the high bit is 1, this is a run-length packet
                    if (m_channels == 3) {
                        Color3uint8 value;
                        readBGR((uint8*)(&value), input);
                        for (int i = 0; i < numValues; ++i, ++x) {
                            for (int b = 0; b < 3; ++b, ++byteOffset) {
                                m_byte[byteOffset] = value[b];
                            }
                        }
                    } else {
                        Color4uint8 value;
                        readBGRA((uint8*)(&value), input);
                        for (int i = 0; i < numValues; ++i, ++x) {
                            for (int b = 0; b < 3; ++b, ++byteOffset) {
                                m_byte[byteOffset] = value[b];
                            }
                        }
                    }

                } else {
                    // When the high bit is 0, this is a raw packet
                    for (int i = 0; i < numValues; ++i, ++x, byteOffset += m_channels) {
                        readBGR(m_byte + byteOffset, input);
                    }
                }
            }
        }
    } else {
        alwaysAssertM(false, "Unsupported type");
    }
}
Example #13
0
inline static void readBGRA(uint8* byte, BinaryInput& bi) {
    readBGR(byte, bi);
    byte[3] = bi.readUInt8();
}
Example #14
0
 void deserialize(BinaryInput& b) {
     scale.deserialize(b);
     translate.deserialize(b);
     name = b.readString(16);
 }
Example #15
0
void GImage::decodeJPEG(
    BinaryInput&                input) {

	struct jpeg_decompress_struct   cinfo;
	struct jpeg_error_mgr           jerr;
    int                             loc = 0;

    channels = 3;
    // We have to set up the error handler, in case initialization fails.
	cinfo.err = jpeg_std_error(&jerr);

    // Initialize the JPEG decompression object.
	jpeg_create_decompress(&cinfo);

	// Specify data source (eg, a file, for us, memory)
	jpeg_memory_src(&cinfo, const_cast<uint8*>(input.getCArray()), input.size());

	// Read the parameters with jpeg_read_header()
	jpeg_read_header(&cinfo, TRUE);

	// Set parameters for decompression
	// (We do nothing here since the defaults are fine)

	// Start decompressor
	jpeg_start_decompress(&cinfo);

	// Get and set the values of interest to this object
	this->width     = cinfo.output_width;
	this->height    = cinfo.output_height;

	// Prepare the pointer object for the pixel data
    _byte = (uint8*)System::malloc(width * height * 3);

 	// JSAMPLEs per row in output buffer
    int bpp         = cinfo.output_components;
    int row_stride  = cinfo.output_width * bpp;

	// Make a one-row-high sample array that will go away when done with image
    JSAMPARRAY temp = (*cinfo.mem->alloc_sarray)
		((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

    // Read data on a scanline by scanline basis
	while (cinfo.output_scanline < cinfo.output_height) {

        // We may need to adjust the output based on the
        // number of channels it has.
        switch (bpp) {
	    case 1:
            // Grayscale; decompress to temp.
    		jpeg_read_scanlines(&cinfo, temp, 1);

            // Expand to three channels
            {
                uint8* scan     = &(_byte[loc * 3]);
                uint8* endScan  = scan + (width * 3);
                uint8* t        = *temp;

                while (scan < endScan) {
                    uint8 value = t[0];

                    // Spread the value 3x.
                    scan[0] = value;
                    scan[1] = value;
                    scan[2] = value;

                    scan    += 3;
                    t       += 1;
                }
            }
		    break;

	    case 3:
            // Read directly into the array
            {
                // Need one extra level of indirection.
                uint8*     scan = _byte + loc;
                JSAMPARRAY ptr  = &scan;
    		    jpeg_read_scanlines(&cinfo, ptr, 1);
            }
		    break;

	    case 4:
            // RGBA; decompress to temp.
    		jpeg_read_scanlines(&cinfo, temp, 1);

            // Drop the 3rd channel
            {
                uint8* scan     = &(_byte[loc * 3]);
                uint8* endScan  = scan + width * 3;
                uint8* t        = *temp;

                while (scan < endScan) {
                    scan[0] = t[0];
                    scan[1] = t[1];
                    scan[2] = t[2];
                    
                    scan    += 3;
                    t       += 4;
                }
            }
		    break;

	    default:
		    throw Error("Unexpected number6 of channels.", input.getFilename());
	    }

		loc += row_stride;
	}

	// Finish decompression
	jpeg_finish_decompress(&cinfo);

	// Release JPEG decompression object
	jpeg_destroy_decompress(&cinfo);
}
Example #16
0
void GImage::decodeBMP(
    BinaryInput&            input) {

    // The BMP decoding uses these flags.
    static const uint16 PICTURE_NONE               = 0x0000;
    static const uint16 PICTURE_BITMAP             = 0x1000;

    // Compression Flags
    static const uint16 PICTURE_UNCOMPRESSED       = 0x0100;
    static const uint16 PICTURE_MONOCHROME         = 0x0001;
    static const uint16 PICTURE_4BIT               = 0x0002;
    static const uint16 PICTURE_8BIT               = 0x0004;
    static const uint16 PICTURE_16BIT              = 0x0008;
    static const uint16 PICTURE_24BIT              = 0x0010;
    static const uint16 PICTURE_32BIT              = 0x0020;

    (void)PICTURE_16BIT;
    (void)PICTURE_32BIT;

    // This is a simple BMP loader that can handle uncompressed BMP files.
    // Verify this is a BMP file by looking for the BM tag.
    input.reset();
    std::string tag = input.readString(2);
    if (tag != "BM") {
        throw Error("Not a BMP file", input.getFilename());
    }

    m_channels = 3;
	// Skip to the BITMAPINFOHEADER's width and height
	input.skip(16);

    m_width  = input.readUInt32();
    m_height = input.readUInt32();

	// Skip to the bit count and compression type
	input.skip(2);

    uint16 bitCount        = input.readUInt16();
    uint32 compressionType = input.readUInt32();

    uint8 red;
    uint8 green;
    uint8 blue;
    uint8 blank;

	// Only uncompressed bitmaps are supported by this code
    if ((int32)compressionType != BI_RGB) {
        throw Error("BMP images must be uncompressed", input.getFilename());
    }

    uint8* palette = NULL;

	// Create the palette if needed
    if (bitCount <= 8) {

        // Skip to the palette color count in the header
        input.skip(12);

        int numColors = input.readUInt32();

        palette = (uint8*)System::malloc(numColors * 3);
        debugAssert(palette);

        // Skip past the end of the header to the palette info
        input.skip(4);

        int c;
        for (c = 0; c < numColors * 3; c += 3) {
            // Palette information in bitmaps is stored in BGR_ format.
            // That means it's blue-green-red-blank, for each entry.
            blue  = input.readUInt8();
            green = input.readUInt8();
            red   = input.readUInt8();
            blank = input.readUInt8();

            palette[c]     = red;
            palette[c + 1] = green;
            palette[c + 2] = blue;
        }
	}

    int hStart = 0;
    int hEnd   = 0;
    int hDir   = 0;

    if (m_height < 0) {
        m_height = -m_height;
        hStart = 0;
        hEnd   = m_height;
        hDir   = 1;
    } else {
        //height = height;
        hStart = m_height - 1;
        hEnd   = -1;
        hDir   = -1;
    }

    m_byte = (uint8*)m_memMan->alloc(m_width * m_height * 3);
    debugAssert(m_byte);

    int BMScanWidth;
    int BMPadding;
    uint8 BMGroup;
    uint8 BMPixel8;
    int currPixel;
    int dest;
    int flags = PICTURE_NONE;

    if (bitCount == 1) {
        // Note that this file is not necessarily grayscale, since it's possible
        // the palette is blue-and-white, or whatever. But of course most image
        // programs only write 1-bit images if they're black-and-white.
        flags = PICTURE_BITMAP | PICTURE_UNCOMPRESSED | PICTURE_MONOCHROME;

        // For bitmaps, each scanline is dword-aligned.
        BMScanWidth = (m_width + 7) >> 3;
        if (BMScanWidth & 3) {
            BMScanWidth += 4 - (BMScanWidth & 3);
        }

        // Powers of 2
        int pow2[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};

        for (int h = hStart; h != hEnd; h += hDir) {

            currPixel = 0;
            dest = 3 * h * m_width;

            for (int w = 0; w < BMScanWidth; ++w) {

                BMGroup = input.readUInt8();

                // Now we read the pixels. Usually there are eight pixels per byte,
                // since each pixel is represented by one bit, but if the width
                // is not a multiple of eight, the last byte will have some bits
                // set, with the others just being extra. Plus there's the
                // dword-alignment padding. So we keep checking to see if we've
                // already read "width" number of pixels.
                for (int i = 7; i >= 0; --i) {
                    if (currPixel < m_width) {
                        int src  = 3 * ((BMGroup & pow2[i]) >> i);
                    
                        m_byte[dest]     = palette[src];
                        m_byte[dest + 1] = palette[src + 1];
                        m_byte[dest + 2] = palette[src + 2];
                    
                        ++currPixel;
                        dest += 3;
                    }
                }
            }
        }
Example #17
0
	void deserialize(BinaryInput& b) {
		i32 = b.readInt32();
		i64 = b.readInt64();
		s   = b.readString();
		f	= b.readFloat32();
	}
Example #18
0
GFont::GFont(const String& filename, BinaryInput& b) {    

    int ver = b.readInt32();
    debugAssertM(ver == 1 || ver == 2, "Can't read font files other than version 1");
    (void)ver;

    if (ver == 1) {
        charsetSize = 128;
    } else {
        charsetSize = b.readInt32();
    }

    // Read the widths
    subWidth.resize(charsetSize);
    for (int c = 0; c < charsetSize; ++c) {
        subWidth[c] = b.readUInt16();
    }

    baseline = b.readUInt16();
    int texWidth = b.readUInt16();
    charWidth  = texWidth / 16;
    charHeight = texWidth / 16;

    // The input may not be a power of 2
    int width  = ceilPow2(charWidth * 16);
    int height = ceilPow2(charHeight * (charsetSize / 16));
  
    // Create a texture
    const uint8* ptr = ((uint8*)b.getCArray()) + b.getPosition();
    debugAssertM((b.getLength() - b.getPosition()) >= width * height, 
        "File does not contain enough data for this size texture");

    Texture::Preprocess preprocess;
    preprocess.computeMinMaxMean = false;
    const bool generateMipMaps = true;

    
    m_texture = 
        Texture::fromMemory
        (   filename, 
            ptr,
            ImageFormat::R8(),
            width, 
            height,
            1,
            1,
            ImageFormat::R8(), 
            Texture::DIM_2D,
            generateMipMaps,
            preprocess);
       
    m_textureMatrix[0] = 1.0f / m_texture->width();
    m_textureMatrix[1] = 0;
    m_textureMatrix[2] = 0;
    m_textureMatrix[3] = 0;
    m_textureMatrix[4] = 0;
    m_textureMatrix[5] = 1.0f / m_texture->height();
    m_textureMatrix[6] = 0;
    m_textureMatrix[7] = 0;    
    m_textureMatrix[8] = 0;
    m_textureMatrix[9] = 0;
    m_textureMatrix[10] = 1;
    m_textureMatrix[11] = 0;
    m_textureMatrix[12] = 0;
    m_textureMatrix[13] = 0;
    m_textureMatrix[14] = 0;
    m_textureMatrix[15] = 1;

    m_name = filename;
}
Example #19
0
void GImage::decodeTGA(
    BinaryInput&        input) {

    // This is a simple TGA loader that can handle uncompressed
    // truecolor TGA files (TGA type 2). 
    // Verify this is a TGA file by looking for the TRUEVISION tag.
    int pos = input.getPosition();
    input.setPosition(input.size() - 18);
    std::string tag = input.readString(16);
    if (tag != "TRUEVISION-XFILE") {
        throw Error("Not a TGA file", input.getFilename());
    }

    input.setPosition(pos);

    int IDLength     = input.readUInt8();
    int colorMapType = input.readUInt8();
    int imageType    = input.readUInt8();

    (void)colorMapType;
	
    // 2 is the type supported by this routine.
    if (imageType != 2) {
        throw Error("TGA images must be type 2 (Uncompressed truecolor)", input.getFilename());
    }
	
    // Color map specification
    input.skip(5);

    // Image specification

    // Skip x and y offsets
    input.skip(4); 

    m_width  = input.readInt16();
    m_height = input.readInt16();

    int colorDepth = input.readUInt8();

    if ((colorDepth != 24) && (colorDepth != 32)) {
        throw Error("TGA files must be 24 or 32 bit.", input.getFilename());
    }

    if (colorDepth == 32) {
        m_channels = 4;
    } else {
        m_channels = 3;
    }

    // Image descriptor contains overlay data as well
    // as data indicating where the origin is
    int imageDescriptor = input.readUInt8();
    (void)imageDescriptor;
	
    // Image ID
    input.skip(IDLength);

    m_byte = (uint8*)m_memMan->alloc(m_width * m_height * m_channels);
    debugAssert(m_byte);
	
    // Pixel data
    int x;
    int y;

    if (m_channels == 3) {
        for (y = m_height - 1; y >= 0; --y) {
          for (x = 0; x < m_width; ++x) {
            int b = input.readUInt8();
            int g = input.readUInt8();
            int r = input.readUInt8();
		    
            int i = (x + y * m_width) * 3;
            m_byte[i + 0] = r;
            m_byte[i + 1] = g;
            m_byte[i + 2] = b;
          }
        }
    } else {
        for (y = m_height - 1; y >= 0; --y) {
          for (x = 0; x < m_width; ++x) {
            int b = input.readUInt8();
            int g = input.readUInt8();
            int r = input.readUInt8();
            int a = input.readUInt8();
		    
            int i = (x + y * m_width) * 4;
            m_byte[i + 0] = r;
            m_byte[i + 1] = g;
            m_byte[i + 2] = b;
            m_byte[i + 3] = a;
          }
        }
    }
}