Esempio n. 1
0
bool cineon::Reader::ReadBlock(void *data, const DataSize size, Block &block)
{
	int i;

	// check the block coordinates
	block.Check();

	// get the number of components for this element descriptor
	const int numberOfComponents = this->header.NumberOfElements();

	// check the widths and bit depths of the image elements
	bool consistentDepth = true;
	bool consistentWidth = true;
	const int bitDepth = this->header.BitDepth(0);
	const int width = this->header.PixelsPerLine(0);
	for (i = 1; i < numberOfComponents; i++) {
		if (this->header.BitDepth(i) != bitDepth) {
			consistentDepth = false;
			if (!consistentWidth)
				break;
		}
		if (this->header.PixelsPerLine(i) != width) {
			consistentWidth = false;
			if (!consistentDepth)
				break;
		}
	}

	// lets see if this can be done in a single fast read
	if (consistentDepth && consistentWidth && this->header.EndOfLinePadding() == 0 &&
		((bitDepth == 8 && size == cineon::kByte) ||
		 (bitDepth == 16 && size == cineon::kWord) ||
		 (bitDepth == 32 && size == cineon::kInt) ||
		 (bitDepth == 64 && size == cineon::kLongLong)) &&
		block.x1 == 0 && block.x2 == (int)(this->header.Width()-1))
	{
		// seek to the beginning of the image block
		if (this->fd->Seek((this->header.ImageOffset() + (block.y1 * this->header.Width() * (bitDepth / 8) * numberOfComponents)), InStream::kStart) == false)
			return false;

		// size of the image
		const size_t imageSize = this->header.Width() * (block.y2 - block.y1 + 1) * numberOfComponents;
		const size_t imageByteSize = imageSize * bitDepth / 8;

		size_t rs = this->fd->ReadDirect(data, imageByteSize);
		if (rs != imageByteSize)
			return false;

		// swap the bytes if different byte order
		if (this->header.RequiresByteSwap())
			cineon::EndianSwapImageBuffer(size, data, imageSize);

		return true;
	}


	// determine if the encoding system is loaded
	if (this->codec == 0)
		// this element reader has not been used
		this->codec = new Codec;

	// read the image block
	return this->codec->Read(this->header, this->rio, block, data, size);
}
Esempio n. 2
0
bool dpx::Reader::ReadBlock(void* data, const DataSize size, Block& block, const Descriptor desc)
{
    int i;
    int element;

    // check the block coordinates
    block.Check();

    // determine which element we are viewing
    for(i = 0; i < MAX_ELEMENTS; i++)
    {
        if(this->header.ImageDescriptor(i) == desc)
        {
            element = i;
            break;
        }
    }
    if(i == MAX_ELEMENTS) // was it found?
        return false;

    // get the number of components for this element descriptor
    const int numberOfComponents = this->header.ImageElementComponentCount(element);

    // bit depth of the image element
    const int bitDepth = this->header.BitDepth(element);

    // rle encoding?
    const bool rle = (this->header.ImageEncoding(element) == kRLE);

    // lets see if this can be done in a single fast read
    if(!rle && this->header.EndOfLinePadding(element) == 0 &&
       ((bitDepth == 8 && size == dpx::kByte) || (bitDepth == 16 && size == dpx::kWord) ||
        (bitDepth == 32 && size == dpx::kFloat) || (bitDepth == 64 && size == dpx::kDouble)) &&
       block.x1 == 0 && block.x2 == (int)(this->header.Width() - 1))
    {
        // seek to the beginning of the image block
        if(this->fd->Seek(
               (this->header.DataOffset(element) + (block.y1 * this->header.Width() * (bitDepth / 8) * numberOfComponents)),
               InStream::kStart) == false)
            return false;

        // size of the image
        const size_t imageSize = this->header.Width() * (block.y2 - block.y1 + 1) * numberOfComponents;
        const size_t imageByteSize = imageSize * bitDepth / 8;

        size_t rs = this->fd->ReadDirect(data, imageByteSize);
        if(rs != imageByteSize)
            return false;

        // swap the bytes if different byte order
        if(this->header.RequiresByteSwap())
            dpx::EndianSwapImageBuffer(size, data, imageSize);

        return true;
    }

    // determine if the encoding system is loaded
    if(this->codex[element] == 0)
    {
        // this element reader has not been used
        if(rle)
            // TODO
            // this->codex[element] = new RunLengthEncoding;
            return false;
        else
            this->codex[element] = new Codec;
    }

    // read the image block
    return this->codex[element]->Read(this->header, this->rio, element, block, data, size);
}