2025-06-28 17:40:42 +02:00
|
|
|
// /*
|
|
|
|
|
// * File: PixelToImageWriter.cpp
|
|
|
|
|
// * Author: Saleem Edah-Tally - nmset@yandex.com
|
|
|
|
|
// * License : CeCILL-C
|
|
|
|
|
// * Copyright Saleem Edah-Tally - © 2025
|
|
|
|
|
// *
|
|
|
|
|
// * Created on 27 06 2025, 20:28
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
#include "PixelToImageWriter.h"
|
2025-07-01 22:38:07 +02:00
|
|
|
#include <StampWorker.h>
|
2025-06-28 17:40:42 +02:00
|
|
|
#include <fstream>
|
2025-07-01 22:38:07 +02:00
|
|
|
#include <DefsInsaneWidget.h>
|
|
|
|
|
#include <DefsStampWidget.h>
|
2025-06-28 17:40:42 +02:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
bool PixelToImageWriter::Convert(const std::string& pixelFilePath,
|
2025-07-01 22:38:07 +02:00
|
|
|
int imageWidth, int imageHeight,
|
|
|
|
|
std::vector<StampDescriptor*> * descriptors,
|
|
|
|
|
int outputFormat, wxImage * image)
|
2025-06-28 17:40:42 +02:00
|
|
|
{
|
|
|
|
|
UpdateExtensionsMap();
|
|
|
|
|
wxImage * outImage = image;
|
|
|
|
|
unique_ptr<wxImage> tmpImage;
|
|
|
|
|
if (!image)
|
|
|
|
|
{
|
|
|
|
|
tmpImage = make_unique<wxImage>();
|
|
|
|
|
outImage = tmpImage.get();
|
|
|
|
|
}
|
|
|
|
|
string raw;
|
|
|
|
|
ifstream ifs(pixelFilePath, ios::binary);
|
|
|
|
|
if (!ifs.good())
|
|
|
|
|
{
|
|
|
|
|
cerr << _("Failed to read raw file.") << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
raw.assign(istreambuf_iterator<char>(ifs), istreambuf_iterator<char>());
|
|
|
|
|
|
|
|
|
|
outImage->SetData((unsigned char*) raw.data(), imageWidth, imageHeight, true); // true +++
|
2025-07-01 22:38:07 +02:00
|
|
|
if (descriptors)
|
|
|
|
|
{
|
|
|
|
|
for (StampDescriptor * descriptor : *descriptors)
|
|
|
|
|
{
|
|
|
|
|
if (descriptor)
|
|
|
|
|
{
|
|
|
|
|
StampWorker::StampBackground(*outImage, descriptor->image, descriptor->location);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-28 17:40:42 +02:00
|
|
|
|
|
|
|
|
switch (outputFormat)
|
|
|
|
|
{
|
|
|
|
|
case PNG:
|
|
|
|
|
outImage->SaveFile(pixelFilePath + "." + Extensions[PNG], wxBITMAP_TYPE_PNG);
|
|
|
|
|
break;
|
|
|
|
|
case JPEG:
|
|
|
|
|
outImage->SaveFile(pixelFilePath + "." + Extensions[JPEG], wxBITMAP_TYPE_JPEG);
|
|
|
|
|
break;
|
|
|
|
|
case TIFF:
|
|
|
|
|
outImage->SaveFile(pixelFilePath + "." + Extensions[TIFF], wxBITMAP_TYPE_TIFF);
|
|
|
|
|
break;
|
|
|
|
|
case PNM:
|
|
|
|
|
outImage->SaveFile(pixelFilePath + "." + Extensions[PNM], wxBITMAP_TYPE_PNM);
|
|
|
|
|
break;
|
|
|
|
|
case PDF:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
cerr << _("Unhandled output image format.") << endl;
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|