Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
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;
}