Ejemplo n.º 1
0
bool FormImageBase::saveFile(const QString &fileName){
    qDebug() << Q_FUNC_INFO << "image:" << fileName;

    QFileInfo fileInfo(fileName);
    (*recentDir).setPath(fileInfo.absolutePath());
    image = imageProp.getImage();

    if( PostfixNames::outputFormat.compare(".tga") == 0 || fileInfo.completeSuffix().compare("tga") == 0 ){
        TargaImage tgaImage;
        tgaImage.write(image,fileName);
    }else{
        image.save(fileName);
    }

    return true;
}
Ejemplo n.º 2
0
void FormImageBase::saveImageToDir(const QString &dir,QImage& image){

    QString fullFileName = dir + "/" +
                           imageName + PostfixNames::getPostfix(imageProp.imageType)
                           + PostfixNames::outputFormat;

    qDebug() << "<FormImageProp> save image:" << fullFileName;
    QFileInfo fileInfo(fullFileName);
    (*recentDir).setPath(fileInfo.absolutePath());

    if( PostfixNames::outputFormat.compare(".tga") == 0){
        TargaImage tgaImage;
        tgaImage.write(image,fullFileName);
    }else
        image.save(fullFileName);
}
/* saveTargaColorMatrix()
 * ----------------------
 * Save the specified ColorMatrix as the specified targa file 
 * @param targaFilename - name of the targa file to save as (including .tga)
 * @return - true on successful save, false on failure 
 */
bool ImageProcessing::saveTargaColorMatrix(const string& targaFilename, 
										   const ColorMatrix& source) 
{
	// Try to load a blank targa for the output
	TargaImage* dest = TargaImage::blankImage(source.cols(), source.rows());
	if( dest == nullptr ) {
		cout << "Error: unable to create blank image for output." << endl;
		return false;
	}

	// Setup constants for the output image
	const unsigned int rows   = dest->height();
	const unsigned int cols   = dest->width();
	unsigned char*	   pixels = dest->pixels();

	// Write the source ColorMatrix to the dest TargaImage
	for(unsigned int row = 0, i = 0; row < rows; ++row)
	for(unsigned int col = 0; col < cols; ++col, ++i)
	{
		const Color color(source(row,col));
		pixels[i*4 + 0] = color.r();
		pixels[i*4 + 1] = color.g();
		pixels[i*4 + 2] = color.b();
		pixels[i*4 + 3] = color.a();
	}

	// Save the new dest TargaImage
	bool success = true;
	if( dest->write(targaFilename.c_str()) != 1 ) {
		cout << "Error: unable to save " << targaFilename 
			 << ", " << tga_error_string(tga_get_last_error()) 
			 << endl;
		success = false;
	} 

	// Cleanup the new TargaImage
	delete dest;
	
	return success;
}