コード例 #1
0
ファイル: png.cpp プロジェクト: kucerad/rpak-viz
// Save current image in file [true = success, false otherwise]
bool PNG::save(string pathname) const{
	//create encoder and set settings and info (optional)
	LodePNG::Encoder encoder;
	encoder.getSettings().zlibsettings.windowSize = 2048;

	//encode and save
	std::vector<unsigned char> buffer;
	encoder.encode(buffer, image.empty() ? 0 : &image[0], width, height);
	LodePNG::saveFile(buffer, pathname);
	
	if(encoder.hasError())
	{
		return false;
	}
	return true;
}
コード例 #2
0
bool ImageWriter::convert( Image* image )
{
    #pragma TODO("Fix the LodePNG image writing code to the new API")

#if defined(ENABLE_IMAGE_WRITER_)
	LodePNG::Encoder encoder;
	
	LodePNG_InfoColor& png = encoder.getInfoPng().color;
	LodePNG_InfoColor& raw = encoder.getInfoRaw().color;
	
	switch(image->getPixelFormat())
	{
	case PixelFormat::Depth:
		png.colorType = 0;
		raw.colorType = 0;
		break;
	case PixelFormat::R8G8B8:
		png.colorType = 2;
		raw.colorType = 2;
		break;
	case PixelFormat::R8G8B8A8:
		png.colorType = 6;
		raw.colorType = 6;
		break;
	default:
		LogError("Pixel format is not supported");
		return false;
	}

	raw.bitDepth = 8;
	
	encoder.encode(output, image->getBuffer(),
		image->getWidth(), image->getHeight());

	if( encoder.hasError() )
	{
		LogError("Could not encode image to PNG");
		return false;
	}

	return true;
#else
	return false;
#endif
}
コード例 #3
0
ファイル: ProceduralTexture.cpp プロジェクト: PH3NIX/CubicVR
bool ProceduralTexture::savePNG(char *png_map)
{
	std::vector<unsigned char> buffer;
		
	//create encoder and set settings and info (optional)
	LodePNG::Encoder encoder;
	encoder.addText("Comment", "CubicVR Procedural Texture");
	encoder.getSettings().zlibsettings.windowSize = 2048;
	
	encoder.encode(buffer, image.empty() ? 0 : &image[0], width, height);
	
	if(encoder.hasError())
	{
		Logger::log(LOG_ERROR,"[savePng] Error %d\n", encoder.getError());
		return false;
	}
	
	LodePNG::saveFile(buffer, png_map);
	
	return true;
}
コード例 #4
0
void FW::exportLodePngImage(OutputStream& stream, const Image* image)
{
    // Select format and convert.

    FW_ASSERT(image);
    const Vec2i& size = image->getSize();
    bool hasAlpha = image->getFormat().hasChannel(ImageFormat::ChannelType_A);
    ImageFormat::ID format = (hasAlpha) ? ImageFormat::R8_G8_B8_A8 : ImageFormat::R8_G8_B8;

    Image* converted = NULL;
    if (image->getFormat().getID() != format)
    {
        converted = new Image(size, format);
        *converted = *image;
    }

    // Encode image.

    LodePNG::Encoder encoder;
    int colorType = (hasAlpha) ? 6 : 2;
    encoder.getSettings().autoLeaveOutAlphaChannel = false;
    encoder.getInfoRaw().color.colorType = colorType;
    encoder.getInfoPng().color.colorType = colorType;

    std::vector<U8> dataBuffer;
    encoder.encode(dataBuffer, (U8*)((converted) ? converted : image)->getPtr(), size.x, size.y);

    if (encoder.hasError())
        setError("exportLodePngImage(): LodePNG error %d!", encoder.getError());

    // Write to the output stream.

    if (!hasError() && !dataBuffer.empty())
        stream.write(&dataBuffer[0], (int)dataBuffer.size());

    // Clean up.

    delete converted;
}