当前位置: 首页>>代码示例>>C++>>正文


C++ ImageDecoder类代码示例

本文整理汇总了C++中ImageDecoder的典型用法代码示例。如果您正苦于以下问题:C++ ImageDecoder类的具体用法?C++ ImageDecoder怎么用?C++ ImageDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ImageDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getColorRows

void PLTFile::getColorRows(byte rows[4 * 256 * kLayerMAX], const uint8 colors[kLayerMAX]) {
	for (uint i = 0; i < kLayerMAX; i++, rows += 4 * 256) {
		ImageDecoder *palette = 0;

		try {
			palette = getLayerPalette(i, colors[i]);

			// The images have their origin at the bottom left, so we flip the color row
			const uint8 row = palette->getMipMap(0).height - 1 - colors[i];

			// Copy the whole row into the buffer
			memcpy(rows, palette->getMipMap(0).data + (row * 4 * 256), 4 * 256);

		} catch (Common::Exception &e) {
			// On error set to pink (while honoring intensity), for high debug visibility
			for (uint32 p = 0; p < 256; p++) {
				rows[p * 4 + 0] = p;
				rows[p * 4 + 1] = 0x00;
				rows[p * 4 + 2] = p;
				rows[p * 4 + 3] = 0xFF;
			}

			e.add("Failed to load palette \"%s\"", kPalettes[i]);
			Common::printException(e, "WARNING: ");
		}

		delete palette;
	}
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例2: assert

/** Load a specific layer palette image and perform some sanity checks. */
ImageDecoder *PLTFile::getLayerPalette(uint32 layer, uint8 row) {
	assert(layer < kLayerMAX);

	// TODO: We may want to cache these somehow...
	ImageDecoder *palette = loadImage(kPalettes[layer]);
	try {
		if (palette->getFormat() != kPixelFormatBGRA)
			throw Common::Exception("Invalid format (%d)", palette->getFormat());

		if (palette->getMipMapCount() < 1)
			throw Common::Exception("No mip maps");

		const ImageDecoder::MipMap &mipMap = palette->getMipMap(0);

		if (mipMap.width != 256)
			throw Common::Exception("Invalid width (%d)", mipMap.width);

		if (row >= mipMap.height)
			throw Common::Exception("Invalid height (%d >= %d)", row, mipMap.height);

	} catch (...) {
		delete palette;
		throw;
	}

	return palette;
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例3:

Surface *ImageDecoder::loadFile(Common::SeekableReadStream &stream, const PixelFormat &format) {
	// TODO: implement support for bzipped memory

	// FIXME: this is not a very nice solution but it should work
	// for the moment, we should use a different way to get all
	// decoders
	static BMPDecoder bmpDecoder;
	static ImageDecoder *decoderList[] = {
		&bmpDecoder,			// for uncompressed .BMP files
		0
	};

	ImageDecoder *decoder = 0;
	for (int i = 0; decoderList[i] != 0; ++i) {
		if (decoderList[i]->decodeable(stream)) {
			decoder = decoderList[i];
			break;
		}
	}

	if (!decoder)
		return 0;

	return decoder->decodeImage(stream, format);
}
开发者ID:AdamRi,项目名称:scummvm-pink,代码行数:25,代码来源:imagedec.cpp

示例4: _SYS_image_BG1DrawRect

void _SYS_image_BG1DrawRect(struct _SYSAttachedVideoBuffer *vbuf,
    const _SYSAssetImage *im, struct _SYSInt2 *destXY, unsigned frame,
        struct _SYSInt2 *srcXY, struct _SYSInt2 *size)
{
    if (!isAligned(vbuf) || !isAligned(im) ||
        !isAligned(destXY) || !isAligned(srcXY) || !isAligned(size))
        return SvmRuntime::fault(F_SYSCALL_ADDR_ALIGN);

    if (!SvmMemory::mapRAM(vbuf))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);

    struct _SYSInt2 lDestXY, lSrcXY, lSize;
    if (!SvmMemory::copyROData(lDestXY, destXY))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);
    if (!SvmMemory::copyROData(lSrcXY, srcXY))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);
    if (!SvmMemory::copyROData(lSize, size))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);

    ImageDecoder decoder;
    if (!decoder.init(im, vbuf->cube))
        return SvmRuntime::fault(F_BAD_ASSET_IMAGE);

    ImageIter iter(decoder, frame, lSrcXY.x, lSrcXY.y, lSize.x, lSize.y);
    iter.copyToBG1(vbuf->vbuf, lDestXY.x, lDestXY.y);
}
开发者ID:andrewsmyk,项目名称:thundercracker,代码行数:26,代码来源:syscall_image.cpp

示例5: _SYS_image_memDrawRect

void _SYS_image_memDrawRect(uint16_t *dest, _SYSCubeID destCID,
    const _SYSAssetImage *im, unsigned dest_stride, unsigned frame,
    struct _SYSInt2 *srcXY, struct _SYSInt2 *size)
{
    if (!isAligned(dest, 2) || !isAligned(im) || !isAligned(srcXY) || !isAligned(size))
        return SvmRuntime::fault(F_SYSCALL_ADDR_ALIGN);

    struct _SYSInt2 lSrcXY, lSize;
    if (!SvmMemory::copyROData(lSrcXY, srcXY))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);
    if (!SvmMemory::copyROData(lSize, size))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);

    ImageDecoder decoder;
    if (destCID == _SYS_CUBE_ID_INVALID) {
        // Relocation disabled
        if (!decoder.init(im))
            return SvmRuntime::fault(F_BAD_ASSET_IMAGE);
    } else {
        // Relocate to a specific cube (validated by decoder.init)
        if (!decoder.init(im, destCID))
            return SvmRuntime::fault(F_BAD_ASSET_IMAGE);
    }

    ImageIter iter(decoder, frame, lSrcXY.x, lSrcXY.y, lSize.x, lSize.y);

    if (!SvmMemory::mapRAM(dest, iter.getDestBytes(dest_stride)))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);

    iter.copyToMem(dest, dest_stride);
}
开发者ID:andrewsmyk,项目名称:thundercracker,代码行数:31,代码来源:syscall_image.cpp

示例6: load

void Cursor::load() {
	::Aurora::FileType type;

	Common::SeekableReadStream *img = ResMan.getResource(::Aurora::kResourceCursor, _name, &type);
	if (!img)
		throw Common::Exception("No such cursor resource \"%s\"", _name.c_str());

	_hotspotX = 0;
	_hotspotY = 0;

	ImageDecoder *image;
	// Loading the different image formats
	if      (type == ::Aurora::kFileTypeTGA)
		image = new TGA(*img);
	else if (type == ::Aurora::kFileTypeDDS)
		image = new DDS(*img);
	else if (type == ::Aurora::kFileTypeCUR) {
		WinIconImage *cursor = new WinIconImage(*img);

		if (_hotspotX < 0)
			_hotspotX = cursor->getHotspotX();
		if (_hotspotY < 0)
			_hotspotY = cursor->getHotspotY();

		image = cursor;
	} else {
		delete img;
		throw Common::Exception("Unsupported cursor resource type %d", (int) type);
	}

	delete img;

	_width  = image->getMipMap(0).width;
	_height = image->getMipMap(0).height;

	TXI txi;
	txi.getFeatures().filter = false;

	try {
		Texture *texture = new Texture(image, &txi);

		image = 0;

		try {
			_texture = TextureMan.add(texture, _name);
		} catch(...) {
			delete texture;
			throw;
		}

	} catch (...) {
		delete image;
		throw;
	}

	_hotspotX = CLIP(_hotspotX, 0, _width  - 1);
	_hotspotY = CLIP(_hotspotY, 0, _height - 1);
}
开发者ID:DeejStar,项目名称:xoreos,代码行数:58,代码来源:cursor.cpp

示例7: TRACE_EVENT1

SkBitmap ImageFrameGenerator::tryToResumeDecode(size_t index, const SkISize& scaledSize)
{
    TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecode", "frame index", static_cast<int>(index));

    ImageDecoder* decoder = 0;
    const bool resumeDecoding = ImageDecodingStore::instance().lockDecoder(this, m_fullSize, &decoder);
    ASSERT(!resumeDecoding || decoder);

    SkBitmap fullSizeImage;
    bool complete = decode(index, &decoder, &fullSizeImage);

    if (!decoder)
        return SkBitmap();

    // If we are not resuming decoding that means the decoder is freshly
    // created and we have ownership. If we are resuming decoding then
    // the decoder is owned by ImageDecodingStore.
    OwnPtr<ImageDecoder> decoderContainer;
    if (!resumeDecoding)
        decoderContainer = adoptPtr(decoder);

    if (fullSizeImage.isNull()) {
        // If decoding has failed, we can save work in the future by
        // ignoring further requests to decode the image.
        m_decodeFailed = decoder->failed();
        if (resumeDecoding)
            ImageDecodingStore::instance().unlockDecoder(this, decoder);
        return SkBitmap();
    }

    bool removeDecoder = false;
    if (complete) {
        // Free as much memory as possible.  For single-frame images, we can
        // just delete the decoder entirely.  For multi-frame images, we keep
        // the decoder around in order to preserve decoded information such as
        // the required previous frame indexes, but if we've reached the last
        // frame we can at least delete all the cached frames.  (If we were to
        // do this before reaching the last frame, any subsequent requested
        // frames which relied on the current frame would trigger extra
        // re-decoding of all frames in the dependency chain.)
        if (!m_isMultiFrame)
            removeDecoder = true;
        else if (index == m_frameCount - 1)
            decoder->clearCacheExceptFrame(kNotFound);
    }

    if (resumeDecoding) {
        if (removeDecoder)
            ImageDecodingStore::instance().removeDecoder(this, decoder);
        else
            ImageDecodingStore::instance().unlockDecoder(this, decoder);
    } else if (!removeDecoder) {
        ImageDecodingStore::instance().insertDecoder(this, decoderContainer.release());
    }
    return fullSizeImage;
}
开发者ID:astojilj,项目名称:chromium-crosswalk,代码行数:56,代码来源:ImageFrameGenerator.cpp

示例8: decodeStream

Image* ImageFactory::decodeStream(io::InputStream* is, PixelFormat format) {
	Image* bitmap = nullptr;
	ImageDecoder* decoder = ImageDecoder::Factory(is);
	if (decoder) {
//		decoder->disablePreMultipyAlpha();
		decoder->decode(is, bitmap, format);
		delete decoder;
	}
	return bitmap;
}
开发者ID:lij0511,项目名称:pandora,代码行数:10,代码来源:ImageFactory.cpp

示例9: Surface

/* Create a tinted texture by combining the tint map with the tint colors.
 *
 * This is currently all done here in software and has several drawbacks:
 * - Slow
 * - We're creating lots of uncompressed RBGA texture, so it
 *   takes up a lot of memory, both on the GPU and in system RAM
 *
 * TODO: We really need to do this in shaders in the future.
 */
void ModelNode_NWN2::createTint() {
	if (_tintMap.empty())
		return;

	ImageDecoder *tintMap   = 0;
	Surface      *tintedMap = 0;
	try {
		// Load and uncompress the texture
		tintMap = Texture::loadImage(_tintMap);
		if (tintMap->isCompressed())
			tintMap->decompress();

		const ImageDecoder::MipMap &tintImg = tintMap->getMipMap(0);

		// Create a new target surface with the same dimensions
		tintedMap = new Surface(tintImg.width, tintImg.height);
		ImageDecoder::MipMap &tintedImg = tintedMap->getMipMap();

		// Iterate over all pixels: read values, mix tints, write pixel to target surface
		for (int n = 0; n < tintImg.width * tintImg.height; n++) {
			float srcColor[4], dstColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
			tintImg.getPixel(n, srcColor[0], srcColor[1], srcColor[2], srcColor[3]);

			if (srcColor[3] != 0.0f) {
				// Mix using the value and the alpha components as intensities
				// TODO: Verify how the mixing is actually done in NWN2!
				for (int i = 0; i < 3; i++) {
					for (int j = 0; j < 3; j++)
						dstColor[j] += _tint[i][j] * srcColor[i] * _tint[i][3] * srcColor[3] * _diffuse[i];
				}
			} else
				// Source alpha is 0.0f: No tinting for this pixel
				for (int i = 0; i < 3; i++)
					dstColor[i] = _diffuse[i] * _tint[i][3];

			tintedImg.setPixel(n, dstColor[0], dstColor[1], dstColor[2], dstColor[3]);
		}

	} catch (...) {
		delete tintMap;
		delete tintedMap;
		return;
	}

	delete tintMap;

	// And add the new texture to the TextureManager
	TextureHandle tintedTexture = TextureMan.add(Texture::create(tintedMap));

	_textures.push_back(tintedTexture);
	_tintedMapIndex = _textures.size() - 1;
}
开发者ID:Glyth,项目名称:xoreos,代码行数:61,代码来源:model_nwn2.cpp

示例10: TRACE_EVENT1

const ScaledImageFragment* ImageFrameGenerator::tryToResumeDecodeAndScale(const SkISize& scaledSize, size_t index)
{
    TRACE_EVENT1("webkit", "ImageFrameGenerator::tryToResumeDecodeAndScale", "index", static_cast<int>(index));

    ImageDecoder* decoder = 0;
    const bool resumeDecoding = ImageDecodingStore::instance()->lockDecoder(this, m_fullSize, &decoder);
    ASSERT(!resumeDecoding || decoder);

    OwnPtr<ScaledImageFragment> fullSizeImage = decode(index, &decoder);

    if (!decoder)
        return 0;

    // If we are not resuming decoding that means the decoder is freshly
    // created and we have ownership. If we are resuming decoding then
    // the decoder is owned by ImageDecodingStore.
    OwnPtr<ImageDecoder> decoderContainer;
    if (!resumeDecoding)
        decoderContainer = adoptPtr(decoder);

    if (!fullSizeImage) {
        // If decode has failed and resulted an empty image we can save work
        // in the future by returning early.
        m_decodeFailedAndEmpty = !m_isMultiFrame && decoder->failed();

        if (resumeDecoding)
            ImageDecodingStore::instance()->unlockDecoder(this, decoder);
        return 0;
    }

    const ScaledImageFragment* cachedImage = ImageDecodingStore::instance()->insertAndLockCache(this, fullSizeImage.release());

    // If the image generated is complete then there is no need to keep
    // the decoder. The exception is multi-frame decoder which can generate
    // multiple complete frames.
    const bool removeDecoder = cachedImage->isComplete() && !m_isMultiFrame;

    if (resumeDecoding) {
        if (removeDecoder)
            ImageDecodingStore::instance()->removeDecoder(this, decoder);
        else
            ImageDecodingStore::instance()->unlockDecoder(this, decoder);
    } else if (!removeDecoder) {
        ImageDecodingStore::instance()->insertDecoder(this, decoderContainer.release(), DiscardablePixelRef::isDiscardable(cachedImage->bitmap().pixelRef()));
    }

    if (m_fullSize == scaledSize)
        return cachedImage;
    return tryToScale(cachedImage, scaledSize, index);
}
开发者ID:halton,项目名称:blink-crosswalk,代码行数:50,代码来源:ImageFrameGenerator.cpp

示例11: TEST_F

TEST_F(ImageFrameGeneratorTest, incompleteBitmapCopied)
{
    setFrameStatus(ImageFrame::FramePartial);

    const ScaledImageFragment* tempImage= m_generator->decodeAndScale(fullSize());
    EXPECT_FALSE(tempImage->isComplete());
    EXPECT_EQ(1, m_frameBufferRequestCount);

    ImageDecoder* tempDecoder = 0;
    EXPECT_TRUE(ImageDecodingStore::instance()->lockDecoder(m_generator.get(), fullSize(), &tempDecoder));
    ASSERT_TRUE(tempDecoder);
    EXPECT_NE(tempDecoder->frameBufferAtIndex(0)->getSkBitmap().getPixels(), tempImage->bitmap().getPixels());
    ImageDecodingStore::instance()->unlockCache(m_generator.get(), tempImage);
    ImageDecodingStore::instance()->unlockDecoder(m_generator.get(), tempDecoder);
}
开发者ID:halton,项目名称:blink-crosswalk,代码行数:15,代码来源:ImageFrameGeneratorTest.cpp

示例12: _SYS_image_BG0Draw

void _SYS_image_BG0Draw(struct _SYSAttachedVideoBuffer *vbuf,
    const _SYSAssetImage *im, uint16_t addr, unsigned frame)
{
    if (!isAligned(vbuf) || !isAligned(im))
        return SvmRuntime::fault(F_SYSCALL_ADDR_ALIGN);

    if (!SvmMemory::mapRAM(vbuf))
        return SvmRuntime::fault(F_SYSCALL_ADDRESS);

    ImageDecoder decoder;
    if (!decoder.init(im, vbuf->cube))
        return SvmRuntime::fault(F_BAD_ASSET_IMAGE);

    ImageIter iter(decoder, frame);
    iter.copyToVRAM(vbuf->vbuf, addr, _SYS_VRAM_BG0_WIDTH);
}
开发者ID:andrewsmyk,项目名称:thundercracker,代码行数:16,代码来源:syscall_image.cpp

示例13: TRACE_EVENT1

SkBitmap ImageFrameGenerator::tryToResumeDecode(const SkISize& scaledSize, size_t index)
{
    TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecodeAndScale", "index", static_cast<int>(index));

    ImageDecoder* decoder = 0;
    const bool resumeDecoding = ImageDecodingStore::instance()->lockDecoder(this, m_fullSize, &decoder);
    ASSERT(!resumeDecoding || decoder);

    SkBitmap fullSizeImage;
    bool complete = decode(index, &decoder, &fullSizeImage);

    if (!decoder)
        return SkBitmap();

    // If we are not resuming decoding that means the decoder is freshly
    // created and we have ownership. If we are resuming decoding then
    // the decoder is owned by ImageDecodingStore.
    OwnPtr<ImageDecoder> decoderContainer;
    if (!resumeDecoding)
        decoderContainer = adoptPtr(decoder);

    if (fullSizeImage.isNull()) {
        // If decode has failed and resulted an empty image we can save work
        // in the future by returning early.
        m_decodeFailedAndEmpty = !m_isMultiFrame && decoder->failed();

        if (resumeDecoding)
            ImageDecodingStore::instance()->unlockDecoder(this, decoder);
        return SkBitmap();
    }

    // If the image generated is complete then there is no need to keep
    // the decoder. The exception is multi-frame decoder which can generate
    // multiple complete frames.
    const bool removeDecoder = complete && !m_isMultiFrame;

    if (resumeDecoding) {
        if (removeDecoder)
            ImageDecodingStore::instance()->removeDecoder(this, decoder);
        else
            ImageDecodingStore::instance()->unlockDecoder(this, decoder);
    } else if (!removeDecoder) {
        ImageDecodingStore::instance()->insertDecoder(this, decoderContainer.release());
    }
    return fullSizeImage;
}
开发者ID:RobinWuDev,项目名称:Qt,代码行数:46,代码来源:ImageFrameGenerator.cpp

示例14: if

ImageDecoder *Texture::loadImage(Common::SeekableReadStream *imageStream, ::Aurora::FileType type,
                                 TXI *txi) {

	// Check for a cube map, but only those that don't use a file for each side
	const bool isCubeMap = txi && txi->getFeatures().cube && (txi->getFeatures().fileRange == 0);

	ImageDecoder *image = 0;
	try {
		// Loading the different image formats
		if      (type == ::Aurora::kFileTypeTGA)
			image = new TGA(*imageStream, isCubeMap);
		else if (type == ::Aurora::kFileTypeDDS)
			image = new DDS(*imageStream);
		else if (type == ::Aurora::kFileTypeTPC)
			image = new TPC(*imageStream);
		else if (type == ::Aurora::kFileTypeTXB)
			image = new TXB(*imageStream);
		else if (type == ::Aurora::kFileTypeSBM)
			image = new SBM(*imageStream);
		else if (type == ::Aurora::kFileTypeXEOSITEX)
			image = new XEOSITEX(*imageStream);
		else
			throw Common::Exception("Unsupported image resource type %d", (int) type);

		if (image->getMipMapCount() < 1)
			throw Common::Exception("Texture has no images");

		// Decompress
		if (GfxMan.needManualDeS3TC())
			image->decompress();

	} catch (...) {
		delete image;
		delete imageStream;

		throw;
	}

	delete imageStream;
	return image;
}
开发者ID:ehalls,项目名称:xoreos,代码行数:41,代码来源:texture.cpp

示例15: TEST_F

TEST_F(ImageFrameGeneratorTest, frameHasAlpha)
{
    setFrameStatus(ImageFrame::FramePartial);

    char buffer[100 * 100 * 4];
    m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4);
    EXPECT_TRUE(m_generator->hasAlpha(0));
    EXPECT_EQ(1, m_decodeRequestCount);

    ImageDecoder* tempDecoder = 0;
    EXPECT_TRUE(ImageDecodingStore::instance().lockDecoder(m_generator.get(), fullSize(), &tempDecoder));
    ASSERT_TRUE(tempDecoder);
    tempDecoder->frameBufferAtIndex(0)->setHasAlpha(false);
    ImageDecodingStore::instance().unlockDecoder(m_generator.get(), tempDecoder);
    EXPECT_EQ(2, m_decodeRequestCount);

    setFrameStatus(ImageFrame::FrameComplete);
    m_generator->decodeAndScale(0, imageInfo(), buffer, 100 * 4);
    EXPECT_EQ(3, m_decodeRequestCount);
    EXPECT_FALSE(m_generator->hasAlpha(0));
}
开发者ID:howardroark2018,项目名称:chromium,代码行数:21,代码来源:ImageFrameGeneratorTest.cpp


注:本文中的ImageDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。