10#include "fitshistogramcommand.h"
11#include "fitshistogrameditor.h"
12#include "fitsviewer.h"
13#include "fits_debug.h"
16 FITSHistogramEditor * inHisto,
20 type(newType), min(lmin), max(lmax)
24FITSHistogramCommand::~FITSHistogramCommand()
29bool FITSHistogramCommand::calculateDelta(
const uint8_t * buffer)
31 uint8_t
const * image_buffer = m_ImageData->getImageBuffer();
32 uint32_t totalPixels = m_ImageData->samplesPerChannel() * m_ImageData->channels();
33 unsigned long totalBytes = totalPixels * m_ImageData->getBytesPerPixel();
35 auto * raw_delta =
new uint8_t[totalBytes];
37 if (raw_delta ==
nullptr)
39 qCWarning(KSTARS_FITS) <<
"Error! not enough memory to create image delta";
43 for (uint32_t i = 0; i < totalBytes; i++)
44 raw_delta[i] = buffer[i] ^ image_buffer[i];
46 compressedBytes =
sizeof(uint8_t) * totalBytes + totalBytes / 64 + 16 + 3;
48 delta =
new uint8_t[compressedBytes];
53 qCCritical(KSTARS_FITS)
54 <<
"FITSHistogram Error: Ran out of memory compressing delta";
58 int r = compress2(delta, &compressedBytes, raw_delta, totalBytes, 5);
64 qCCritical(KSTARS_FITS)
65 <<
"FITSHistogram Error: Failed to compress raw_delta";
73bool FITSHistogramCommand::reverseDelta()
75 uint8_t
const * image_buffer = m_ImageData->getImageBuffer();
76 uint32_t totalPixels = m_ImageData->samplesPerChannel() * m_ImageData->channels();
77 unsigned long totalBytes = totalPixels * m_ImageData->getBytesPerPixel();
79 auto * output_image =
new uint8_t[totalBytes];
81 if (output_image ==
nullptr)
83 qCWarning(KSTARS_FITS) <<
"Error! not enough memory to create output image";
87 auto * raw_delta =
new uint8_t[totalBytes];
89 if (raw_delta ==
nullptr)
91 delete[] output_image;
92 qCWarning(KSTARS_FITS) <<
"Error! not enough memory to create image delta";
96 int r = uncompress(raw_delta, &totalBytes, delta, compressedBytes);
99 qCCritical(KSTARS_FITS)
100 <<
"FITSHistogram compression error in reverseDelta()";
101 delete[] output_image;
106 for (
unsigned int i = 0; i < totalBytes; i++)
107 output_image[i] = raw_delta[i] ^ image_buffer[i];
109 m_ImageData->setImageBuffer(output_image);
116void FITSHistogramCommand::redo()
118 uint8_t
const * image_buffer = m_ImageData->getImageBuffer();
119 uint8_t * buffer =
nullptr;
120 uint32_t totalPixels = m_ImageData->samplesPerChannel() * m_ImageData->channels();
121 int BBP = m_ImageData->getBytesPerPixel();
125 if (delta !=
nullptr)
127 FITSImage::Statistic prevStats;
128 m_ImageData->saveStatistics(prevStats);
132 m_ImageData->restoreStatistics(stats);
138 m_ImageData->saveStatistics(stats);
141 if (type >= FITS_ROTATE_CW && type <= FITS_MOUNT_FLIP_V)
143 m_ImageData->applyFilter(type);
147 buffer =
new uint8_t[totalPixels * BBP];
149 if (buffer ==
nullptr)
151 qWarning(KSTARS_FITS()) <<
"Error! not enough memory to create image buffer in redo()";
156 memcpy(buffer, image_buffer, totalPixels * BBP);
163 m_ImageData->applyFilter(FITS_LINEAR,
nullptr, &dataMin, &dataMax);
167 m_ImageData->applyFilter(FITS_LOG,
nullptr, &dataMin, &dataMax);
171 m_ImageData->applyFilter(FITS_SQRT,
nullptr, &dataMin, &dataMax);
175 m_ImageData->applyFilter(type);
179 calculateDelta(buffer);
199void FITSHistogramCommand::undo()
203 if (delta !=
nullptr)
205 FITSImage::Statistic prevStats;
206 m_ImageData->saveStatistics(prevStats);
210 m_ImageData->restoreStatistics(stats);
219 m_ImageData->applyFilter(FITS_ROTATE_CCW);
221 case FITS_ROTATE_CCW:
222 m_ImageData->applyFilter(FITS_ROTATE_CW);
224 case FITS_MOUNT_FLIP_H:
225 case FITS_MOUNT_FLIP_V:
226 m_ImageData->applyFilter(type);
248QString FITSHistogramCommand::text()
const
253 return i18n(
"Auto Scale");
255 return i18n(
"Linear Scale");
257 return i18n(
"Logarithmic Scale");
259 return i18n(
"Square Root Scale");
262 if (type - 1 <= FITSViewer::filterTypes.count())
263 return FITSViewer::filterTypes[type - 1].toString();
267 return i18n(
"Unknown");
QString i18n(const char *text, const TYPE &arg...)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
void restoreOverrideCursor()
void setOverrideCursor(const QCursor &cursor)