Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fe3e5f66be | |||
| 6fd17fbdf5 | |||
| f30dd2a520 | |||
| 21675d9479 | |||
| f669baa8a6 | |||
| c317012c99 | |||
| d0dbef20c7 | |||
| bd45900821 | |||
| 96a89bff92 | |||
| c05fc36ee3 | |||
| 05b0aa9a2f | |||
| 7b70b6cce5 | |||
| 5150ec5639 | |||
| 79529552d9 | |||
| c872c72bb5 | |||
| 58abf762c0 | |||
| e47c99fd21 | |||
| 24ddf1dc61 | |||
| 8f333191c3 | |||
| e4cb99657e | |||
| d644e8095d | |||
| 1796e128ad | |||
| 37fdac39dc | |||
| 13e1abf07e | |||
| 617abf7afe | |||
| d59ee7fddc | |||
| d545c6ca0f | |||
| 5249b277ec | |||
| e4b9fefa5a | |||
| d069ce3302 | |||
| 58c182adc0 | |||
| c36068aaf4 | |||
| fcb3aec81f | |||
| 7510dac82b | |||
| 55439be04c |
+10
-4
@@ -18,8 +18,6 @@ if(SANITIZE_ADDRESS_LEAK)
|
||||
endif(SANITIZE_ADDRESS_LEAK)
|
||||
|
||||
find_package(Qt6 COMPONENTS Widgets Sql OpenGLWidgets Qml REQUIRED)
|
||||
find_library(GSL_LIB gsl REQUIRED)
|
||||
find_library(GSLCBLAS_LIB gslcblas REQUIRED)
|
||||
find_library(EXIF_LIB exif REQUIRED)
|
||||
find_library(FITS_LIB cfitsio REQUIRED)
|
||||
find_library(RAW_LIB NAMES raw_r REQUIRED)
|
||||
@@ -39,21 +37,25 @@ set(TENMON_SRC
|
||||
histogram.cpp histogram.h
|
||||
httpdownloader.h httpdownloader.cpp
|
||||
imageinfo.cpp imageinfo.h
|
||||
imageinfodata.cpp imageinfodata.h
|
||||
imageringlist.cpp imageringlist.h
|
||||
imagescrollarea.cpp imagescrollarea.h
|
||||
imagewidget.h imagewidget.cpp
|
||||
loadimage.h loadimage.cpp
|
||||
loadrunable.cpp loadrunable.h
|
||||
main.cpp
|
||||
mainwindow.cpp mainwindow.h
|
||||
markedfiles.cpp markedfiles.h
|
||||
mtfparam.h
|
||||
rawimage.cpp rawimage.h
|
||||
rawimage_sse.cpp
|
||||
scriptengine.cpp scriptengine.h
|
||||
settingsdialog.cpp settingsdialog.h
|
||||
starfit.cpp starfit.h
|
||||
statusbar.cpp statusbar.h
|
||||
stfslider.cpp stfslider.h
|
||||
stretchtoolbar.cpp stretchtoolbar.h
|
||||
tfloat16.h
|
||||
thumbnailer/genthumbnail.cpp thumbnailer/genthumbnail.h
|
||||
)
|
||||
|
||||
qt_add_resources(TENMON_SRC resources/resources.qrc)
|
||||
@@ -85,6 +87,8 @@ find_path(STELLARSOLVER_INCLUDE stellarsolver.h PATH_SUFFIXES libstellarsolver)
|
||||
if(STELLARSOLVER_INCLUDE AND STELLARSOLVER_LIB)
|
||||
target_include_directories(tenmon PRIVATE ${STELLARSOLVER_INCLUDE})
|
||||
if(MXE)
|
||||
find_library(GSL_LIB gsl REQUIRED)
|
||||
find_library(GSLCBLAS_LIB gslcblas REQUIRED)
|
||||
target_link_libraries(tenmon PRIVATE ${STELLARSOLVER_LIB} ${GSL_LIB} ${GSLCBLAS_LIB} boost_regex-mt-x64)
|
||||
else(MXE)
|
||||
target_link_libraries(tenmon PRIVATE ${STELLARSOLVER_LIB})
|
||||
@@ -98,7 +102,7 @@ if(STELLARSOLVER_INCLUDE AND STELLARSOLVER_LIB)
|
||||
message(STATUS "Found stellarsolver ${STELLARSOLVER_INCLUDE} ${STELLARSOLVER_LIB}")
|
||||
endif(STELLARSOLVER_INCLUDE AND STELLARSOLVER_LIB)
|
||||
|
||||
target_link_libraries(tenmon PRIVATE Qt6::Widgets Qt6::Sql Qt6::OpenGLWidgets Qt6::Qml ${GSL_LIB} ${GSLCBLAS_LIB} ${EXIF_LIB} ${FITS_LIB} ${RAW_LIB} ${WCS_LIB} ${LCMS2_LIB} XISF)
|
||||
target_link_libraries(tenmon PRIVATE Qt6::Widgets Qt6::Sql Qt6::OpenGLWidgets Qt6::Qml ${EXIF_LIB} ${FITS_LIB} ${RAW_LIB} ${WCS_LIB} ${LCMS2_LIB} XISF)
|
||||
if(APPLE)
|
||||
target_link_libraries(tenmon PRIVATE Qt6::DBus "-framework CoreFoundation")
|
||||
elseif(UNIX)
|
||||
@@ -138,3 +142,5 @@ else()
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -Dlocal_dir=${CMAKE_CURRENT_SOURCE_DIR} -Doutput_dir=${CMAKE_CURRENT_BINARY_DIR}
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/gitversion.cmake")
|
||||
endif()
|
||||
|
||||
add_subdirectory(thumbnailer)
|
||||
|
||||
@@ -2,11 +2,11 @@ FITS/XISF image viewer with multithreaded image loading
|
||||
|
||||
To get all dependencies install these packages
|
||||
|
||||
sudo apt install qt6-base-dev qt6-declarative-dev libqt6opengl6-dev libraw-dev libexif-dev libcfitsio-dev libgsl-dev wcslib-dev cmake libzstd-dev libqt6sql6-sqlite
|
||||
sudo apt install qt6-base-dev qt6-declarative-dev libqt6opengl6-dev libraw-dev libexif-dev libcfitsio-dev wcslib-dev cmake libzstd-dev libqt6sql6-sqlite
|
||||
|
||||
on OpenSUSE
|
||||
|
||||
sudo zypper install gsl-devel libexif-devel libraw-devel wcslib-devel qt6-base-devel qt6-qml-devel libzstd-devel
|
||||
sudo zypper install libexif-devel libraw-devel wcslib-devel qt6-base-devel qt6-qml-devel libzstd-devel
|
||||
|
||||
MacOS X
|
||||
|
||||
|
||||
@@ -31,20 +31,16 @@ About::About(QWidget *parent) : QDialog(parent)
|
||||
HelpDialog::HelpDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setWindowTitle(tr("Help"));
|
||||
resize(800, 600);
|
||||
|
||||
QLocale locale;
|
||||
QString l = QLocale::languageToString(locale.language());
|
||||
resize(1000, 600);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
QTextEdit *helpText = new QTextEdit(this);
|
||||
helpText->setReadOnly(true);
|
||||
layout->addWidget(helpText);
|
||||
|
||||
QFile tenmonText(":/help");
|
||||
tenmonText.open(QIODevice::ReadOnly);
|
||||
helpText->setHtml(tenmonText.readAll());
|
||||
|
||||
layout->addWidget(helpText);
|
||||
}
|
||||
|
||||
QString getVersion()
|
||||
|
||||
+51
-32
@@ -1,5 +1,7 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Help</title>
|
||||
<style type="text/css">
|
||||
h1, h2, h3, h4 { padding:0px; margin:10px; }
|
||||
p { padding:0px; margin:5px; }
|
||||
@@ -9,14 +11,13 @@ img { margin: 5px; }
|
||||
<body>
|
||||
<h2>Tenmon help</h2>
|
||||
|
||||
<p>Tenmon is intended primarily for viewing astro photos and images. It supports the following formats:
|
||||
<p>Tenmon is intended primarily for viewing astro photos and images. It supports the following formats:</p>
|
||||
<ul>
|
||||
<li>FITS 8, 16, 32 bit integer and 32, 64 bit float</li>
|
||||
<li>XISF 8, 16, 32 bit integer and 32, 64 bit float</li>
|
||||
<li>JPEG, PNG, BMP, GIF, PBM, PGM, PPM and SVG images</li>
|
||||
<li>CR2, CR3, NEF, DNG raw images</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<h3>Main windows</h3>
|
||||
<p>The main window shows the currently loaded image. On the left is the <i>Image info</i> panel which displays details about the loaded image.
|
||||
@@ -35,26 +36,32 @@ In the case of saving JPEG or PNG, the stretch function is applied to the saved
|
||||
To open an image, you can also drag and drop it to main window.</p>
|
||||
|
||||
<h3>View</h3>
|
||||
<p>The <i>View</i> menu has options to control the size and scale of displayed images:
|
||||
<p>The <i>View</i> menu has options to control the size and scale of displayed images:</p>
|
||||
<ul>
|
||||
<li><i>Zoom In</i> and <i>Zoom Out</i> magnify and shrink the image. The mouse wheel can be also used to zoom freely.</li>
|
||||
<li><i>Best fit</i> auto-zooms the image to fit the current size of the window.</li>
|
||||
<li><i>100%</i> will zoom to 1:1 scale.</li>
|
||||
<li><i>Bayer mask</i> set which bayer mask should be used when doing demosaicing.</li>
|
||||
<li><i>Colormap</i> select color pallette when showing image with false colours.</li>
|
||||
<li><i>Fullscreen</i> enlarges the main window to the whole screen.</li>
|
||||
<li><i>Thumbnails</i> will display small thumbnails for all images in the current directory.</li>
|
||||
<li><i>Slideshow</i> start showing all images periodically with interval that can be set in settings.</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>Colormap can also be user defined. Place image file named colormap.png into application data directory.
|
||||
On Windows"C:/Users/<USER>/AppData/Roaming/nou/Tenmon" Linux: "~/.local/share/nou/Tenmon/" MacOS: "~/Library/Application Support/nou/Tenmon/"
|
||||
This image should be 256 pixel wide. Each row of image will be used as separate color map and added to Colormap menu.</p>
|
||||
|
||||
|
||||
<h3>Stretch toolbar</h3>
|
||||
<p>This panel changes how images are displayed.
|
||||
<br><img src=":/about/stretch-panel.png"></p>
|
||||
<p>Starting on the left, there is slider scale with three adjustable points to manually control the stretch.
|
||||
<br><img src=":/about/stretch-panel.png" alt="Stretch panel"></p>
|
||||
<p>Starting on the left, there is slider scale with three adjustable points to manually control the stretch.</p>
|
||||
<ul>
|
||||
<li>black point - all pixels with lower value (darker) than this setting will be clipped black</li>
|
||||
<li>mid point - defines the value to be stretched to 50% intensity</li>
|
||||
<li>white point - all pixels with higher value (brighter) than this will be clipped white</li>
|
||||
</ul>
|
||||
Following the slider are 7 buttons for automatic stretching:
|
||||
<p>Following the slider are 7 buttons for automatic stretching:</p>
|
||||
<ul>
|
||||
<li><i>Linked channels</i> toggle stretching each RGB channel individually.</li>
|
||||
<li><i>Auto Stretch</i> automatically apply black and mid points to render the image with optimal brightness.</li>
|
||||
@@ -62,7 +69,7 @@ Following the slider are 7 buttons for automatic stretching:
|
||||
<li><i>Invert</i> invert colors to display the image as negative.</li>
|
||||
<li><i>False colors</i> show black and white in false colour palette.</li>
|
||||
<li><i>Debayer CFA</i> Demosaicing black and white image from CFA sensor to color one.</li>
|
||||
<li><i>Apply Auto stretch on load</i> toggle automatically applying Autostretch for each image when loaded.</p>
|
||||
<li><i>Apply Auto stretch on load</i> toggle automatically applying Autostretch for each image when loaded.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Marking images</h3>
|
||||
@@ -77,13 +84,12 @@ mouse button and drag across thumbnails to mark them. Holding <i>Ctrl</i> will u
|
||||
<h3>File system and tree</h3>
|
||||
<p>File system panel contain list of images in current opened directory. You can select file from this list and it will be displayed. It is also possible to
|
||||
use arrow keys to go back (left and up) and forth (right and down) between images.</p>
|
||||
<p>File tree show file system structure. You can right click to show context menu to perform various actions from <i>File</i> menu. There are also few others
|
||||
<p>File tree show file system structure. You can right click to show context menu to perform various actions from <i>File</i> menu. There are also few others</p>
|
||||
<ul>
|
||||
<li><i>Set as root directory</i> show only this directory and subdirectories</li>
|
||||
<li><i>Reset root directory</i> show whole file system</li>
|
||||
<li><i>Go up</i> show directory that is one level above current root directory</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<h3>Database of FITS/XISF files</h3>
|
||||
<p>Tenmon can scan a directory of FITS/XISF files and index metadata from FITS headers into it's internal database. This allows searching and sorting images based on that metadata.</p>
|
||||
@@ -105,14 +111,13 @@ Setting both "RA pos" and "DEC pos" can return images that doesn't contain enter
|
||||
"RA range" and "DEC range" filter out images which center coordinate is within entered range.
|
||||
Pressing Enter or clicking on <i>Filter</i> button will filter out database record according to search parameter.
|
||||
|
||||
<p>Wildcards:
|
||||
<p>Wildcards:</p>
|
||||
<ul>
|
||||
<li><b>%</b> (percent) is a wildcard representing zero or more of any characters.</li>
|
||||
<li><b>_</b> (underscore) is a wildcard for exactly one of any character.</i>
|
||||
<li><b>_</b> (underscore) is a wildcard for exactly one of any character.</li>
|
||||
<li>Without wildcard characters, the exact string must match.</li>
|
||||
</ul>
|
||||
</p>
|
||||
<br><img src=":/about/filter.png"><br>
|
||||
<p><img src=":/about/filter.png" alt="Filter"><br>
|
||||
This example filters for files where: "Bias" is in the file name, the OBJECT property is "M_42" (where the underscore can be any single character), and the DATE property begins with "2022".
|
||||
</p>
|
||||
|
||||
@@ -136,10 +141,9 @@ programs like KStars for astrometry.net index files.
|
||||
</p>
|
||||
|
||||
<h3>Batch processing</h3>
|
||||
|
||||
This module allow to write scripts in JavaScript that process image files. Batch Processing window consist from three main parts. On top is list of input files and directories.
|
||||
<p>This module allow to write scripts in JavaScript that process image files. Batch Processing window consist from three main parts. On top is list of input files and directories.
|
||||
You can add directories or individual files to this list. Directories are scanned recursively to find all files even non image files. This list of files is then passed to script in array named <b>files</b>.
|
||||
In script you can then iterate through files like this.
|
||||
In script you can then iterate through files like this.</p>
|
||||
<pre>for(file of files)
|
||||
{
|
||||
if(file.suffix() == "fits")
|
||||
@@ -153,12 +157,12 @@ In script you can then iterate through files like this.
|
||||
this output directory is ignored.</p>
|
||||
|
||||
<p>Bellow that is list of scripts. These scripts are located in application data directory. Select script which you want to run by clicking on it. Clicking on <i>Open scripts</i> will open directory with these scripts where you create new and edit them.
|
||||
Location of this directory is on Windows: "C:/Users/<USER>/AppData/Roaming/nou/Tenmon" Linux: "~/.local/share/nou/Tenmon/scripts" MacOS: "~/Library/Application Support/nou/Tenmon/scripts"</p>
|
||||
Location of this directory is on Windows: "C:/Users/<USER>/AppData/Roaming/nou/Tenmon/scripts" Linux: "~/.local/share/nou/Tenmon/scripts" MacOS: "~/Library/Application Support/nou/Tenmon/scripts"</p>
|
||||
|
||||
<p>Next is Log windows that contain any messages that come from scripts. Mainly calls to <code>core.log()</code> At bottom there buttons that can start or stop execution of selected scripts.</p>
|
||||
|
||||
<h4>core</h4>
|
||||
There is global object called <b>core</b> that have these methods.
|
||||
<p>There is global object called <b>core</b> that have these methods.</p>
|
||||
<ul>
|
||||
<li><b>log(message)</b> print message to log window.</li>
|
||||
<li><b>mark(file)</b> mark file same way as in GUI. Takes object of type <i>File</i> as argument.</li>
|
||||
@@ -175,10 +179,15 @@ There is global object called <b>core</b> that have these methods.
|
||||
<li><b>getItem(items)</b> show selection dialog which allow to select one item from array of items. It return selected item as string. When cancel is pressed it return Undefined.</li>
|
||||
<li><b>setStartingSolution(solution)</b> with this you can set starting point and image scale. It accepth object with attributes "ra", "dec", "pixscale".
|
||||
Same object as returned by <i>File.solve()</i> method. You can also call it without paramer in which case it will clear any previously set values.</li>
|
||||
<li><b>getSolverProfile()</b> return solver profile as Object.
|
||||
<pre>var profile = core.getSolverProfile();
|
||||
core.log(JSON.stringify(profile));</pre></li>
|
||||
<li><b>setSolverProfile(index)</b> set solver profile by index. Valid values are from 1 to 8 as in GUI.</li>
|
||||
<li><b>setSolverProfile(profile)</b> set solver profile. Parameter is same as object returned by <i>getSolverProfile()</i> method</li>
|
||||
</ul>
|
||||
|
||||
<h4>File</h4>
|
||||
In <b>files</b> array there are instances of type <b>File</b> objects that have these methods.
|
||||
<p>In <b>files</b> array there are instances of type <b>File</b> objects that have these methods.</p>
|
||||
<ul>
|
||||
<li><b>fileName()</b> returns the name of the file, excluding the path.</li>
|
||||
<li><b>absoluteFilePath()</b> returns an absolute path including the file name.</li>
|
||||
@@ -196,23 +205,33 @@ In <b>files</b> array there are instances of type <b>File</b> objects that have
|
||||
<li><b>fitsRecords()</b> return array of objects with properties <b>key, value</b> and <b>comment</b> </li>
|
||||
<li><b>modifyFITSRecords(FITSRecordModify)</b> modify FITS header by adding, removing or updating FITS record. Return true on success. Refer to <i>FITSRecordModify</i></li>
|
||||
<li><b>isMarked()</b> return true if file is marked.</li>
|
||||
<li><b>copy(newpath)</b> copy file to new location. It return instance of new <i>File<i> object that represent this copied file. This path can be relative or absolute. In case that <i>newpath</i> parameter is relative
|
||||
<li><b>copy(newpath)</b> copy file to new location. It return instance of new <i>File</i> object that represent this copied file. This path can be relative or absolute. In case that <i>newpath</i> parameter is relative
|
||||
path then it "Output directory" from GUI windows is used as base directory. Parameter <i>newpath</i> can absolute path. File is then copied to this path. In case that copy fail it return null.</li>
|
||||
<li><b>move(newpath)</b> move file to new location. It return false if move failed. This can happend if destination is not writable but also if destination file already exist. This functions does not overwrite existing file.
|
||||
This path can be relative or absolute. In case that <i>newpath</i> parameter is relative path then it "Output directory" from GUI windows is used as base directory. Parameter <i>newpath</i> can be absolute path.
|
||||
File is then moved to this path.</li>
|
||||
<li><b>convert(outpath, format, params)</b> convert image file from any format that program is able to open into FITS, XISF, JPEG, PNG, BMP.
|
||||
Parameters are: <i>outputpath</i> path where converted image will be saved. It automatically replace suffix according to format. <i>format</i> one of "FITS" "XISF", "JPG", "PNG", "TIFF" or "BMP". <i>params</i> object with attributes "compressionType" and "compressionLevel".
|
||||
Valid values for compressionType are be "gzip" or "rice" when converting to FITS. When converting to XISF compressionType can be "zlib", "lz4", "lz4hc", "zstd", "zlib+sh", "lz4+sh", "lz4hc+sh", "zstd+sh".
|
||||
It is recommended to use "+sh" variants of compression.
|
||||
XISF format also accept "compressionLevel" in range 0-100 where zero is fastest compression and 100 slowest. If you omit this attribute or set it to -1 then default compression level will be used.
|
||||
It return new instance of <i>File</i> that point to converted file.
|
||||
Parameters are: <i>outputpath</i> path where converted image will be saved. It automatically replace suffix according to format. This method return new instance of <i>File</i> that point to converted file.
|
||||
<i>format</i> one of "FITS" "XISF", "JPG", "PNG", "TIFF" or "BMP".
|
||||
<i>params</i> object with attributes
|
||||
<ul>
|
||||
<li>"compressionLevel" used with XISF format. integer value between 0-100 determining speed and compression ratio.</li>
|
||||
<li>"compressionType" for FITS format it can be "gzip" and "rice". For XISF it can be "zlib", "lz4", "lz4hc", "zstd", "zlib+sh", "lz4+sh", "lz4hc+sh", "zstd+sh"</li>
|
||||
<li>"binning" any integer value above 1 will perform integer downsample</li>
|
||||
<li>"average" by default set to true. If you set to false it will sum pixel values instead of averaging when performing binning.</li>
|
||||
<li>"resize" downsample image to defined width and height by subobject <code>"resize":{"width": 128, "height": 128, "aspect":"keep"}</code>
|
||||
"aspect" determine how to handle aspect ration when resizing image. "keep" and "expand" preserve original aspect ratio. Difference is that "keep" resulting image will be at most requested size
|
||||
"epand" resulting size will be at least requested size. For example input image 800x600 pixels and resizing to 128x128. With keep resulting image will be 128x96 while with epxand it will be 170x128.
|
||||
If set to "ignore" then resulting image will be exact size 128x128 ignoring original aspect ratio. By default keep is used.</li>
|
||||
<li>"autostretch" when set to true it apply automatic stretch function to pixel values. By default it is set to false.</li>
|
||||
</ul>
|
||||
In case that both binning and resizing is set binning is performed first then resing.
|
||||
<pre>file.convert("converted_file.xisf", "xisf", {"compressionType": "zstd+sh", "compressionLevel": 70});
|
||||
file.convert("converted_file.fits", "fits", {"compressionType": "rice"});
|
||||
file.convert("converted_file.jpg", "png");</pre>
|
||||
</li>
|
||||
<li><b>convertAsync(outpath, format, params)</b> same as previous method but it does conversion in separated thread asynchronously and in parallel. Before calling any method on object returned by this method you must call
|
||||
<code>core.sync();</code> to ensure that conversion is done and destination file exists.
|
||||
file.convert("converted_file.jpg", "png");
|
||||
file.convert("thumbnail.jpg", "jpg", {"binning": 2, "average": true, "resize": {"width":256, "height": 256, "aspect":"ignore"}, "autostretch": true});</pre></li>
|
||||
<li><b>convertAsync(outpath, format, params)</b> same as previous method but it does conversion in separated thread asynchronously and in parallel.
|
||||
Before calling any method on object returned by this method you must call <code>core.sync();</code> to ensure that conversion is done and destination file exists.
|
||||
<pre>let compression = {"compressionType": "zstd+sh"};
|
||||
let convertedFiles = [];
|
||||
for(file in files)
|
||||
@@ -239,8 +258,8 @@ core.log("Median value is " + s.median);</pre></li>
|
||||
</ul>
|
||||
|
||||
<h4>FITSRecordModify</h4>
|
||||
This class is used to define modify operation FITS header in FITS and XISF files. It can remove update and add records. Order of operation is also remove then update and last add.
|
||||
The keyword names may be up to 8 characters long and can only contain uppercase letters, the digits 0-9, the hyphen, and the underscore character.
|
||||
<p>This class is used to define modify operation FITS header in FITS and XISF files. It can remove update and add records. Order of operation is also remove then update and last add.
|
||||
The keyword names may be up to 8 characters long and can only contain uppercase letters, the digits 0-9, the hyphen, and the underscore character.</p>
|
||||
<pre>let modify = new FITSRecordModify();
|
||||
modify.updateKeyword("OBJECT", "M42");
|
||||
modify.updateKeyword("MYTILE", "PART1", "adding custom keyword so WBPP can group it");
|
||||
|
||||
+8
-6
@@ -1,5 +1,7 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Pomocník</title>
|
||||
<style type="text/css">
|
||||
h1, h2, h3, h4 { padding:0px; margin:10px; }
|
||||
p { padding:0px; margin:5px 5px 10px 5px; }
|
||||
@@ -8,21 +10,21 @@ p { padding:0px; margin:5px 5px 10px 5px; }
|
||||
<body>
|
||||
<h2>Tenmon pomocník</h2>
|
||||
|
||||
<p>Tenmon slúži primárne na zobrazenie astronomických fotiek a obrázkov. Dokáže otvoriť nasledovné formáty:
|
||||
<p>Tenmon slúži primárne na zobrazenie astronomických fotiek a obrázkov. Dokáže otvoriť nasledovné formáty:</p>
|
||||
<ul>
|
||||
<li>FITS 8, 16, 32 bitové celočíselné 32 a 64 bitové s plávajúcou čiarkou</li>
|
||||
<li>XISF 8, 16, 32 bitové celočíselné 32 a 64 bitové s plávajúcou čiarkou</li>
|
||||
<li>JPEG, PNG, BMP, GIF, PBM, PGM, PPM a SVG obrázky</li>
|
||||
<li>CR2, CR3, NEF, DNG raw obrázky</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<h3>Hlavné okno</h3>
|
||||
<p>V hlavnom okne sa zobrazujú načítané obrázky. Naľavo sú potom <i>Informácie o obrázku</i> kde sa zobrazujú podrobné
|
||||
informácie o aktuálnom obrázku a <i>Zoznam súborov</i> kde sú všetky obrázky z adresára kde je aktuálne zobrazený obrázok.
|
||||
Hore je hlavné menu a pod ním je <i>Panel úrovní</i>. Všetky panely sa dajú zavrieť a presúvať. Zatvorený panel sa dá znova
|
||||
zobraziť v menu <i>Dokovacie panely</i>.
|
||||
</p>
|
||||
zobraziť v menu <i>Dokovacie panely</i>.</p>
|
||||
<p>Na spodnom okraji okna je lišta v ktorej sa ukazuje aktuálna hodnota pixelu pod kurzorom a ak má obrázok WCS dátá aj aktuálne
|
||||
celestiálne koordináty.</p>
|
||||
|
||||
<h3>Otváranie a ukladanie obrázkov</h3>
|
||||
<p>Otvoriť obrázok je možné v menu <i>Súbor->Otvoriť</i>. Po vybraní súboru ktorý sa má otvoriť je
|
||||
@@ -43,13 +45,13 @@ hlavné okno na celú obrazovku. <i>Náhľady</i> zobrazí malé náhľady pre v
|
||||
<p>
|
||||
Tento panel umožňuje upraviť spôsob ako sa zobrazujú obrazové dáta. Ako prvá je na tomto panely posuvná škála
|
||||
na ktorej sa dajú nastaviť tri body.
|
||||
<br><br><img src=":/about/stretch-panel.png">
|
||||
<br><br><img src=":/about/stretch-panel.png"></p>
|
||||
<ul>
|
||||
<li>čierny bod - všetky pixeli s hodnotou menšou ako nastavená budú zobrazené ako čierne</li>
|
||||
<li>stredný bod - pixeli s touto hodnotou budú zobrazené ako 50% šedá</li>
|
||||
<li>biely bod - pixeli nad touto hodnotou budú zobrazené ako biele</li>
|
||||
</ul>
|
||||
Prvé tlačidlo prepína prepojenie nastavenia čierneho, stretdného a bieleho bodu. Po prepnutí sa dá každý farebný kanál nastaviť
|
||||
<p>Prvé tlačidlo prepína prepojenie nastavenia čierneho, stretdného a bieleho bodu. Po prepnutí sa dá každý farebný kanál nastaviť
|
||||
samostatne.
|
||||
Nasleduje tlačidlo ktoré nastaví hodnoty čierneho a stredného bodu tak aby bol obrázok zobrazený optimálnym jasom.
|
||||
Druhé tlačidlo resetuje hodnoty pre čierny, stredný a biely bod na východzie hodnoty. Invertovanie farieb zobrazí obrázok ako negatív.
|
||||
|
||||
+3
-2
@@ -67,7 +67,8 @@ void BatchProcessing::scanScriptDir()
|
||||
if(idx>=0)_ui->scriptsList->setCurrentRow(idx);
|
||||
}
|
||||
|
||||
BatchProcessing::BatchProcessing(QWidget *parent) : QDialog(parent)
|
||||
BatchProcessing::BatchProcessing(Database *database, QWidget *parent) : QDialog(parent)
|
||||
, _database(database)
|
||||
{
|
||||
_ui = new Ui::BatchProcessing;
|
||||
_ui->setupUi(this);
|
||||
@@ -200,7 +201,7 @@ void BatchProcessing::runScript()
|
||||
auto selectedItems = _ui->scriptsList->selectedItems();
|
||||
if(selectedItems.size())
|
||||
{
|
||||
_engineThread = new Script::ScriptEngineThread(this);
|
||||
_engineThread = new Script::ScriptEngineThread(_database, this);
|
||||
connect(_engineThread, &Script::ScriptEngineThread::newMessage, this, &BatchProcessing::newMessage);
|
||||
connect(_engineThread, &Script::ScriptEngineThread::finished, this, &BatchProcessing::scriptFinished);
|
||||
QStringList paths;
|
||||
|
||||
+4
-1
@@ -7,6 +7,8 @@
|
||||
|
||||
namespace Ui { class BatchProcessing; }
|
||||
|
||||
class Database;
|
||||
|
||||
class BatchProcessing : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -15,10 +17,11 @@ class BatchProcessing : public QDialog
|
||||
QFileSystemWatcher _fileWatcher;
|
||||
Script::ScriptEngineThread *_engineThread = nullptr;
|
||||
QColor _textColor;
|
||||
Database *_database;
|
||||
private slots:
|
||||
void scanScriptDir();
|
||||
public:
|
||||
explicit BatchProcessing(QWidget *parent = nullptr);
|
||||
explicit BatchProcessing(Database *database, QWidget *parent = nullptr);
|
||||
~BatchProcessing();
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
+13
-6
@@ -4,7 +4,7 @@
|
||||
#include <QSqlError>
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
#include "loadrunable.h"
|
||||
#include "loadimage.h"
|
||||
|
||||
Database::Database(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@@ -15,7 +15,7 @@ bool Database::init(const QLatin1String &connectionName)
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
QDir dir(path);
|
||||
|
||||
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE", connectionName);
|
||||
database = QSqlDatabase::addDatabase("QSQLITE", connectionName);
|
||||
|
||||
if(!dir.mkpath("."))
|
||||
return false;
|
||||
@@ -27,7 +27,7 @@ bool Database::init(const QLatin1String &connectionName)
|
||||
{
|
||||
QSqlQuery query(database);
|
||||
query.exec("PRAGMA foreign_keys = ON");
|
||||
int version = checkVersion();
|
||||
int version = checkVersion(database);
|
||||
if(version == 0)
|
||||
{
|
||||
query.exec("PRAGMA user_version = 1");
|
||||
@@ -76,6 +76,14 @@ bool Database::init(const QLatin1String &connectionName)
|
||||
}
|
||||
qDebug() << error.text();
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed to open database" << connectionName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Database is invalid";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -146,10 +154,9 @@ bool Database::checkError(QSqlQuery &query)
|
||||
}
|
||||
}
|
||||
|
||||
int Database::checkVersion()
|
||||
int Database::checkVersion(QSqlDatabase &db)
|
||||
{
|
||||
QSqlDatabase db = QSqlDatabase::database();
|
||||
QSqlQuery query("PRAGMA user_version");
|
||||
QSqlQuery query("PRAGMA user_version", db);
|
||||
if(query.next())
|
||||
return query.value(0).toInt();
|
||||
return -1;
|
||||
|
||||
+2
-1
@@ -10,6 +10,7 @@
|
||||
class Database : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
QSqlDatabase database;
|
||||
QSqlQuery m_markQuery;
|
||||
QSqlQuery m_unmarkQuery;
|
||||
QSqlQuery m_isMarkedQuery;
|
||||
@@ -40,7 +41,7 @@ protected:
|
||||
bool indexDir2(const QDir &dir, QProgressDialog *progress, QStringList &scannedDirs);
|
||||
bool indexFile(const QFileInfo &file);
|
||||
bool checkError(QSqlQuery &query);
|
||||
int checkVersion();
|
||||
int checkVersion(QSqlDatabase &db);
|
||||
signals:
|
||||
void databaseChanged();
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <algorithm>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QStyleOption>
|
||||
|
||||
Histogram::Histogram(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
|
||||
-402
@@ -1,55 +1,6 @@
|
||||
#include "imageinfo.h"
|
||||
#include <QSettings>
|
||||
#include <QTime>
|
||||
#include <QHeaderView>
|
||||
#include <wcslib/wcshdr.h>
|
||||
#include <wcslib/wcsfix.h>
|
||||
#include <libxisf.h>
|
||||
|
||||
static const QVector<QByteArray> noEditableKey = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"};
|
||||
|
||||
bool FITSRecord::editable() const
|
||||
{
|
||||
return noEditableKey.count(key);
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment) :
|
||||
key(key), value(value), comment(comment)
|
||||
{
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const LibXISF::FITSKeyword &record)
|
||||
{
|
||||
key = record.name.c_str();
|
||||
comment = record.comment.c_str();
|
||||
|
||||
QString string = record.value.c_str();
|
||||
if(string.startsWith('\'') && string.endsWith('\''))
|
||||
{
|
||||
string.chop(1);
|
||||
string.remove(0, 1);
|
||||
}
|
||||
bool isint;
|
||||
bool isdouble;
|
||||
double vald = string.toDouble(&isdouble);
|
||||
long long vall = string.toLongLong(&isint);
|
||||
if(isint)
|
||||
value = vall;
|
||||
else if(isdouble)
|
||||
value = vald;
|
||||
else if(string == "T" || string == "F")
|
||||
value = string == "T";
|
||||
else
|
||||
value = string;
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const LibXISF::Property &property)
|
||||
{
|
||||
key = property.id.c_str();
|
||||
value = QString::fromStdString(property.value.toString());
|
||||
comment = property.comment.c_str();
|
||||
xisf = true;
|
||||
}
|
||||
|
||||
ImageInfo::ImageInfo(QWidget *parent) : QTreeWidget(parent)
|
||||
{
|
||||
@@ -89,356 +40,3 @@ void ImageInfo::setInfo(const ImageInfoData &info)
|
||||
}
|
||||
expandAll();
|
||||
}
|
||||
|
||||
void WCSDataT::freeWCS()
|
||||
{
|
||||
wcsvfree(&nwcs, &wcs);
|
||||
nwcs = 0;
|
||||
wcs = nullptr;
|
||||
}
|
||||
|
||||
WCSDataT::WCSDataT(int width, int height, char *header, int nrec) :
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
int nreject = 0;
|
||||
int status = wcspih(header, nrec, 1, 0, &nreject, &nwcs, &wcs);
|
||||
if(status != 0)
|
||||
{
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
WCSDataT::WCSDataT(int width, int height, const QVector<FITSRecord> &header) :
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
QByteArray str;
|
||||
int nrec = 1;
|
||||
for(const FITSRecord &record : header)
|
||||
{
|
||||
if(record.key.startsWith("PV"))continue;
|
||||
|
||||
QByteArray rec;
|
||||
rec.append(record.key.leftJustified(8, ' '));
|
||||
rec.append("= ");
|
||||
rec.append(record.value.toString().toLatin1());
|
||||
rec.append(" / ");
|
||||
rec.append(record.comment);
|
||||
str.append(rec.leftJustified(80, ' ', true));
|
||||
nrec++;
|
||||
}
|
||||
str.append(QByteArray("END").leftJustified(80));
|
||||
|
||||
int nreject = 0;
|
||||
status = wcspih(str.data(), nrec, 1, 0, &nreject, &nwcs, &wcs);
|
||||
if(status != 0)
|
||||
{
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
WCSDataT::~WCSDataT()
|
||||
{
|
||||
if(wcs)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
bool WCSDataT::pixelToWorld(const QPointF &pixel, SkyPoint &point) const
|
||||
{
|
||||
if(!valid())return false;
|
||||
|
||||
double pixcrd[2] = {pixel.x(), pixel.y()};
|
||||
double imgcrd[8] = {0};
|
||||
double phi = 0;
|
||||
double theta = 0;
|
||||
double world[8] = {0};
|
||||
int stat[NWCSFIX] = {0};
|
||||
int status = wcsp2s(wcs, 1, 2, pixcrd, imgcrd, &phi, &theta, world, stat);
|
||||
if(status == 0)
|
||||
{
|
||||
point = SkyPoint(world[0], world[1]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WCSDataT::worldToPixel(const SkyPoint &point, QPointF &pixel) const
|
||||
{
|
||||
if(!valid())return false;
|
||||
|
||||
double world[2] = {point.RA(), point.DEC()};
|
||||
double phi = 0;
|
||||
double theta = 0;
|
||||
double imgcrd[8] = {0};
|
||||
double pixcrd[8] = {0};
|
||||
int stat[NWCSFIX] = {0};
|
||||
int status = wcss2p(wcs, 1, 2, world, &phi, &theta, imgcrd, pixcrd, stat);
|
||||
if(status == 0)
|
||||
{
|
||||
pixel = QPointF(pixcrd[0], pixcrd[1]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WCSDataT::calculateBounds(double &minRa, double &maxRa, double &minDec, double &maxDec, double &crVal1, double &crVal2) const
|
||||
{
|
||||
if(wcs == nullptr)return;
|
||||
|
||||
minRa = 1000;
|
||||
maxRa = -1000;
|
||||
minDec = 1000;
|
||||
maxDec = -1000;
|
||||
|
||||
if(wcs->crval)
|
||||
{
|
||||
crVal1 = wcs->crval[0];
|
||||
crVal2 = wcs->crval[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
crVal1 = crVal2 = NAN;
|
||||
}
|
||||
|
||||
auto update = [&](const QPointF &pixel)
|
||||
{
|
||||
SkyPoint point;
|
||||
pixelToWorld(pixel, point);
|
||||
minRa = std::min(minRa, point.RA());
|
||||
maxRa = std::max(maxRa, point.RA());
|
||||
minDec = std::min(minDec, point.DEC());
|
||||
maxDec = std::max(maxDec, point.DEC());
|
||||
};
|
||||
|
||||
for(int x=0; x<width; x++)
|
||||
{
|
||||
update(QPointF(x, 0));
|
||||
update(QPointF(x, height - 1));
|
||||
}
|
||||
|
||||
for(int y=0; y<height; y++)
|
||||
{
|
||||
update(QPointF(0, y));
|
||||
update(QPointF(width - 1, y));
|
||||
}
|
||||
|
||||
QPointF ncp;
|
||||
QPointF scp;
|
||||
QRectF s(0, 0, width - 1, height - 1);
|
||||
if(worldToPixel(SkyPoint(0, 90), ncp))
|
||||
{
|
||||
if(s.contains(ncp))
|
||||
maxDec = 90;
|
||||
}
|
||||
|
||||
if(worldToPixel(SkyPoint(0, -90), scp))
|
||||
{
|
||||
if(s.contains(scp))
|
||||
minDec = -90;
|
||||
}
|
||||
}
|
||||
|
||||
double hav(double x)
|
||||
{
|
||||
return (1.0 - std::cos(x)) * 0.5;
|
||||
}
|
||||
|
||||
double haverSine(const SkyPoint &a, SkyPoint &b)
|
||||
{
|
||||
const double ToRAD = M_PI / 180.0;
|
||||
double d = hav((a.DEC() - b.DEC()) * ToRAD) + std::cos(a.DEC() * ToRAD) * std::cos(b.DEC() * ToRAD) * hav((a.RA() - b.RA()) * ToRAD);
|
||||
return std::acos(1.0 - 2.0 * d) * (180.0 / M_PI);
|
||||
}
|
||||
|
||||
SkyPointScale WCSDataT::getRaDecScale() const
|
||||
{
|
||||
SkyPointScale ret;
|
||||
pixelToWorld(QPointF(width/2.0, height/2.0), ret.point);
|
||||
SkyPoint pointX;
|
||||
SkyPoint pointY;
|
||||
pixelToWorld(QPointF(width/2.0+1, height/2.0), pointX);
|
||||
pixelToWorld(QPointF(width/2.0, height/2.0+1), pointY);
|
||||
double scaleX = haverSine(ret.point, pointX) * 3600.0;
|
||||
double scaleY = haverSine(ret.point, pointY) * 3600.0;
|
||||
ret.scaleLow = std::min(scaleX, scaleY);
|
||||
ret.scaleHigh = std::max(scaleX, scaleY);
|
||||
ret.scaleValid = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint() : ra(NAN), dec(NAN)
|
||||
{
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint(double ra, double dec) : ra(ra), dec(dec)
|
||||
{
|
||||
}
|
||||
|
||||
void SkyPoint::set(double ra, double dec)
|
||||
{
|
||||
this->ra = ra;
|
||||
this->dec = dec;
|
||||
}
|
||||
|
||||
QString SkyPoint::toString() const
|
||||
{
|
||||
if(std::isnan(ra) || std::isnan(dec))
|
||||
return QString();
|
||||
|
||||
QTime t(0, 0);
|
||||
t = t.addSecs(ra * 240);
|
||||
|
||||
double deg, min, sec;
|
||||
min = std::abs(std::modf(dec, °) * 60);
|
||||
sec = std::modf(min, &min) * 60;
|
||||
return QString("RA: %1 DEC: %2° %3' %4\"").arg(t.toString("HH'h' mm'm' ss's'")).arg(deg, 2, 'f', 0, '0').arg(min, 2, 'f', 0, '0').arg(sec, 2, 'f', 0, '0');
|
||||
}
|
||||
|
||||
double SkyPoint::fromHMS(const QString &hms)
|
||||
{
|
||||
double deg = fromDMS(hms);
|
||||
if(std::isnan(deg))return deg;
|
||||
return deg * 15.0;
|
||||
}
|
||||
|
||||
double SkyPoint::fromDMS(const QString &dms)
|
||||
{
|
||||
double deg = 0.0;
|
||||
QString str = dms.trimmed();
|
||||
str.remove(QRegularExpression("[hdms°'\"]"));
|
||||
str.replace(':', ' ');
|
||||
str.replace(QRegularExpression("\\s+"), " ");
|
||||
QStringList fields = str.split(' ');
|
||||
double sign = 1.0;
|
||||
|
||||
bool ok = false;
|
||||
if(fields.size() >= 1)
|
||||
deg = fields.at(0).toDouble(&ok);
|
||||
if(!ok)return NAN;
|
||||
if(deg < 0.0)
|
||||
sign = -1.0;
|
||||
if(fields.size() >= 2)
|
||||
deg += sign * fields.at(1).toDouble() / 60.0;
|
||||
if(fields.size() >= 3)
|
||||
deg += sign * fields.at(2).toDouble() / 3600.0;
|
||||
|
||||
return deg;
|
||||
}
|
||||
|
||||
QString SkyPoint::toHMS(double decHour)
|
||||
{
|
||||
double h,m,s,md;
|
||||
md = std::modf(decHour, &h) * 60.0;
|
||||
s = std::modf(md, &m) * 60.0;
|
||||
|
||||
return QString("%1h %2m %3s").arg((int)h, 2, 10, QChar('0')).arg((int)m, 2, 10, QChar('0')).arg((int)s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
QString SkyPoint::toDMS(double deg)
|
||||
{
|
||||
double d,m,s,md;
|
||||
md = std::modf(deg, &d) * 60.0;
|
||||
s = std::modf(md, &m) * 60.0;
|
||||
|
||||
return QString("%1˚ %2' %3\"").arg((int)d, 2, 10, QChar('0')).arg((int)m, 2, 10, QChar('0')).arg((int)s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
SkyPointScale ImageInfoData::getCenterRaDec() const
|
||||
{
|
||||
SkyPointScale ret;
|
||||
if(wcs && wcs->valid())
|
||||
{
|
||||
ret = wcs->getRaDecScale();
|
||||
}
|
||||
else
|
||||
{
|
||||
double ra,dec,focalLen,scale,pixSizeX,pixSizeY;
|
||||
int binX = 1;
|
||||
int binY = 1;
|
||||
ra = dec = focalLen = scale = pixSizeX = pixSizeY = NAN;
|
||||
bool ok;
|
||||
for(const FITSRecord &header : fitsHeader)
|
||||
{
|
||||
if(header.key == "OBJCTRA")
|
||||
{
|
||||
double tmp = SkyPoint::fromHMS(header.value.toString());
|
||||
if(!std::isnan(tmp))ra = tmp;
|
||||
}
|
||||
else if(header.key == "RA" && std::isnan(ra))
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)ra = tmp;
|
||||
}
|
||||
else if(header.key == "OBJCTDEC")
|
||||
{
|
||||
double tmp = SkyPoint::fromDMS(header.value.toString());
|
||||
if(!std::isnan(tmp))dec = tmp;
|
||||
}
|
||||
else if(header.key == "DEC" && std::isnan(dec))
|
||||
{
|
||||
double tmp = SkyPoint::fromDMS(header.value.toString());
|
||||
if(!std::isnan(tmp))dec = tmp;
|
||||
}
|
||||
else if(header.key == "SCALE")
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)scale = tmp;
|
||||
}
|
||||
else if(header.key == "FOCALLEN")
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)focalLen = tmp;
|
||||
}
|
||||
else if(header.key == "PIXSIZE1" || header.key == "XPIXSZ")
|
||||
{
|
||||
pixSizeX = header.value.toDouble();
|
||||
}
|
||||
else if(header.key == "PIXSIZE2" || header.key == "YPIXSZ")
|
||||
{
|
||||
pixSizeY = header.value.toDouble();
|
||||
}
|
||||
else if(header.key == "XBINNING")
|
||||
{
|
||||
int tmp = header.value.toInt(&ok);
|
||||
if(ok)binX = tmp;
|
||||
}
|
||||
else if(header.key == "YBINNING")
|
||||
{
|
||||
int tmp = header.value.toInt(&ok);
|
||||
if(ok)binY = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
ret.point.set(ra, dec);
|
||||
if(!std::isnan(scale))
|
||||
{
|
||||
ret.scaleLow = ret.scaleHigh = scale;
|
||||
ret.scaleValid = true;
|
||||
}
|
||||
else if(!(std::isnan(focalLen) || std::isnan(pixSizeX) || std::isnan(pixSizeY)))
|
||||
{
|
||||
const double r = 206.2648097656; // (180 * 3600) / (1000 * pi) magic number to convert pixel size to focal length ratio to arcsec.
|
||||
ret.scaleLow = std::min(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r);
|
||||
ret.scaleHigh = std::max(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r);
|
||||
ret.scaleValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(ret.scaleValid)
|
||||
{
|
||||
ret.scaleLow *= 0.8;
|
||||
ret.scaleHigh *= 1.2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+1
-82
@@ -2,88 +2,7 @@
|
||||
#define IMAGEINFO_H
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include <wcslib/wcs.h>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
namespace LibXISF { struct FITSKeyword; struct Property; }
|
||||
|
||||
struct FITSRecord
|
||||
{
|
||||
QByteArray key;
|
||||
QVariant value;
|
||||
QByteArray comment;
|
||||
bool xisf = false;
|
||||
bool editable() const;
|
||||
FITSRecord(){}
|
||||
FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment);
|
||||
FITSRecord(const LibXISF::FITSKeyword &record);
|
||||
FITSRecord(const LibXISF::Property &property);
|
||||
};
|
||||
|
||||
class SkyPoint
|
||||
{
|
||||
double ra = NAN;
|
||||
double dec = NAN;
|
||||
public:
|
||||
SkyPoint();
|
||||
SkyPoint(double ra, double dec);
|
||||
void set(double ra, double dec);
|
||||
double RA() const { return ra; }
|
||||
double RAHour() const { return ra / 15.0; }
|
||||
double DEC() const { return dec; }
|
||||
QString toString() const;
|
||||
static double fromHMS(const QString &hms);
|
||||
static double fromDMS(const QString &dms);
|
||||
static QString toHMS(double decHour);
|
||||
static QString toDMS(double deg);
|
||||
};
|
||||
|
||||
struct SkyPointScale
|
||||
{
|
||||
SkyPoint point;
|
||||
//arcsec per pixel
|
||||
bool scaleValid = false;
|
||||
double scaleLow = 0.0;
|
||||
double scaleHigh = 10000.0;
|
||||
};
|
||||
|
||||
class WCSDataT
|
||||
{
|
||||
int nwcs = 0;
|
||||
struct wcsprm *wcs = nullptr;
|
||||
int width;
|
||||
int height;
|
||||
void freeWCS();
|
||||
public:
|
||||
WCSDataT(int width, int height, char *header, int nrec);
|
||||
WCSDataT(int width, int height, const QVector<FITSRecord> &header);
|
||||
WCSDataT(const WCSDataT &) = delete;
|
||||
~WCSDataT();
|
||||
bool pixelToWorld(const QPointF &pixel, SkyPoint &point) const;
|
||||
bool worldToPixel(const SkyPoint &point, QPointF &pixel) const;
|
||||
void calculateBounds(double &minRa, double &maxRa, double &minDec, double &maxDec, double &crVal1, double &crVal2) const;
|
||||
bool valid() const { return wcs; };
|
||||
SkyPointScale getRaDecScale() const;
|
||||
};
|
||||
|
||||
struct ImageInfoData
|
||||
{
|
||||
QVector<FITSRecord> fitsHeader;
|
||||
QVector<QPair<QString, QString>> info;
|
||||
std::shared_ptr<WCSDataT> wcs;
|
||||
SkyPointScale getCenterRaDec() const;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ImageInfoData);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
None,
|
||||
Statistics,
|
||||
Peaks,
|
||||
Stars,
|
||||
}AnalyzeLevel;
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class ImageInfo : public QTreeWidget
|
||||
{
|
||||
|
||||
@@ -0,0 +1,405 @@
|
||||
#include "imageinfodata.h"
|
||||
#include <QTime>
|
||||
#include <QRectF>
|
||||
#include <QRegularExpression>
|
||||
#include <wcslib/wcshdr.h>
|
||||
#include <wcslib/wcsfix.h>
|
||||
#include "libxisf.h"
|
||||
|
||||
static const QVector<QByteArray> noEditableKey = {"SIMPLE", "BITPIX", "NAXIS", "NAXIS1", "NAXIS2", "NAXIS3", "EXTEND", "BZERO", "BSCALE"};
|
||||
|
||||
bool FITSRecord::editable() const
|
||||
{
|
||||
return noEditableKey.count(key);
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment) :
|
||||
key(key), value(value), comment(comment)
|
||||
{
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const LibXISF::FITSKeyword &record)
|
||||
{
|
||||
key = record.name.c_str();
|
||||
comment = record.comment.c_str();
|
||||
|
||||
QString string = record.value.c_str();
|
||||
if(string.startsWith('\'') && string.endsWith('\''))
|
||||
{
|
||||
string.chop(1);
|
||||
string.remove(0, 1);
|
||||
}
|
||||
bool isint;
|
||||
bool isdouble;
|
||||
double vald = string.toDouble(&isdouble);
|
||||
long long vall = string.toLongLong(&isint);
|
||||
if(isint)
|
||||
value = vall;
|
||||
else if(isdouble)
|
||||
value = vald;
|
||||
else if(string == "T" || string == "F")
|
||||
value = string == "T";
|
||||
else
|
||||
value = string;
|
||||
}
|
||||
|
||||
FITSRecord::FITSRecord(const LibXISF::Property &property)
|
||||
{
|
||||
key = property.id.c_str();
|
||||
value = QString::fromStdString(property.value.toString());
|
||||
comment = property.comment.c_str();
|
||||
xisf = true;
|
||||
}
|
||||
|
||||
void WCSDataT::freeWCS()
|
||||
{
|
||||
wcsvfree(&nwcs, &wcs);
|
||||
nwcs = 0;
|
||||
wcs = nullptr;
|
||||
}
|
||||
|
||||
WCSDataT::WCSDataT(int width, int height, char *header, int nrec) :
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
int nreject = 0;
|
||||
int status = wcspih(header, nrec, 1, 0, &nreject, &nwcs, &wcs);
|
||||
if(status != 0)
|
||||
{
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
WCSDataT::WCSDataT(int width, int height, const QVector<FITSRecord> &header) :
|
||||
width(width),
|
||||
height(height)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
QByteArray str;
|
||||
int nrec = 1;
|
||||
for(const FITSRecord &record : header)
|
||||
{
|
||||
if(record.key.startsWith("PV"))continue;
|
||||
|
||||
QByteArray rec;
|
||||
rec.append(record.key.leftJustified(8, ' '));
|
||||
rec.append("= ");
|
||||
rec.append(record.value.toString().toLatin1());
|
||||
rec.append(" / ");
|
||||
rec.append(record.comment);
|
||||
str.append(rec.leftJustified(80, ' ', true));
|
||||
nrec++;
|
||||
}
|
||||
str.append(QByteArray("END").leftJustified(80));
|
||||
|
||||
int nreject = 0;
|
||||
status = wcspih(str.data(), nrec, 1, 0, &nreject, &nwcs, &wcs);
|
||||
if(status != 0)
|
||||
{
|
||||
freeWCS();
|
||||
return;
|
||||
}
|
||||
status = cdfix(wcs);
|
||||
if(status > 0 || wcs->crpix[0] == 0)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
WCSDataT::~WCSDataT()
|
||||
{
|
||||
if(wcs)
|
||||
freeWCS();
|
||||
}
|
||||
|
||||
bool WCSDataT::pixelToWorld(const QPointF &pixel, SkyPoint &point) const
|
||||
{
|
||||
if(!valid())return false;
|
||||
|
||||
double pixcrd[2] = {pixel.x(), pixel.y()};
|
||||
double imgcrd[8] = {0};
|
||||
double phi = 0;
|
||||
double theta = 0;
|
||||
double world[8] = {0};
|
||||
int stat[NWCSFIX] = {0};
|
||||
int status = wcsp2s(wcs, 1, 2, pixcrd, imgcrd, &phi, &theta, world, stat);
|
||||
if(status == 0)
|
||||
{
|
||||
point = SkyPoint(world[0], world[1]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WCSDataT::worldToPixel(const SkyPoint &point, QPointF &pixel) const
|
||||
{
|
||||
if(!valid())return false;
|
||||
|
||||
double world[2] = {point.RA(), point.DEC()};
|
||||
double phi = 0;
|
||||
double theta = 0;
|
||||
double imgcrd[8] = {0};
|
||||
double pixcrd[8] = {0};
|
||||
int stat[NWCSFIX] = {0};
|
||||
int status = wcss2p(wcs, 1, 2, world, &phi, &theta, imgcrd, pixcrd, stat);
|
||||
if(status == 0)
|
||||
{
|
||||
pixel = QPointF(pixcrd[0], pixcrd[1]);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WCSDataT::calculateBounds(double &minRa, double &maxRa, double &minDec, double &maxDec, double &crVal1, double &crVal2) const
|
||||
{
|
||||
if(wcs == nullptr)return;
|
||||
|
||||
minRa = 1000;
|
||||
maxRa = -1000;
|
||||
minDec = 1000;
|
||||
maxDec = -1000;
|
||||
|
||||
if(wcs->crval)
|
||||
{
|
||||
crVal1 = wcs->crval[0];
|
||||
crVal2 = wcs->crval[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
crVal1 = crVal2 = NAN;
|
||||
}
|
||||
|
||||
auto update = [&](const QPointF &pixel)
|
||||
{
|
||||
SkyPoint point;
|
||||
pixelToWorld(pixel, point);
|
||||
minRa = std::min(minRa, point.RA());
|
||||
maxRa = std::max(maxRa, point.RA());
|
||||
minDec = std::min(minDec, point.DEC());
|
||||
maxDec = std::max(maxDec, point.DEC());
|
||||
};
|
||||
|
||||
for(int x=0; x<width; x++)
|
||||
{
|
||||
update(QPointF(x, 0));
|
||||
update(QPointF(x, height - 1));
|
||||
}
|
||||
|
||||
for(int y=0; y<height; y++)
|
||||
{
|
||||
update(QPointF(0, y));
|
||||
update(QPointF(width - 1, y));
|
||||
}
|
||||
|
||||
QPointF ncp;
|
||||
QPointF scp;
|
||||
QRectF s(0, 0, width - 1, height - 1);
|
||||
if(worldToPixel(SkyPoint(0, 90), ncp))
|
||||
{
|
||||
if(s.contains(ncp))
|
||||
maxDec = 90;
|
||||
}
|
||||
|
||||
if(worldToPixel(SkyPoint(0, -90), scp))
|
||||
{
|
||||
if(s.contains(scp))
|
||||
minDec = -90;
|
||||
}
|
||||
}
|
||||
|
||||
double hav(double x)
|
||||
{
|
||||
return (1.0 - std::cos(x)) * 0.5;
|
||||
}
|
||||
|
||||
double haverSine(const SkyPoint &a, SkyPoint &b)
|
||||
{
|
||||
const double ToRAD = M_PI / 180.0;
|
||||
double d = hav((a.DEC() - b.DEC()) * ToRAD) + std::cos(a.DEC() * ToRAD) * std::cos(b.DEC() * ToRAD) * hav((a.RA() - b.RA()) * ToRAD);
|
||||
return std::acos(1.0 - 2.0 * d) * (180.0 / M_PI);
|
||||
}
|
||||
|
||||
SkyPointScale WCSDataT::getRaDecScale() const
|
||||
{
|
||||
SkyPointScale ret;
|
||||
pixelToWorld(QPointF(width/2.0, height/2.0), ret.point);
|
||||
SkyPoint pointX;
|
||||
SkyPoint pointY;
|
||||
pixelToWorld(QPointF(width/2.0+1, height/2.0), pointX);
|
||||
pixelToWorld(QPointF(width/2.0, height/2.0+1), pointY);
|
||||
double scaleX = haverSine(ret.point, pointX) * 3600.0;
|
||||
double scaleY = haverSine(ret.point, pointY) * 3600.0;
|
||||
ret.scaleLow = std::min(scaleX, scaleY);
|
||||
ret.scaleHigh = std::max(scaleX, scaleY);
|
||||
ret.scaleValid = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint() : ra(NAN), dec(NAN)
|
||||
{
|
||||
}
|
||||
|
||||
SkyPoint::SkyPoint(double ra, double dec) : ra(ra), dec(dec)
|
||||
{
|
||||
}
|
||||
|
||||
void SkyPoint::set(double ra, double dec)
|
||||
{
|
||||
this->ra = ra;
|
||||
this->dec = dec;
|
||||
}
|
||||
|
||||
QString SkyPoint::toString() const
|
||||
{
|
||||
if(std::isnan(ra) || std::isnan(dec))
|
||||
return QString();
|
||||
|
||||
QTime t(0, 0);
|
||||
t = t.addSecs(ra * 240);
|
||||
|
||||
double deg, min, sec;
|
||||
min = std::abs(std::modf(dec, °) * 60);
|
||||
sec = std::modf(min, &min) * 60;
|
||||
return QString("RA: %1 DEC: %2° %3' %4\"").arg(t.toString("HH'h' mm'm' ss's'")).arg(deg, 2, 'f', 0, '0').arg(min, 2, 'f', 0, '0').arg(sec, 2, 'f', 0, '0');
|
||||
}
|
||||
|
||||
double SkyPoint::fromHMS(const QString &hms)
|
||||
{
|
||||
double deg = fromDMS(hms);
|
||||
if(std::isnan(deg))return deg;
|
||||
return deg * 15.0;
|
||||
}
|
||||
|
||||
double SkyPoint::fromDMS(const QString &dms)
|
||||
{
|
||||
double deg = 0.0;
|
||||
QString str = dms.trimmed();
|
||||
str.remove(QRegularExpression("[hdms°'\"]"));
|
||||
str.replace(':', ' ');
|
||||
str.replace(QRegularExpression("\\s+"), " ");
|
||||
QStringList fields = str.split(' ');
|
||||
double sign = 1.0;
|
||||
|
||||
bool ok = false;
|
||||
if(fields.size() >= 1)
|
||||
deg = fields.at(0).toDouble(&ok);
|
||||
if(!ok)return NAN;
|
||||
if(deg < 0.0)
|
||||
sign = -1.0;
|
||||
if(fields.size() >= 2)
|
||||
deg += sign * fields.at(1).toDouble() / 60.0;
|
||||
if(fields.size() >= 3)
|
||||
deg += sign * fields.at(2).toDouble() / 3600.0;
|
||||
|
||||
return deg;
|
||||
}
|
||||
|
||||
QString SkyPoint::toHMS(double decHour)
|
||||
{
|
||||
double h,m,s,md;
|
||||
md = std::modf(decHour, &h) * 60.0;
|
||||
s = std::modf(md, &m) * 60.0;
|
||||
|
||||
return QString("%1h %2m %3s").arg((int)h, 2, 10, QChar('0')).arg((int)m, 2, 10, QChar('0')).arg((int)s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
QString SkyPoint::toDMS(double deg)
|
||||
{
|
||||
double d,m,s,md;
|
||||
md = std::modf(deg, &d) * 60.0;
|
||||
s = std::modf(md, &m) * 60.0;
|
||||
|
||||
return QString("%1˚ %2' %3\"").arg((int)d, 2, 10, QChar('0')).arg((int)m, 2, 10, QChar('0')).arg((int)s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
SkyPointScale ImageInfoData::getCenterRaDec() const
|
||||
{
|
||||
SkyPointScale ret;
|
||||
if(wcs && wcs->valid())
|
||||
{
|
||||
ret = wcs->getRaDecScale();
|
||||
}
|
||||
else
|
||||
{
|
||||
double ra,dec,focalLen,scale,pixSizeX,pixSizeY;
|
||||
int binX = 1;
|
||||
int binY = 1;
|
||||
ra = dec = focalLen = scale = pixSizeX = pixSizeY = NAN;
|
||||
bool ok;
|
||||
for(const FITSRecord &header : fitsHeader)
|
||||
{
|
||||
if(header.key == "OBJCTRA")
|
||||
{
|
||||
double tmp = SkyPoint::fromHMS(header.value.toString());
|
||||
if(!std::isnan(tmp))ra = tmp;
|
||||
}
|
||||
else if(header.key == "RA" && std::isnan(ra))
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)ra = tmp;
|
||||
}
|
||||
else if(header.key == "OBJCTDEC")
|
||||
{
|
||||
double tmp = SkyPoint::fromDMS(header.value.toString());
|
||||
if(!std::isnan(tmp))dec = tmp;
|
||||
}
|
||||
else if(header.key == "DEC" && std::isnan(dec))
|
||||
{
|
||||
double tmp = SkyPoint::fromDMS(header.value.toString());
|
||||
if(!std::isnan(tmp))dec = tmp;
|
||||
}
|
||||
else if(header.key == "SCALE")
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)scale = tmp;
|
||||
}
|
||||
else if(header.key == "FOCALLEN")
|
||||
{
|
||||
double tmp = header.value.toDouble(&ok);
|
||||
if(ok)focalLen = tmp;
|
||||
}
|
||||
else if(header.key == "PIXSIZE1" || header.key == "XPIXSZ")
|
||||
{
|
||||
pixSizeX = header.value.toDouble();
|
||||
}
|
||||
else if(header.key == "PIXSIZE2" || header.key == "YPIXSZ")
|
||||
{
|
||||
pixSizeY = header.value.toDouble();
|
||||
}
|
||||
else if(header.key == "XBINNING")
|
||||
{
|
||||
int tmp = header.value.toInt(&ok);
|
||||
if(ok)binX = tmp;
|
||||
}
|
||||
else if(header.key == "YBINNING")
|
||||
{
|
||||
int tmp = header.value.toInt(&ok);
|
||||
if(ok)binY = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
ret.point.set(ra, dec);
|
||||
if(!std::isnan(scale))
|
||||
{
|
||||
ret.scaleLow = ret.scaleHigh = scale;
|
||||
ret.scaleValid = true;
|
||||
}
|
||||
else if(!(std::isnan(focalLen) || std::isnan(pixSizeX) || std::isnan(pixSizeY)))
|
||||
{
|
||||
const double r = 206.2648097656; // (180 * 3600) / (1000 * pi) magic number to convert pixel size to focal length ratio to arcsec.
|
||||
ret.scaleLow = std::min(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r);
|
||||
ret.scaleHigh = std::max(pixSizeX * binX / focalLen * r, pixSizeY * binY / focalLen * r);
|
||||
ret.scaleValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(ret.scaleValid)
|
||||
{
|
||||
ret.scaleLow *= 0.8;
|
||||
ret.scaleHigh *= 1.2;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
#ifndef IMAGEINFODATA_H
|
||||
#define IMAGEINFODATA_H
|
||||
|
||||
#include <QString>
|
||||
#include <QPointF>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
#include <wcslib/wcs.h>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
namespace LibXISF { struct FITSKeyword; struct Property; }
|
||||
|
||||
struct FITSRecord
|
||||
{
|
||||
QByteArray key;
|
||||
QVariant value;
|
||||
QByteArray comment;
|
||||
bool xisf = false;
|
||||
bool editable() const;
|
||||
FITSRecord(){}
|
||||
FITSRecord(const QByteArray &key, const QVariant &value, const QByteArray &comment);
|
||||
FITSRecord(const LibXISF::FITSKeyword &record);
|
||||
FITSRecord(const LibXISF::Property &property);
|
||||
};
|
||||
|
||||
class SkyPoint
|
||||
{
|
||||
double ra = NAN;
|
||||
double dec = NAN;
|
||||
public:
|
||||
SkyPoint();
|
||||
SkyPoint(double ra, double dec);
|
||||
void set(double ra, double dec);
|
||||
double RA() const { return ra; }
|
||||
double RAHour() const { return ra / 15.0; }
|
||||
double DEC() const { return dec; }
|
||||
QString toString() const;
|
||||
static double fromHMS(const QString &hms);
|
||||
static double fromDMS(const QString &dms);
|
||||
static QString toHMS(double decHour);
|
||||
static QString toDMS(double deg);
|
||||
};
|
||||
|
||||
struct SkyPointScale
|
||||
{
|
||||
SkyPoint point;
|
||||
//arcsec per pixel
|
||||
bool scaleValid = false;
|
||||
double scaleLow = 0.0;
|
||||
double scaleHigh = 10000.0;
|
||||
};
|
||||
|
||||
class WCSDataT
|
||||
{
|
||||
int nwcs = 0;
|
||||
struct wcsprm *wcs = nullptr;
|
||||
int width;
|
||||
int height;
|
||||
void freeWCS();
|
||||
public:
|
||||
WCSDataT(int width, int height, char *header, int nrec);
|
||||
WCSDataT(int width, int height, const QVector<FITSRecord> &header);
|
||||
WCSDataT(const WCSDataT &) = delete;
|
||||
~WCSDataT();
|
||||
bool pixelToWorld(const QPointF &pixel, SkyPoint &point) const;
|
||||
bool worldToPixel(const SkyPoint &point, QPointF &pixel) const;
|
||||
void calculateBounds(double &minRa, double &maxRa, double &minDec, double &maxDec, double &crVal1, double &crVal2) const;
|
||||
bool valid() const { return wcs; };
|
||||
SkyPointScale getRaDecScale() const;
|
||||
};
|
||||
|
||||
struct ImageInfoData
|
||||
{
|
||||
QVector<FITSRecord> fitsHeader;
|
||||
QVector<QPair<QString, QString>> info;
|
||||
std::shared_ptr<WCSDataT> wcs;
|
||||
SkyPointScale getCenterRaDec() const;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
None,
|
||||
Statistics,
|
||||
Peaks,
|
||||
Stars,
|
||||
}AnalyzeLevel;
|
||||
|
||||
Q_DECLARE_METATYPE(ImageInfoData);
|
||||
|
||||
#endif // IMAGEINFODATA_H
|
||||
+28
-6
@@ -4,6 +4,7 @@
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QTimer>
|
||||
#include <QRegularExpression>
|
||||
#include "loadrunable.h"
|
||||
#include "rawimage.h"
|
||||
#include "database.h"
|
||||
@@ -84,6 +85,11 @@ void Image::clearThumbnail()
|
||||
m_thumbnail.reset();
|
||||
}
|
||||
|
||||
bool Image::isLoading() const
|
||||
{
|
||||
return m_loading;
|
||||
}
|
||||
|
||||
void Image::imageLoaded(std::shared_ptr<RawImage> rawImage, ImageInfoData info)
|
||||
{
|
||||
m_loading = false;
|
||||
@@ -107,6 +113,7 @@ ImageRingList::ImageRingList(Database *database, const QStringList &nameFilter,
|
||||
, m_analyzeLevel(None)
|
||||
, m_database(database)
|
||||
, m_nameFilter(nameFilter)
|
||||
, m_fileSuffix(nameFilter)
|
||||
{
|
||||
connect(&m_fileSystemWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(dirChanged(QString)));
|
||||
m_nameFilter.replaceInStrings(QRegularExpression("^"), "*.");
|
||||
@@ -164,8 +171,8 @@ bool ImageRingList::setDir(const QString path, const QString ¤tFile, bool
|
||||
};
|
||||
|
||||
scanDir(path);
|
||||
qDebug() << absolutePaths.size();
|
||||
setFiles(absolutePaths, m_liveMode ? absolutePaths.first() : currentFile);
|
||||
//qDebug() << absolutePaths.size();
|
||||
setFilesPrivate(absolutePaths, m_liveMode ? absolutePaths.first() : currentFile);
|
||||
|
||||
m_fileSystemWatcher.removePaths(m_fileSystemWatcher.directories());
|
||||
m_fileSystemWatcher.addPath(path);
|
||||
@@ -186,6 +193,17 @@ void ImageRingList::setFile(const QString &file)
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setFiles(QStringList files)
|
||||
{
|
||||
QRegularExpression reg("(" + m_fileSuffix.join("|") + ")");
|
||||
files.removeIf([®](const QString &file){
|
||||
QFileInfo info(file);
|
||||
auto match = reg.match(info.suffix());
|
||||
return !match.hasMatch() || !info.exists() || !info.isReadable() || !info.isFile();
|
||||
});
|
||||
setFilesPrivate(files);
|
||||
}
|
||||
|
||||
ImagePtr ImageRingList::currentImage()
|
||||
{
|
||||
if(m_images.size())
|
||||
@@ -199,7 +217,7 @@ void ImageRingList::increment()
|
||||
if(m_images.size())
|
||||
{
|
||||
//don't increment if current image was not loaded yet
|
||||
if(!(*m_currImage)->rawImage())
|
||||
if((*m_currImage)->isLoading())
|
||||
return;
|
||||
|
||||
(*m_firstImage)->release();
|
||||
@@ -215,6 +233,10 @@ void ImageRingList::decrement()
|
||||
{
|
||||
if(m_images.size())
|
||||
{
|
||||
//don't decrement if current image was not loaded yet
|
||||
if((*m_currImage)->isLoading())
|
||||
return;
|
||||
|
||||
(*m_lastImage)->release();
|
||||
m_firstImage = decrement(m_firstImage);
|
||||
m_currImage = decrement(m_currImage);
|
||||
@@ -227,11 +249,11 @@ void ImageRingList::decrement()
|
||||
void ImageRingList::setMarked()
|
||||
{
|
||||
QStringList files = m_database->getMarkedFiles();
|
||||
std::remove_if(files.begin(), files.end(), [](const QString &file){
|
||||
files.removeIf([](const QString &file){
|
||||
QFileInfo info(file);
|
||||
return !info.exists() || !info.isReadable();
|
||||
});
|
||||
setFiles(files);
|
||||
setFilesPrivate(files);
|
||||
}
|
||||
|
||||
void ImageRingList::setLiveMode(bool live)
|
||||
@@ -464,7 +486,7 @@ void ImageRingList::toggleSlideshow(bool start)
|
||||
}
|
||||
}
|
||||
|
||||
void ImageRingList::setFiles(const QStringList files, const QString ¤tFile)
|
||||
void ImageRingList::setFilesPrivate(const QStringList files, const QString ¤tFile)
|
||||
{
|
||||
m_loadPool->clear();
|
||||
m_thumbPool->clear();
|
||||
|
||||
+6
-2
@@ -7,8 +7,9 @@
|
||||
#include <QPixmap>
|
||||
#include <QDir>
|
||||
#include <memory>
|
||||
#include "imageinfo.h"
|
||||
#include "imageinfodata.h"
|
||||
#include "rawimage.h"
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
class ImageRingList;
|
||||
class QThreadPool;
|
||||
@@ -37,6 +38,7 @@ public:
|
||||
bool isCurrent() const;
|
||||
int number() const;
|
||||
void clearThumbnail();
|
||||
bool isLoading() const;
|
||||
signals:
|
||||
void pixmapLoaded(Image *ptr);
|
||||
void thumbnailLoaded(Image *ptr);
|
||||
@@ -66,6 +68,7 @@ class ImageRingList : public QAbstractItemModel
|
||||
QThreadPool *m_thumbPool;
|
||||
Database *m_database;
|
||||
QStringList m_nameFilter;
|
||||
QStringList m_fileSuffix;
|
||||
QTimer *m_slideShowTimer;
|
||||
QTimer *m_dirChangeDelay;
|
||||
QString m_currentDir;
|
||||
@@ -74,6 +77,7 @@ public:
|
||||
~ImageRingList() override;
|
||||
bool setDir(const QString path, const QString ¤tFile = QString(), bool recursive = false);
|
||||
void setFile(const QString &file);
|
||||
void setFiles(QStringList files);
|
||||
ImagePtr currentImage();
|
||||
void setLiveMode(bool live);
|
||||
void setCalculateStats(bool stats);
|
||||
@@ -103,7 +107,7 @@ public slots:
|
||||
void decrement();
|
||||
void setMarked();
|
||||
protected:
|
||||
void setFiles(const QStringList files, const QString ¤tFile = QString());
|
||||
void setFilesPrivate(const QStringList files, const QString ¤tFile = QString());
|
||||
QList<ImagePtr>::iterator increment(QList<ImagePtr>::iterator iter);
|
||||
QList<ImagePtr>::iterator decrement(QList<ImagePtr>::iterator iter);
|
||||
signals:
|
||||
|
||||
+6
-1
@@ -58,6 +58,11 @@ void ImageScrollArea::setBayerMask(int mask)
|
||||
m_imageWidget->setBayerMask(mask);
|
||||
}
|
||||
|
||||
void ImageScrollArea::setColormap(int colormap)
|
||||
{
|
||||
m_imageWidget->setColormap(colormap);
|
||||
}
|
||||
|
||||
void ImageScrollArea::updateScrollbars(int valueH, int stepH, int maxH, int valueV, int stepV, int maxV)
|
||||
{
|
||||
if(maxH > 0)
|
||||
@@ -105,7 +110,7 @@ void ImageScrollArea::oneToOne()
|
||||
|
||||
void ImageScrollArea::imageLoaded(Image *image)
|
||||
{
|
||||
if(image && image->rawImage())
|
||||
if(image)
|
||||
{
|
||||
m_imageWidget->setImage(image->rawImage(), image->number());
|
||||
m_imageWidget->setWCS(image->info().wcs);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define IMAGESCROLLAREA_H
|
||||
|
||||
#include "imagewidget.h"
|
||||
#include <QScrollBar>
|
||||
|
||||
class ImageScrollArea : public QWidget
|
||||
{
|
||||
@@ -16,6 +17,7 @@ public:
|
||||
void allocateThumbnails(const QStringList &paths);
|
||||
void showThumbnail(bool enable);
|
||||
void setBayerMask(int mask);
|
||||
void setColormap(int colormap);
|
||||
protected:
|
||||
void updateScrollbars(int valueH, int stepH, int maxH, int valueV, int stepV, int maxV);
|
||||
public slots:
|
||||
|
||||
+49
-4
@@ -9,12 +9,15 @@
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QPainter>
|
||||
#include "imageringlist.h"
|
||||
#include <QStandardPaths>
|
||||
#include <QFloat16>
|
||||
#include <QStyle>
|
||||
#include "imageringlist.h"
|
||||
|
||||
int FILTERING = 1;
|
||||
bool OpenGLES = false;
|
||||
const int LUT_SIZE = 32;
|
||||
bool BESTFIT = false;
|
||||
|
||||
struct RawImageType
|
||||
{
|
||||
@@ -87,6 +90,7 @@ ImageWidgetGL::ImageWidgetGL(Database *database, QWidget *parent) : QOpenGLWidge
|
||||
});
|
||||
|
||||
setMouseTracking(true);
|
||||
m_bestFit = BESTFIT;
|
||||
}
|
||||
|
||||
ImageWidgetGL::~ImageWidgetGL()
|
||||
@@ -258,6 +262,12 @@ void ImageWidgetGL::setBayerMask(int mask)
|
||||
update();
|
||||
}
|
||||
|
||||
void ImageWidgetGL::setColormap(int colormap)
|
||||
{
|
||||
m_colormapIdx = colormap;
|
||||
update();
|
||||
}
|
||||
|
||||
void ImageWidgetGL::setMTFParams(const MTFParam ¶ms)
|
||||
{
|
||||
m_mtfParams = params;
|
||||
@@ -359,7 +369,7 @@ void swPaint(std::shared_ptr<RawImage> &rawImage, float dx, float dy, float scal
|
||||
auto mtf = [&mtfParams](int i, float x)
|
||||
{
|
||||
x = (x - mtfParams.blackPoint[i]) / (mtfParams.whitePoint[i] - mtfParams.blackPoint[i]);
|
||||
x = std::min(std::max(x, 0.0f), 1.0f);
|
||||
x = std::clamp(x, 0.0f, 1.0f);
|
||||
return ((mtfParams.midPoint[i] - 1.0f) * x) / ((2.0f * mtfParams.midPoint[i] - 1.0f) * x - mtfParams.midPoint[i]);
|
||||
};
|
||||
|
||||
@@ -382,9 +392,9 @@ void swPaint(std::shared_ptr<RawImage> &rawImage, float dx, float dy, float scal
|
||||
float iptr;
|
||||
float fy = std::modf((y + oy) * iscale, &iptr);
|
||||
int64_t py = iptr;
|
||||
int64_t w = py * rawImage->widthBytes();
|
||||
int64_t w = py * rawImage->widthSamples();
|
||||
int64_t w2 = w;
|
||||
if(py+1 < imgHeight)w2 += rawImage->widthBytes();
|
||||
if(py+1 < imgHeight)w2 += rawImage->widthSamples();
|
||||
if(py >= imgHeight)break;
|
||||
|
||||
for(int64_t x = std::max((int64_t)0, -ox); x < width; x++)
|
||||
@@ -600,6 +610,7 @@ void ImageWidgetGL::paintGL()
|
||||
m_program->setUniformValue("filtering", m_scale > 1.0f ? FILTERING : 1);
|
||||
m_program->setUniformValue("lut_table", 2);
|
||||
m_program->setUniformValue("srgb", m_srgb);
|
||||
m_program->setUniformValue("colormapIdx", m_colormapIdx);
|
||||
f->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
m_vao->release();
|
||||
}
|
||||
@@ -702,6 +713,7 @@ void ImageWidgetGL::initializeGL()
|
||||
m_program->setAttributeBuffer("qt_MultiTexCoord0", GL_FLOAT, sizeof(float)*2, 2, sizeof(float)*4);
|
||||
m_program->setUniformValue("qt_Texture0", (GLuint)0);
|
||||
m_program->setUniformValue("lut_table", (GLuint)2);
|
||||
m_program->setUniformValue("colormap", (GLuint)3);
|
||||
m_program->setUniformValue("scale", 1.0f, 0.0f);
|
||||
|
||||
m_debayerProgram = std::unique_ptr<QOpenGLShaderProgram>(new QOpenGLShaderProgram);
|
||||
@@ -764,6 +776,19 @@ void ImageWidgetGL::initializeGL()
|
||||
m_lut->allocateStorage();
|
||||
m_lut->bind(2);
|
||||
|
||||
QImage colormap = loadColormap();
|
||||
m_colormap = std::make_unique<QOpenGLTexture>(QOpenGLTexture::Target2DArray);
|
||||
m_colormap->setSize(colormap.width());
|
||||
m_colormap->setLayers(colormap.height());
|
||||
m_colormap->setFormat(QOpenGLTexture::RGBA8_UNorm);
|
||||
m_colormap->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear);
|
||||
m_colormap->setWrapMode(QOpenGLTexture::ClampToEdge);
|
||||
m_colormap->allocateStorage();
|
||||
for(int i=0; i<colormap.height(); i++)
|
||||
m_colormap->setData(0, i, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, colormap.scanLine(i));
|
||||
|
||||
m_colormap->bind(3);
|
||||
|
||||
if(m_rawImage)
|
||||
setImage(m_rawImage, m_currentImg);
|
||||
}
|
||||
@@ -945,3 +970,23 @@ void ImageWidgetGL::updateScrollBars()
|
||||
else
|
||||
emit scrollBarsUpdate(m_dx, m_width, m_imgWidth * m_scale - m_width, m_dy, m_height, m_imgHeight * m_scale - m_height);
|
||||
}
|
||||
|
||||
QImage ImageWidget::loadColormap()
|
||||
{
|
||||
QImage embedded(":/colormap.png");
|
||||
QStringList path = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation);
|
||||
if(path.size())
|
||||
{
|
||||
QImage user(path.first() + "/colormap.png");
|
||||
if(!user.isNull())
|
||||
{
|
||||
user = user.scaledToWidth(embedded.width(), Qt::SmoothTransformation);
|
||||
QImage tmp(embedded.width(), embedded.height() + user.height(), QImage::Format_RGBA8888);
|
||||
QPainter painter(&tmp);
|
||||
painter.drawImage(0, 0, embedded);
|
||||
painter.drawImage(0, embedded.height(), user);
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
return embedded.convertToFormat(QImage::Format_RGBA8888);
|
||||
}
|
||||
|
||||
+7
-1
@@ -10,7 +10,7 @@
|
||||
#include <QOpenGLFunctions>
|
||||
#include "database.h"
|
||||
#include "rawimage.h"
|
||||
#include "imageinfo.h"
|
||||
#include "imageinfodata.h"
|
||||
#include "stretchtoolbar.h"
|
||||
|
||||
class ImageWidget
|
||||
@@ -26,6 +26,7 @@ public:
|
||||
virtual void bestFit() = 0;
|
||||
|
||||
virtual void setBayerMask(int mask) = 0;
|
||||
virtual void setColormap(int colormap) = 0;
|
||||
virtual void setOffset(float dx, float dy) = 0;
|
||||
virtual void allocateThumbnails(const QStringList &paths) = 0;
|
||||
|
||||
@@ -36,6 +37,8 @@ public:
|
||||
virtual QImage renderToImage() = 0;
|
||||
virtual void thumbnailLoaded(const Image *image) = 0;
|
||||
virtual void showThumbnail(bool enable) = 0;
|
||||
|
||||
static QImage loadColormap();
|
||||
};
|
||||
|
||||
struct ImageThumb
|
||||
@@ -63,6 +66,7 @@ class ImageWidgetGL : public QOpenGLWidget, public ImageWidget
|
||||
std::unique_ptr<QOpenGLVertexArrayObject> m_vaoThumb;
|
||||
std::unique_ptr<QOpenGLTexture> m_thumbnailTexture;
|
||||
std::unique_ptr<QOpenGLTexture> m_lut;
|
||||
std::unique_ptr<QOpenGLTexture> m_colormap;
|
||||
GLuint m_debayerTex = 0;
|
||||
std::shared_ptr<RawImage> m_rawImage;
|
||||
std::shared_ptr<WCSDataT> m_wcs;
|
||||
@@ -87,6 +91,7 @@ class ImageWidgetGL : public QOpenGLWidget, public ImageWidget
|
||||
int m_maxTextureSize = 0;
|
||||
int m_maxArrayLayers = 0;
|
||||
int m_firstRed[2] = {0, 0};
|
||||
int m_colormapIdx = 0;
|
||||
QVector<ImageThumb> m_thumnails;
|
||||
Database *m_database = nullptr;
|
||||
QPointF m_lastPos;
|
||||
@@ -102,6 +107,7 @@ public:
|
||||
void allocateThumbnails(const QStringList &paths) override;
|
||||
QVector2D getImagePixelCoord(const QVector2D &pos);
|
||||
void setBayerMask(int mask) override;
|
||||
void setColormap(int colormap) override;
|
||||
void setOffset(float dx, float dy) override;
|
||||
void setMTFParams(const MTFParam ¶ms) override;
|
||||
void superPixel(bool enable) override;
|
||||
|
||||
+419
@@ -0,0 +1,419 @@
|
||||
#include "loadimage.h"
|
||||
#include <QElapsedTimer>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <libraw/libraw.h>
|
||||
#include <fitsio2.h>
|
||||
#include "libxisf.h"
|
||||
#include <libexif/exif-data.h>
|
||||
#include "rawimage.h"
|
||||
|
||||
QString makeUNCPath(const QString &path)
|
||||
{
|
||||
#ifdef Q_OS_WIN64
|
||||
if(!path.startsWith("\\\\") && !path.startsWith("//"))
|
||||
{
|
||||
QString tmp;
|
||||
QFileInfo info(path);
|
||||
tmp = info.absoluteFilePath();
|
||||
tmp = QDir::toNativeSeparators(tmp);
|
||||
tmp.prepend("\\\\?\\");
|
||||
qDebug() << "makeMaxPath" << path << tmp;
|
||||
return tmp;
|
||||
}
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
int loadFITSHeader(fitsfile *file, ImageInfoData &info)
|
||||
{
|
||||
int imgtype;
|
||||
int naxis;
|
||||
long naxes[3] = {0};
|
||||
int nexist;
|
||||
int status = 0;
|
||||
char key[FLEN_KEYWORD];
|
||||
char val[FLEN_VALUE];
|
||||
char comm[FLEN_COMMENT];
|
||||
char strval[FLEN_VALUE];
|
||||
QVariant var;
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
||||
fits_get_hdrspace(file, &nexist, nullptr, &status);
|
||||
for(int i=1; i<=nexist; i++)
|
||||
{
|
||||
fits_read_keyn(file, i, key, val, comm, &status);
|
||||
fits_read_key(file, TSTRING, key, strval, nullptr, &status);
|
||||
if(status == 0 || status == VALUE_UNDEFINED)
|
||||
{
|
||||
QString string(strval);
|
||||
bool isint;
|
||||
bool isdouble;
|
||||
double vald = string.toDouble(&isdouble);
|
||||
long long vall = string.toLongLong(&isint);
|
||||
if(isint)
|
||||
var = vall;
|
||||
else if(isdouble)
|
||||
var = vald;
|
||||
else if(status == VALUE_UNDEFINED)
|
||||
var = QVariant();
|
||||
else if(string == "T" || string == "F")
|
||||
var = string == "T";
|
||||
else
|
||||
var = string;
|
||||
status = 0;
|
||||
info.fitsHeader.append(FITSRecord(key, var, comm));
|
||||
}
|
||||
else
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
char *header = nullptr;
|
||||
int nrec = 0;
|
||||
const char *exclist[] = {"PV1_1", "PV1_2"};
|
||||
fits_hdr2str(file, TRUE, (char**)exclist, 2, &header, &nrec, &status);
|
||||
if(status == 0)
|
||||
{
|
||||
info.wcs = std::make_shared<WCSDataT>(naxes[0], naxes[1], header, nrec);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
}
|
||||
fits_free_memory(header, &status);
|
||||
return status;
|
||||
}
|
||||
|
||||
bool loadFITS(const QString path, ImageInfoData &info, std::shared_ptr<RawImage> &image, bool planar)
|
||||
{
|
||||
fitsfile *file;
|
||||
int status = 0;
|
||||
int type = -1;
|
||||
int num = 0;
|
||||
long naxes[3] = {0};
|
||||
|
||||
auto checkError = [&info, &status]()
|
||||
{
|
||||
char err[100];
|
||||
fits_get_errstatus(status, err);
|
||||
info.info.append({QObject::tr("Error"), QString(err)});
|
||||
qDebug() << "Failed to load FITS file" << err;
|
||||
return false;
|
||||
};
|
||||
|
||||
fits_open_diskfile(&file, path.toLocal8Bit().data(), READONLY, &status);
|
||||
if(status)return checkError();
|
||||
fits_get_num_hdus(file, &num, &status);
|
||||
if(status)return checkError();
|
||||
|
||||
int imgtype;
|
||||
int naxis;
|
||||
for(int i=1; i <= num; i++)
|
||||
{
|
||||
fits_movabs_hdu(file, i, IMAGE_HDU, &status);if(status)return checkError();
|
||||
fits_get_hdu_type(file, &type, &status);if(status)return checkError();
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);if(status)return checkError();
|
||||
fits_get_img_equivtype(file, &imgtype, &status);if(status)return checkError();
|
||||
|
||||
if(type == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
||||
{
|
||||
RawImage::DataType type;
|
||||
int fitstype;
|
||||
long fpixel[3] = {1,1,1};
|
||||
switch(imgtype)
|
||||
{
|
||||
case BYTE_IMG:
|
||||
type = RawImage::UINT8;
|
||||
fitstype = TBYTE;
|
||||
break;
|
||||
case SHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TSHORT;
|
||||
break;
|
||||
case USHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TUSHORT;
|
||||
break;
|
||||
case ULONG_IMG:
|
||||
type = RawImage::UINT32;
|
||||
fitstype = TUINT;
|
||||
break;
|
||||
case FLOAT_IMG:
|
||||
type = RawImage::FLOAT32;
|
||||
fitstype = TFLOAT;
|
||||
break;
|
||||
case DOUBLE_IMG:
|
||||
type = RawImage::FLOAT64;
|
||||
fitstype = TDOUBLE;
|
||||
break;
|
||||
default:
|
||||
info.info.append({QObject::tr("Error"), QObject::tr("Unsupported sample format")});
|
||||
goto noload;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t size = naxes[0]*naxes[1];
|
||||
size_t w = naxes[0];
|
||||
size_t h = naxes[1];
|
||||
|
||||
info.info.append({QObject::tr("Width"), QString::number(naxes[0])});
|
||||
info.info.append({QObject::tr("Height"), QString::number(naxes[1])});
|
||||
|
||||
RawImage img(w, h, naxis == 2 ? 1 : naxes[2], type);
|
||||
uint8_t *data = static_cast<uint8_t*>(img.data());
|
||||
for (int i=1; i==1 || i<=naxes[2]; i++)
|
||||
{
|
||||
fpixel[2] = i;
|
||||
fits_read_pix(file, fitstype, fpixel, size, NULL, data + img.size() * RawImage::typeSize(type) * (i-1), NULL, &status);
|
||||
if(status)return checkError();
|
||||
}
|
||||
if(fitstype == TSHORT)
|
||||
{
|
||||
uint16_t *s = static_cast<uint16_t*>(img.data());
|
||||
size_t size = img.size() * img.channels();
|
||||
for(size_t i=0; i<size; i++)
|
||||
s[i] -= INT16_MIN;
|
||||
}
|
||||
|
||||
if(img.channels() == 1 || planar)
|
||||
image = std::make_shared<RawImage>(std::move(img));
|
||||
else
|
||||
image = RawImage::fromPlanar(img);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
noload:
|
||||
if(file)
|
||||
{
|
||||
status = loadFITSHeader(file, info);
|
||||
if(status)return checkError();
|
||||
}
|
||||
|
||||
if(image)
|
||||
{
|
||||
for(auto fits : info.fitsHeader)
|
||||
{
|
||||
if(fits.key == "ROWORDER" && fits.value == "BOTTOM-UP")
|
||||
image->flip();
|
||||
}
|
||||
}
|
||||
|
||||
fits_close_file(file, &status);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadXISF(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &image, bool planar)
|
||||
{
|
||||
try
|
||||
{
|
||||
LibXISF::XISFReader xisf;
|
||||
xisf.open(path.toLocal8Bit().data());
|
||||
|
||||
const LibXISF::Image &xisfImage = xisf.getImage(0);
|
||||
|
||||
auto fitskeywords = xisfImage.fitsKeywords();
|
||||
for(auto fits : fitskeywords)
|
||||
{
|
||||
info.fitsHeader.append(fits);
|
||||
}
|
||||
auto imageproperties = xisfImage.imageProperties();
|
||||
for(auto prop : imageproperties)
|
||||
{
|
||||
info.fitsHeader.append(prop);
|
||||
}
|
||||
|
||||
info.wcs = std::make_shared<WCSDataT>(xisfImage.width(), xisfImage.height(), info.fitsHeader);
|
||||
info.info.append({QObject::tr("Width"), QString::number(xisfImage.width())});
|
||||
info.info.append({QObject::tr("Height"), QString::number(xisfImage.height())});
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
|
||||
RawImage::DataType type;
|
||||
switch(xisfImage.sampleFormat())
|
||||
{
|
||||
case LibXISF::Image::UInt8: type = RawImage::UINT8; break;
|
||||
case LibXISF::Image::UInt16: type = RawImage::UINT16; break;
|
||||
case LibXISF::Image::UInt32: type = RawImage::UINT32; break;
|
||||
case LibXISF::Image::Float32: type = RawImage::FLOAT32; break;
|
||||
case LibXISF::Image::Float64: type = RawImage::FLOAT64; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
LibXISF::Image tmpImage = xisfImage;
|
||||
tmpImage.convertPixelStorageTo(LibXISF::Image::Planar);
|
||||
if(tmpImage.colorSpace() == LibXISF::Image::ColorSpace::Gray)
|
||||
{
|
||||
image = std::make_shared<RawImage>(tmpImage.width(), tmpImage.height(), 1, type);
|
||||
std::memcpy(image->data(), tmpImage.imageData(), tmpImage.imageDataSize() / tmpImage.channelCount());
|
||||
image->setICCProfile(tmpImage.iccProfile());
|
||||
return true;
|
||||
}
|
||||
else if(tmpImage.channelCount() == 3 || tmpImage.channelCount() == 4)
|
||||
{
|
||||
if(planar)
|
||||
{
|
||||
image = std::make_shared<RawImage>(tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type);
|
||||
std::memcpy(image->data(), tmpImage.imageData(), tmpImage.imageDataSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
image = RawImage::fromPlanar(tmpImage.imageData(), tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type);
|
||||
}
|
||||
|
||||
image->setICCProfile(tmpImage.iccProfile());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (LibXISF::Error &err)
|
||||
{
|
||||
info.info.append(QPair<QString, QString>("Error", err.what()));
|
||||
qDebug() << "Failed to load XISF" << err.what();
|
||||
return false;
|
||||
}
|
||||
info.info.append({QObject::tr("Error"), QObject::tr("Unsupported sample format")});
|
||||
return false;
|
||||
}
|
||||
|
||||
bool readFITSHeader(const QString &path, ImageInfoData &info)
|
||||
{
|
||||
fitsfile *fr;
|
||||
int status = 0;
|
||||
QString path2 = makeUNCPath(path);
|
||||
fits_open_diskfile(&fr, path2.toLocal8Bit().data(), READONLY, &status);
|
||||
|
||||
if(fr && status == 0)
|
||||
{
|
||||
status = loadFITSHeader(fr, info);
|
||||
fits_close_file(fr, &status);
|
||||
}
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
bool readXISFHeader(const QString &path, ImageInfoData &info)
|
||||
{
|
||||
QString path2 = makeUNCPath(path);
|
||||
try
|
||||
{
|
||||
LibXISF::XISFReader xisf;
|
||||
xisf.open(path2.toLocal8Bit().data());
|
||||
const LibXISF::Image &image = xisf.getImage(0, false);
|
||||
|
||||
auto fitskeywords = image.fitsKeywords();
|
||||
for(auto fits : fitskeywords)
|
||||
{
|
||||
info.fitsHeader.append(fits);
|
||||
}
|
||||
|
||||
auto imageproperties = image.imageProperties();
|
||||
for(auto prop : imageproperties)
|
||||
{
|
||||
info.fitsHeader.append(prop);
|
||||
}
|
||||
info.wcs = std::make_shared<WCSDataT>(image.width(), image.height(), info.fitsHeader);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
}
|
||||
catch (LibXISF::Error &err)
|
||||
{
|
||||
qDebug() << err.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void loadExifEntry(ImageInfoData &info, ExifContent *content, ExifTag tag)
|
||||
{
|
||||
char val[1024];
|
||||
ExifEntry *entry = exif_content_get_entry(content, tag);
|
||||
if(entry)
|
||||
{
|
||||
exif_entry_get_value(entry, val, sizeof(val));
|
||||
info.info.append({exif_tag_get_title(tag), val});
|
||||
}
|
||||
}
|
||||
|
||||
bool loadRAW(const QString path, ImageInfoData &info, std::shared_ptr<RawImage> &image)
|
||||
{
|
||||
std::unique_ptr<LibRaw> raw = std::make_unique<LibRaw>();
|
||||
raw->open_file(path.toLocal8Bit().data());
|
||||
raw->imgdata.params.half_size = true;
|
||||
raw->imgdata.params.use_camera_wb = true;
|
||||
raw->imgdata.params.user_flip = 0;
|
||||
if(raw->unpack())
|
||||
return false;
|
||||
|
||||
|
||||
libraw_rawdata_t rawdata = raw->imgdata.rawdata;
|
||||
size_t size = rawdata.sizes.width*rawdata.sizes.height;
|
||||
|
||||
std::vector<uint16_t> out;
|
||||
out.resize(size);
|
||||
size_t d = 0;
|
||||
uint h=rawdata.sizes.top_margin+rawdata.sizes.height;
|
||||
uint w=rawdata.sizes.left_margin+rawdata.sizes.width;
|
||||
size_t pitch = rawdata.sizes.raw_pitch/sizeof(uint16_t);
|
||||
|
||||
for(size_t i=rawdata.sizes.top_margin;i<h;i++)
|
||||
{
|
||||
for(size_t o=rawdata.sizes.left_margin;o<w;o++)
|
||||
{
|
||||
uint16_t p = rawdata.raw_image[i*pitch+o];
|
||||
out[d++] = p;
|
||||
}
|
||||
}
|
||||
image = std::make_shared<RawImage>(rawdata.sizes.width, rawdata.sizes.height, 1, RawImage::UINT16);
|
||||
memcpy(image->data(), &out[0], sizeof(uint16_t)*d);
|
||||
|
||||
QString shutterSpeed = QString::number(raw->imgdata.other.shutter);
|
||||
if(raw->imgdata.other.shutter < 1)
|
||||
{
|
||||
shutterSpeed = QString("1/%1s").arg(1.0f/raw->imgdata.other.shutter);
|
||||
}
|
||||
info.info.append({QObject::tr("Width"), QString::number(raw->imgdata.sizes.width)});
|
||||
info.info.append({QObject::tr("Height"), QString::number(raw->imgdata.sizes.height)});
|
||||
info.info.append({QObject::tr("ISO"), QString::number(raw->imgdata.other.iso_speed)});
|
||||
info.info.append({QObject::tr("Shutter speed"), shutterSpeed});
|
||||
#if LIBRAW_MINOR_VERSION>=19
|
||||
// info.append(StringPair(QObject::tr("Camera temperature"), QString::number(raw.imgdata.other.CameraTemperature)));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &rawImage, bool planar)
|
||||
{
|
||||
bool ret = false;
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
if(path.endsWith(".CR2", Qt::CaseInsensitive) || path.endsWith(".CR3", Qt::CaseInsensitive) || path.endsWith(".NEF", Qt::CaseInsensitive) || path.endsWith(".DNG", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadRAW(path, info, rawImage);
|
||||
qDebug() << "LoadRAW" << timer.elapsed();
|
||||
}
|
||||
else if(path.endsWith(".FIT", Qt::CaseInsensitive) || path.endsWith(".FITS", Qt::CaseInsensitive) || path.endsWith(".FZ", Qt::CaseInsensitive) || path.endsWith(".FTS", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadFITS(path, info, rawImage, planar);
|
||||
qDebug() << "LoadFITS" << timer.elapsed();
|
||||
}
|
||||
else if(path.endsWith(".XISF", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadXISF(path, info, rawImage, planar);
|
||||
qDebug() << "LoadXISF" << timer.elapsed();
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage img(path);
|
||||
|
||||
ExifData *exif = exif_data_new_from_file(path.toLocal8Bit().constData());
|
||||
info.info.append({QObject::tr("Width"), QString::number(img.width())});
|
||||
info.info.append({QObject::tr("Height"), QString::number(img.height())});
|
||||
if(exif)
|
||||
{
|
||||
loadExifEntry(info, exif->ifd[EXIF_IFD_EXIF], EXIF_TAG_ISO_SPEED_RATINGS);
|
||||
loadExifEntry(info, exif->ifd[EXIF_IFD_EXIF], EXIF_TAG_SHUTTER_SPEED_VALUE);
|
||||
exif_data_free(exif);
|
||||
}
|
||||
rawImage = std::make_shared<RawImage>(img);
|
||||
qDebug() << "LoadQImage" << timer.elapsed();
|
||||
ret = !img.isNull();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#ifndef LOADIMAGE_H
|
||||
#define LOADIMAGE_H
|
||||
|
||||
#include <QString>
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class RawImage;
|
||||
|
||||
QString makeUNCPath(const QString &path);
|
||||
bool readFITSHeader(const QString &path, ImageInfoData &info);
|
||||
bool readXISFHeader(const QString &path, ImageInfoData &info);
|
||||
bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &rawImage, bool planar = false);
|
||||
|
||||
#endif // LOADIMAGE_H
|
||||
+52
-459
@@ -1,386 +1,23 @@
|
||||
#include "loadrunable.h"
|
||||
#include "imageringlist.h"
|
||||
#include <libraw/libraw.h>
|
||||
#include "imageinfo.h"
|
||||
#include <QFileInfo>
|
||||
#include <QPainter>
|
||||
#include <QElapsedTimer>
|
||||
#include <QDebug>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <libexif/exif-data.h>
|
||||
#include <fitsio2.h>
|
||||
#include <libxisf.h>
|
||||
#include "rawimage.h"
|
||||
#include "starfit.h"
|
||||
#include "loadimage.h"
|
||||
#include <lcms2.h>
|
||||
|
||||
QString makeMaxPath(QString path)
|
||||
{
|
||||
#ifdef Q_OS_WIN64
|
||||
if(!path.startsWith("\\\\?\\"))
|
||||
{
|
||||
QFileInfo info(path);
|
||||
path = info.absoluteFilePath();
|
||||
path = QDir::toNativeSeparators(path);
|
||||
path.prepend("\\\\?\\");
|
||||
qDebug() << path;
|
||||
}
|
||||
#endif
|
||||
return path;
|
||||
}
|
||||
|
||||
LoadRunable::LoadRunable(const QString &file, Image *receiver, AnalyzeLevel level, bool thumbnail) :
|
||||
m_file(makeMaxPath(file)),
|
||||
m_file(makeUNCPath(file)),
|
||||
m_receiver(receiver),
|
||||
m_analyzeLevel(level),
|
||||
m_thumbnail(thumbnail)
|
||||
{
|
||||
}
|
||||
|
||||
void loadExifEntry(ImageInfoData &info, ExifContent *content, ExifTag tag)
|
||||
{
|
||||
char val[1024];
|
||||
ExifEntry *entry = exif_content_get_entry(content, tag);
|
||||
if(entry)
|
||||
{
|
||||
exif_entry_get_value(entry, val, sizeof(val));
|
||||
info.info.append({exif_tag_get_title(tag), val});
|
||||
}
|
||||
}
|
||||
|
||||
void drawPeaks(QImage &img, const std::vector<Peak> &peaks)
|
||||
{
|
||||
QPixmap pix = QPixmap::fromImage(img);
|
||||
QPainter painter(&pix);
|
||||
painter.setPen(Qt::red);
|
||||
for(auto peak : peaks)
|
||||
{
|
||||
painter.drawEllipse(QPoint(peak.x(), peak.y()), 5, 5);
|
||||
}
|
||||
img = pix.toImage();
|
||||
}
|
||||
|
||||
void drawStars(QImage &img, const std::vector<Star> &stars)
|
||||
{
|
||||
QPixmap pix = QPixmap::fromImage(img);
|
||||
QPainter painter(&pix);
|
||||
painter.setPen(Qt::red);
|
||||
for(auto star : stars)
|
||||
{
|
||||
painter.drawEllipse(QPointF(star.m_x, star.m_y), star.hw20X(), star.hw20Y());
|
||||
}
|
||||
img = pix.toImage();
|
||||
}
|
||||
|
||||
void printStarModel(int radius, const std::vector<double> &data, const Star &star)
|
||||
{
|
||||
QString d = "d=[";
|
||||
QString m = "m=[";
|
||||
for(int y=0; y<radius; y++)
|
||||
{
|
||||
for(int x=0; x<radius; x++)
|
||||
{
|
||||
d += QString::number(data[y*radius+x]) + ",";
|
||||
m += QString::number(gauss_model(star.m_am, star.m_x, star.m_y, star.m_sx, star.m_sy, x, y)) + ",";
|
||||
}
|
||||
d += ";";
|
||||
m += ";";
|
||||
}
|
||||
d += "];";
|
||||
m += "];";
|
||||
//std::cout << star.m_am << " " << star.m_sx << star.m_sy << std::endl;
|
||||
std::cout << d.toStdString() << std::endl;
|
||||
std::cout << m.toStdString() << std::endl << std::endl;
|
||||
}
|
||||
|
||||
bool loadRAW(const QString path, ImageInfoData &info, std::shared_ptr<RawImage> &image)
|
||||
{
|
||||
std::unique_ptr<LibRaw> raw = std::make_unique<LibRaw>();
|
||||
raw->open_file(path.toLocal8Bit().data());
|
||||
raw->imgdata.params.half_size = true;
|
||||
raw->imgdata.params.use_camera_wb = true;
|
||||
raw->imgdata.params.user_flip = 0;
|
||||
if(raw->unpack())
|
||||
return false;
|
||||
|
||||
|
||||
libraw_rawdata_t rawdata = raw->imgdata.rawdata;
|
||||
size_t size = rawdata.sizes.width*rawdata.sizes.height;
|
||||
|
||||
std::vector<uint16_t> out;
|
||||
out.resize(size);
|
||||
size_t d = 0;
|
||||
uint h=rawdata.sizes.top_margin+rawdata.sizes.height;
|
||||
uint w=rawdata.sizes.left_margin+rawdata.sizes.width;
|
||||
size_t pitch = rawdata.sizes.raw_pitch/sizeof(uint16_t);
|
||||
|
||||
for(size_t i=rawdata.sizes.top_margin;i<h;i++)
|
||||
{
|
||||
for(size_t o=rawdata.sizes.left_margin;o<w;o++)
|
||||
{
|
||||
uint16_t p = rawdata.raw_image[i*pitch+o];
|
||||
out[d++] = p;
|
||||
}
|
||||
}
|
||||
image = std::make_shared<RawImage>(rawdata.sizes.width, rawdata.sizes.height, 1, RawImage::UINT16);
|
||||
memcpy(image->data(), &out[0], sizeof(uint16_t)*d);
|
||||
|
||||
QString shutterSpeed = QString::number(raw->imgdata.other.shutter);
|
||||
if(raw->imgdata.other.shutter < 1)
|
||||
{
|
||||
shutterSpeed = QString("1/%1s").arg(1.0f/raw->imgdata.other.shutter);
|
||||
}
|
||||
info.info.append({QObject::tr("Width"), QString::number(raw->imgdata.sizes.width)});
|
||||
info.info.append({QObject::tr("Height"), QString::number(raw->imgdata.sizes.height)});
|
||||
info.info.append({QObject::tr("ISO"), QString::number(raw->imgdata.other.iso_speed)});
|
||||
info.info.append({QObject::tr("Shutter speed"), shutterSpeed});
|
||||
#if LIBRAW_MINOR_VERSION>=19
|
||||
// info.append(StringPair(QObject::tr("Camera temperature"), QString::number(raw.imgdata.other.CameraTemperature)));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
int loadFITSHeader(fitsfile *file, ImageInfoData &info)
|
||||
{
|
||||
int imgtype;
|
||||
int naxis;
|
||||
long naxes[3] = {0};
|
||||
int nexist;
|
||||
int status = 0;
|
||||
char key[FLEN_KEYWORD];
|
||||
char val[FLEN_VALUE];
|
||||
char comm[FLEN_COMMENT];
|
||||
char strval[FLEN_VALUE];
|
||||
QVariant var;
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
||||
fits_get_hdrspace(file, &nexist, nullptr, &status);
|
||||
for(int i=1; i<=nexist; i++)
|
||||
{
|
||||
fits_read_keyn(file, i, key, val, comm, &status);
|
||||
fits_read_key(file, TSTRING, key, strval, nullptr, &status);
|
||||
if(status == 0 || status == VALUE_UNDEFINED)
|
||||
{
|
||||
QString string(strval);
|
||||
bool isint;
|
||||
bool isdouble;
|
||||
double vald = string.toDouble(&isdouble);
|
||||
long long vall = string.toLongLong(&isint);
|
||||
if(isint)
|
||||
var = vall;
|
||||
else if(isdouble)
|
||||
var = vald;
|
||||
else if(status == VALUE_UNDEFINED)
|
||||
var = QVariant();
|
||||
else if(string == "T" || string == "F")
|
||||
var = string == "T";
|
||||
else
|
||||
var = string;
|
||||
status = 0;
|
||||
info.fitsHeader.append(FITSRecord(key, var, comm));
|
||||
}
|
||||
else
|
||||
{
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
char *header = nullptr;
|
||||
int nrec = 0;
|
||||
const char *exclist[] = {"PV1_1", "PV1_2"};
|
||||
fits_hdr2str(file, TRUE, (char**)exclist, 2, &header, &nrec, &status);
|
||||
if(status == 0)
|
||||
{
|
||||
info.wcs = std::make_shared<WCSDataT>(naxes[0], naxes[1], header, nrec);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
}
|
||||
fits_free_memory(header, &status);
|
||||
return status;
|
||||
}
|
||||
|
||||
bool loadFITS(const QString path, ImageInfoData &info, std::shared_ptr<RawImage> &image, bool planar)
|
||||
{
|
||||
fitsfile *file;
|
||||
int status = 0;
|
||||
int type = -1;
|
||||
fits_open_diskfile(&file, path.toLocal8Bit().data(), READONLY, &status);
|
||||
int num = 0;
|
||||
fits_get_num_hdus(file, &num, &status);
|
||||
|
||||
int imgtype;
|
||||
int naxis;
|
||||
long naxes[3] = {0};
|
||||
for(int i=1; i <= num; i++)
|
||||
{
|
||||
fits_movabs_hdu(file, i, IMAGE_HDU, &status);
|
||||
fits_get_hdu_type(file, &type, &status);
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);
|
||||
fits_get_img_equivtype(file, &imgtype, &status);
|
||||
|
||||
if(type == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
||||
{
|
||||
RawImage::DataType type;
|
||||
int fitstype;
|
||||
long fpixel[3] = {1,1,1};
|
||||
switch(imgtype)
|
||||
{
|
||||
case BYTE_IMG:
|
||||
type = RawImage::UINT8;
|
||||
fitstype = TBYTE;
|
||||
break;
|
||||
case SHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TSHORT;
|
||||
break;
|
||||
case USHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TUSHORT;
|
||||
break;
|
||||
case ULONG_IMG:
|
||||
type = RawImage::UINT32;
|
||||
fitstype = TUINT;
|
||||
break;
|
||||
case FLOAT_IMG:
|
||||
type = RawImage::FLOAT32;
|
||||
fitstype = TFLOAT;
|
||||
break;
|
||||
case DOUBLE_IMG:
|
||||
type = RawImage::FLOAT64;
|
||||
fitstype = TDOUBLE;
|
||||
break;
|
||||
default:
|
||||
info.info.append({QObject::tr("Error"), QObject::tr("Unsupported sample format")});
|
||||
goto noload;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t size = naxes[0]*naxes[1];
|
||||
size_t w = naxes[0];
|
||||
size_t h = naxes[1];
|
||||
|
||||
info.info.append({QObject::tr("Width"), QString::number(naxes[0])});
|
||||
info.info.append({QObject::tr("Height"), QString::number(naxes[1])});
|
||||
|
||||
RawImage img(w, h, naxis == 2 ? 1 : naxes[2], type);
|
||||
uint8_t *data = static_cast<uint8_t*>(img.data());
|
||||
for (int i=1; i==1 || i<=naxes[2]; i++)
|
||||
{
|
||||
fpixel[2] = i;
|
||||
fits_read_pix(file, fitstype, fpixel, size, NULL, data + img.size() * RawImage::typeSize(type) * (i-1), NULL, &status);
|
||||
}
|
||||
if(fitstype == TSHORT)
|
||||
{
|
||||
uint16_t *s = static_cast<uint16_t*>(img.data());
|
||||
size_t size = img.size() * img.channels();
|
||||
for(size_t i=0; i<size; i++)
|
||||
s[i] -= INT16_MIN;
|
||||
}
|
||||
|
||||
if(img.channels() == 1 || planar)
|
||||
image = std::make_shared<RawImage>(std::move(img));
|
||||
else
|
||||
image = RawImage::fromPlanar(img);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
noload:
|
||||
if(file)
|
||||
loadFITSHeader(file, info);
|
||||
|
||||
if(image)
|
||||
{
|
||||
for(auto fits : info.fitsHeader)
|
||||
{
|
||||
if(fits.key == "ROWORDER" && fits.value == "BOTTOM-UP")
|
||||
image->flip();
|
||||
}
|
||||
}
|
||||
|
||||
fits_close_file(file, &status);
|
||||
if(status)
|
||||
{
|
||||
char err[100];
|
||||
fits_get_errstatus(status, err);
|
||||
info.info.append({QObject::tr("Error"), QString(err)});
|
||||
qDebug() << "Failed to load FITS file" << err;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadXISF(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &image, bool planar)
|
||||
{
|
||||
try
|
||||
{
|
||||
LibXISF::XISFReader xisf;
|
||||
xisf.open(path.toLocal8Bit().data());
|
||||
|
||||
const LibXISF::Image &xisfImage = xisf.getImage(0);
|
||||
|
||||
auto fitskeywords = xisfImage.fitsKeywords();
|
||||
for(auto fits : fitskeywords)
|
||||
{
|
||||
info.fitsHeader.append(fits);
|
||||
}
|
||||
auto imageproperties = xisfImage.imageProperties();
|
||||
for(auto prop : imageproperties)
|
||||
{
|
||||
info.fitsHeader.append(prop);
|
||||
}
|
||||
|
||||
info.wcs = std::make_shared<WCSDataT>(xisfImage.width(), xisfImage.height(), info.fitsHeader);
|
||||
info.info.append({QObject::tr("Width"), QString::number(xisfImage.width())});
|
||||
info.info.append({QObject::tr("Height"), QString::number(xisfImage.height())});
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
|
||||
RawImage::DataType type;
|
||||
switch(xisfImage.sampleFormat())
|
||||
{
|
||||
case LibXISF::Image::UInt8: type = RawImage::UINT8; break;
|
||||
case LibXISF::Image::UInt16: type = RawImage::UINT16; break;
|
||||
case LibXISF::Image::UInt32: type = RawImage::UINT32; break;
|
||||
case LibXISF::Image::Float32: type = RawImage::FLOAT32; break;
|
||||
case LibXISF::Image::Float64: type = RawImage::FLOAT64; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
LibXISF::Image tmpImage = xisfImage;
|
||||
tmpImage.convertPixelStorageTo(LibXISF::Image::Planar);
|
||||
if(tmpImage.colorSpace() == LibXISF::Image::ColorSpace::Gray)
|
||||
{
|
||||
image = std::make_shared<RawImage>(tmpImage.width(), tmpImage.height(), 1, type);
|
||||
std::memcpy(image->data(), tmpImage.imageData(), tmpImage.imageDataSize() / tmpImage.channelCount());
|
||||
image->setICCProfile(tmpImage.iccProfile());
|
||||
return true;
|
||||
}
|
||||
else if(tmpImage.channelCount() == 3 || tmpImage.channelCount() == 4)
|
||||
{
|
||||
if(planar)
|
||||
{
|
||||
image = std::make_shared<RawImage>(tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type);
|
||||
std::memcpy(image->data(), tmpImage.imageData(), tmpImage.imageDataSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
image = RawImage::fromPlanar(tmpImage.imageData(), tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type);
|
||||
}
|
||||
|
||||
image->setICCProfile(tmpImage.iccProfile());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (LibXISF::Error &err)
|
||||
{
|
||||
info.info.append(QPair<QString, QString>("Error", err.what()));
|
||||
qDebug() << "Failed to load XISF" << err.what();
|
||||
return false;
|
||||
}
|
||||
info.info.append({QObject::tr("Error"), QObject::tr("Unsupported sample format")});
|
||||
return false;
|
||||
}
|
||||
|
||||
void LoadRunable::run()
|
||||
{
|
||||
try
|
||||
@@ -462,95 +99,9 @@ void LoadRunable::run()
|
||||
}
|
||||
}
|
||||
|
||||
bool readFITSHeader(const QString &path, ImageInfoData &info)
|
||||
{
|
||||
fitsfile *fr;
|
||||
int status = 0;
|
||||
QString path2 = makeMaxPath(path);
|
||||
fits_open_diskfile(&fr, path2.toLocal8Bit().data(), READONLY, &status);
|
||||
|
||||
if(fr && status == 0)
|
||||
{
|
||||
status = loadFITSHeader(fr, info);
|
||||
fits_close_file(fr, &status);
|
||||
}
|
||||
return status == 0;
|
||||
}
|
||||
|
||||
bool readXISFHeader(const QString &path, ImageInfoData &info)
|
||||
{
|
||||
QString path2 = makeMaxPath(path);
|
||||
try
|
||||
{
|
||||
LibXISF::XISFReader xisf;
|
||||
xisf.open(path2.toLocal8Bit().data());
|
||||
const LibXISF::Image &image = xisf.getImage(0, false);
|
||||
|
||||
auto fitskeywords = image.fitsKeywords();
|
||||
for(auto fits : fitskeywords)
|
||||
{
|
||||
info.fitsHeader.append(fits);
|
||||
}
|
||||
|
||||
auto imageproperties = image.imageProperties();
|
||||
for(auto prop : imageproperties)
|
||||
{
|
||||
info.fitsHeader.append(prop);
|
||||
}
|
||||
info.wcs = std::make_shared<WCSDataT>(image.width(), image.height(), info.fitsHeader);
|
||||
if(!info.wcs->valid())info.wcs.reset();
|
||||
}
|
||||
catch (LibXISF::Error &err)
|
||||
{
|
||||
qDebug() << err.what();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &rawImage, bool planar)
|
||||
{
|
||||
bool ret = false;
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
if(path.endsWith(".CR2", Qt::CaseInsensitive) || path.endsWith(".CR3", Qt::CaseInsensitive) || path.endsWith(".NEF", Qt::CaseInsensitive) || path.endsWith(".DNG", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadRAW(path, info, rawImage);
|
||||
qDebug() << "LoadRAW" << timer.elapsed();
|
||||
}
|
||||
else if(path.endsWith(".FIT", Qt::CaseInsensitive) || path.endsWith(".FITS", Qt::CaseInsensitive) || path.endsWith(".FZ", Qt::CaseInsensitive) || path.endsWith(".FTS", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadFITS(path, info, rawImage, planar);
|
||||
qDebug() << "LoadFITS" << timer.elapsed();
|
||||
}
|
||||
else if(path.endsWith(".XISF", Qt::CaseInsensitive))
|
||||
{
|
||||
ret = loadXISF(path, info, rawImage, planar);
|
||||
qDebug() << "LoadXISF" << timer.elapsed();
|
||||
}
|
||||
else
|
||||
{
|
||||
QImage img(path);
|
||||
|
||||
ExifData *exif = exif_data_new_from_file(path.toLocal8Bit().constData());
|
||||
info.info.append({QObject::tr("Width"), QString::number(img.width())});
|
||||
info.info.append({QObject::tr("Height"), QString::number(img.height())});
|
||||
if(exif)
|
||||
{
|
||||
loadExifEntry(info, exif->ifd[EXIF_IFD_EXIF], EXIF_TAG_ISO_SPEED_RATINGS);
|
||||
loadExifEntry(info, exif->ifd[EXIF_IFD_EXIF], EXIF_TAG_SHUTTER_SPEED_VALUE);
|
||||
exif_data_free(exif);
|
||||
}
|
||||
rawImage = std::make_shared<RawImage>(img);
|
||||
qDebug() << "LoadQImage" << timer.elapsed();
|
||||
ret = !img.isNull();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ConvertRunable::ConvertRunable(const QString &in, const QString &out, const QString &format, const ConvertParams ¶ms, QSemaphore *semaphore) :
|
||||
m_infile(makeMaxPath(in)),
|
||||
m_outfile(makeMaxPath(out)),
|
||||
m_infile(makeUNCPath(in)),
|
||||
m_outfile(makeUNCPath(out)),
|
||||
m_format(format),
|
||||
m_params(params),
|
||||
m_semaphore(semaphore)
|
||||
@@ -640,6 +191,23 @@ void ConvertRunable::run()
|
||||
QFileInfo info(m_outfile);
|
||||
info.dir().mkpath(".");
|
||||
|
||||
if(m_params.autostretch)
|
||||
{
|
||||
rawimage->calcStats();
|
||||
MTFParam mtfParam = rawimage->calcMTFParams();
|
||||
rawimage->applySTF(mtfParam);
|
||||
}
|
||||
if(m_params.binning > 1)
|
||||
{
|
||||
rawimage->resizeInt(m_params.binning, m_params.average);
|
||||
}
|
||||
if(m_params.resize.isValid() && !m_params.resize.isEmpty())
|
||||
{
|
||||
QSize imgSize(rawimage->width(), rawimage->height());
|
||||
imgSize = imgSize.scaled(m_params.resize, m_params.aspect);
|
||||
rawimage->resize(imgSize.width(), imgSize.height());
|
||||
}
|
||||
|
||||
if(rawimage)
|
||||
{
|
||||
if(m_format == "xisf")
|
||||
@@ -725,7 +293,6 @@ void ConvertRunable::run()
|
||||
// if nothing else try QImage
|
||||
{
|
||||
QImage::Format format = QImage::Format_Invalid;
|
||||
int width = rawimage->widthBytes();
|
||||
|
||||
switch(rawimage->type())
|
||||
{
|
||||
@@ -738,7 +305,6 @@ void ConvertRunable::run()
|
||||
if(rawimage->channels() == 1)format = QImage::Format_Grayscale16;
|
||||
else if(rawimage->channels() == 3)format = QImage::Format_RGBX64;
|
||||
else if(rawimage->channels() == 4)format = QImage::Format_RGBA64;
|
||||
width *= 2;
|
||||
break;
|
||||
case RawImage::FLOAT16:
|
||||
case RawImage::FLOAT32:
|
||||
@@ -748,15 +314,12 @@ void ConvertRunable::run()
|
||||
if(rawimage->channels() == 1)format = QImage::Format_Grayscale16;
|
||||
else if(rawimage->channels() == 3)format = QImage::Format_RGBX64;
|
||||
else if(rawimage->channels() == 4)format = QImage::Format_RGBA64;
|
||||
width *= 2;
|
||||
break;
|
||||
}
|
||||
|
||||
if(format == QImage::Format_Invalid)return;
|
||||
|
||||
QImage qimage(rawimage->width(), rawimage->height(), format);
|
||||
for(uint32_t i=0; i < rawimage->height(); i++)
|
||||
std::memcpy(qimage.scanLine(i), rawimage->data(i), width);
|
||||
QImage qimage((const uchar*)rawimage->data(), rawimage->width(), rawimage->height(), rawimage->widthBytes(), format);
|
||||
qimage.save(m_outfile);
|
||||
}
|
||||
}
|
||||
@@ -772,4 +335,34 @@ ConvertRunable::ConvertParams::ConvertParams(const QVariantMap &map)
|
||||
|
||||
if(map.contains("compressionType"))
|
||||
compressionType = map["compressionType"].toString();
|
||||
|
||||
if(map.contains("binning"))
|
||||
binning = map["binning"].toInt();
|
||||
|
||||
if(map.contains("average"))
|
||||
average = map["average"].toBool();
|
||||
|
||||
if(map.contains("resize"))
|
||||
{
|
||||
QVariantMap size = map["resize"].toMap();
|
||||
if(size.contains("width") && size.contains("height"))
|
||||
{
|
||||
int w = size["width"].toInt();
|
||||
int h = size["height"].toInt();
|
||||
resize = QSize(w, h);
|
||||
}
|
||||
if(size.contains("aspect"))
|
||||
{
|
||||
QString aspectStr = map["aspect"].toString();
|
||||
if(aspectStr == "keep")
|
||||
aspect = Qt::KeepAspectRatio;
|
||||
else if(aspectStr == "expand")
|
||||
aspect = Qt::KeepAspectRatioByExpanding;
|
||||
else if(aspectStr == "ignore")
|
||||
aspect = Qt::IgnoreAspectRatio;
|
||||
}
|
||||
}
|
||||
|
||||
if(map.contains("autostretch"))
|
||||
autostretch = map["autostretch"].toBool();
|
||||
}
|
||||
|
||||
+7
-9
@@ -4,14 +4,8 @@
|
||||
#include <QRunnable>
|
||||
#include <QString>
|
||||
#include <QSemaphore>
|
||||
#include "imageinfo.h"
|
||||
|
||||
class RawImage;
|
||||
|
||||
QString makeMaxPath(QString path);
|
||||
bool readFITSHeader(const QString &path, ImageInfoData &info);
|
||||
bool readXISFHeader(const QString &path, ImageInfoData &info);
|
||||
bool loadImage(const QString &path, ImageInfoData &info, std::shared_ptr<RawImage> &rawImage, bool planar = false);
|
||||
#include <QSize>
|
||||
#include "imageinfodata.h"
|
||||
|
||||
class Image;
|
||||
|
||||
@@ -26,7 +20,6 @@ public:
|
||||
void run() override;
|
||||
};
|
||||
|
||||
|
||||
class ConvertRunable : public QRunnable
|
||||
{
|
||||
public:
|
||||
@@ -34,6 +27,11 @@ public:
|
||||
{
|
||||
int compressionLevel = -1;
|
||||
QString compressionType;
|
||||
int binning = 0;
|
||||
bool average = true;
|
||||
QSize resize;
|
||||
Qt::AspectRatioMode aspect = Qt::KeepAspectRatio;
|
||||
bool autostretch = false;
|
||||
ConvertParams(){}
|
||||
ConvertParams(const QVariantMap &map);
|
||||
};
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
#include <QApplication>
|
||||
#include <QSurfaceFormat>
|
||||
#include <QTranslator>
|
||||
#include <QCommandLineParser>
|
||||
#include <stdlib.h>
|
||||
#include "thumbnailer/genthumbnail.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -15,12 +17,39 @@ int main(int argc, char *argv[])
|
||||
#else
|
||||
bool useGLES = true;
|
||||
#endif
|
||||
|
||||
QCommandLineParser cmd;
|
||||
cmd.addOption({"gl", "Use desktop OpenGL. This is default on x86 and MacOS platform."});
|
||||
cmd.addOption({"gles", "Use OpenGL ES. This is default on ARM platform."});
|
||||
cmd.addOption({{"thumb", "thumbnail"}, "Generate thumbnail and save it to path.", "path"});
|
||||
cmd.addOption({{"s", "size"}, "Size of the thumbnails in pixels (default: 128)", "size", "128"});
|
||||
cmd.addPositionalArgument("file", "File to open");
|
||||
cmd.addHelpOption();
|
||||
QStringList cmdArgs;
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
if(std::strcmp("-gl", argv[i]) == 0)
|
||||
cmdArgs.append(argv[i]);
|
||||
|
||||
cmd.process(cmdArgs);
|
||||
if(cmd.isSet("gl"))
|
||||
useGLES = false;
|
||||
if(std::strcmp("-gles", argv[i]) == 0)
|
||||
if(cmd.isSet("gles"))
|
||||
useGLES = true;
|
||||
|
||||
if(cmd.isSet("thumb"))
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
QStringList files = cmd.positionalArguments();
|
||||
if(files.size() == 0)
|
||||
return 1;
|
||||
|
||||
QString thumb = cmd.value("thumb");
|
||||
int size = 128;
|
||||
bool ok;
|
||||
int size2 = cmd.value("s").toInt(&ok);
|
||||
if(ok)
|
||||
size = size2;
|
||||
|
||||
return generateThumbnail(files.front(), thumb, size);
|
||||
}
|
||||
|
||||
QSurfaceFormat format;
|
||||
@@ -39,6 +68,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
|
||||
QApplication a(argc, argv);
|
||||
a.setOrganizationName("nou");
|
||||
a.setApplicationName("Tenmon");
|
||||
@@ -54,5 +84,22 @@ int main(int argc, char *argv[])
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
if(!cmd.positionalArguments().isEmpty())
|
||||
{
|
||||
QStringList files = cmd.positionalArguments();
|
||||
QStringList paths;
|
||||
for(auto &arg : files)
|
||||
{
|
||||
QUrl url(arg);
|
||||
QFileInfo info(url.isLocalFile() ? url.toLocalFile() : arg);
|
||||
if(info.exists())
|
||||
paths.append(info.canonicalFilePath());
|
||||
}
|
||||
if(paths.size() == 1)
|
||||
w.loadFile(paths.front());
|
||||
else if(paths.size() > 1)
|
||||
w.loadFiles(paths);
|
||||
}
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
+38
-18
@@ -167,7 +167,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
||||
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
||||
fileMenu->addAction(tr("Batch processing"), Qt::Key_B | Qt::CTRL, [this](){
|
||||
BatchProcessing *batchProcessing = new BatchProcessing(this);
|
||||
BatchProcessing *batchProcessing = new BatchProcessing(m_database, this);
|
||||
batchProcessing->exec();
|
||||
delete batchProcessing;
|
||||
});
|
||||
@@ -186,7 +186,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
viewMenu->addAction(tr("Zoom In"), QKeySequence::ZoomIn, m_image, &ImageScrollArea::zoomIn);
|
||||
viewMenu->addAction(tr("Zoom Out"), QKeySequence::ZoomOut, m_image, &ImageScrollArea::zoomOut);
|
||||
viewMenu->addAction(tr("Best Fit"), QKeySequence("Ctrl+1"), m_image, &ImageScrollArea::bestFit);
|
||||
viewMenu->addAction(tr("100%"), m_image, &ImageScrollArea::oneToOne);
|
||||
viewMenu->addAction(tr("100%"), QKeySequence("Ctrl+0"), m_image, &ImageScrollArea::oneToOne);
|
||||
viewMenu->addSeparator();
|
||||
QMenu *bayerMenu = viewMenu->addMenu(tr("Bayer mask"));
|
||||
QActionGroup *bayerActionGroup = new QActionGroup(this);
|
||||
@@ -207,6 +207,29 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
settings.setValue("mainwindow/bayermask", data);
|
||||
});
|
||||
|
||||
QStringList colormaps = {"Autumn", "Bone", "Jet", "Winter", "Rainbow", "Ocean", "Summer", "Spring", "Cool", "HSV", "Pink", "Hot", "Parula", "Magma",
|
||||
"Inferno", "Plasma", "Viridis", "Cividis", "Twilight", "Twilight shifted", "Turbo", "Deepgreen"};
|
||||
QMenu *colormapMenu = viewMenu->addMenu(tr("Colormap"));
|
||||
QActionGroup *colormapActionGroup = new QActionGroup(this);
|
||||
|
||||
QImage cmImg = ImageWidget::loadColormap();
|
||||
for(int i=0; i<cmImg.height(); i++)
|
||||
{
|
||||
QImage icon = cmImg.copy(0, i, cmImg.width(), 1).scaled(32, 32);
|
||||
QAction *action = colormapActionGroup->addAction(i < colormaps.size() ? colormaps[i] : tr("User %1").arg(i - colormaps.size() + 1));
|
||||
action->setIcon(QPixmap::fromImage(icon));
|
||||
action->setCheckable(true); action->setData(i);
|
||||
colormapMenu->addAction(action);
|
||||
}
|
||||
viewMenu->addMenu(colormapMenu);
|
||||
connect(colormapActionGroup, &QActionGroup::triggered, [this](QAction *action){
|
||||
int data = action->data().toInt();
|
||||
m_image->setColormap(data);
|
||||
QSettings settings;
|
||||
settings.setValue("mainwindow/colormap", data);
|
||||
});
|
||||
|
||||
|
||||
QAction *thumbnailsAction = viewMenu->addAction(tr("Thumbnails"), Qt::Key_F2, [this](bool checked){
|
||||
if(SettingsDialog::loadThumbsizes())m_ringList->clearThumbnails();
|
||||
m_image->allocateThumbnails(m_ringList->imageNames());
|
||||
@@ -291,6 +314,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
case 3:
|
||||
bggrAction->setChecked(true); break;
|
||||
}
|
||||
int colormap = settings.value("mainwindow/colormap", 4).toInt();
|
||||
if(colormap >= 0 && colormap < colormapActionGroup->actions().size())
|
||||
colormapActionGroup->actions().at(colormap)->setChecked(true);
|
||||
|
||||
m_image->setBayerMask(bayermask);
|
||||
m_image->setColormap(colormap);
|
||||
|
||||
QStringList standardLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation);
|
||||
if(standardLocations.size())
|
||||
@@ -298,22 +327,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
||||
|
||||
_lastDir = settings.value("mainwindow/lastdir", _lastDir).toString();
|
||||
|
||||
QStringList args = QCoreApplication::arguments();
|
||||
args.removeFirst();
|
||||
for(auto &arg : args)
|
||||
{
|
||||
QUrl url(arg);
|
||||
QFileInfo info(url.isLocalFile() ? url.toLocalFile() : arg);
|
||||
if(info.exists())
|
||||
{
|
||||
m_ringList->setFile(info.canonicalFilePath());
|
||||
updateWindowTitle();
|
||||
_lastDir = info.absoluteDir().absolutePath();
|
||||
settings.setValue("mainwindow/lastdir", _lastDir);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_image->setFocus();
|
||||
|
||||
// workaround for nasty wayland backend bug https://bugreports.qt.io/browse/QTBUG-87332
|
||||
@@ -531,9 +544,16 @@ void MainWindow::loadFile(const QString &path)
|
||||
_lastDir = info.canonicalPath();
|
||||
QSettings settings;
|
||||
settings.setValue("mainwindow/lastdir", _lastDir);
|
||||
if(settings.value("settings/bestfit", false).toBool())
|
||||
m_image->bestFit();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::loadFiles(const QStringList &paths)
|
||||
{
|
||||
m_ringList->setFiles(paths);
|
||||
}
|
||||
|
||||
void MainWindow::loadFile(int row)
|
||||
{
|
||||
m_ringList->loadFile(row);
|
||||
|
||||
+2
-1
@@ -41,11 +41,12 @@ protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void copyOrMove(bool copy);
|
||||
void copyOrMove(bool copy, const QString &dest);
|
||||
protected slots:
|
||||
public slots:
|
||||
void socketNotify();
|
||||
void updateWindowTitle();
|
||||
void loadFile();
|
||||
void loadFile(const QString &path);
|
||||
void loadFiles(const QStringList &paths);
|
||||
void loadFile(int row);
|
||||
void loadDir();
|
||||
void indexDir();
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
#ifndef MTFPARAM_H
|
||||
#define MTFPARAM_H
|
||||
|
||||
struct MTFParam
|
||||
{
|
||||
float blackPoint[3] = {0.0f, 0.0f, 0.0f};
|
||||
float midPoint[3] = {0.5f, 0.5f, 0.5f};
|
||||
float whitePoint[3] = {1.0f, 1.0f, 1.0f};
|
||||
};
|
||||
|
||||
#endif // MTFPARAM_H
|
||||
+267
-13
@@ -1,12 +1,24 @@
|
||||
#include "rawimage.h"
|
||||
#include <QDebug>
|
||||
#include <cstring>
|
||||
#include <lcms2.h>
|
||||
#include <algorithm>
|
||||
#ifndef NO_QT
|
||||
#include <QDebug>
|
||||
#include <QElapsedTimer>
|
||||
#include <QFloat16>
|
||||
#include <QColorSpace>
|
||||
#include <lcms2.h>
|
||||
|
||||
using F16 = qfloat16;
|
||||
#else
|
||||
#define __STDC_WANT_IEC_60559_TYPES_EXT__
|
||||
#include <float.h>
|
||||
#ifdef FLT16_MAX
|
||||
using F16 = _Float16;
|
||||
#else
|
||||
#include "tfloat16.h"
|
||||
using F16 = TFloat16;// this is only for MXE
|
||||
#endif // FLT16_MAX
|
||||
|
||||
#endif // NO_QT
|
||||
|
||||
int THUMB_SIZE = 128;
|
||||
int THUMB_SIZE_BORDER = 138;
|
||||
@@ -78,6 +90,7 @@ RawImage::RawImage(RawImage &&d)
|
||||
m_thumbAspect = d.m_thumbAspect;
|
||||
}
|
||||
|
||||
#ifndef NO_QT
|
||||
RawImage::RawImage(const QImage &img)
|
||||
{
|
||||
qDebug() << img;
|
||||
@@ -145,6 +158,7 @@ RawImage::RawImage(const QImage &img)
|
||||
}
|
||||
m_stats.m_stats = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
const RawImage::Stats& RawImage::imageStats() const
|
||||
{
|
||||
@@ -184,7 +198,7 @@ void calcStats(const T *data, size_t n, size_t w, RawImage::Stats &stats)
|
||||
auto findMedian = [histSize](std::vector<uint32_t> &histogram, size_t n) -> size_t
|
||||
{
|
||||
size_t histSum = 0;
|
||||
for(size_t o=0; o < histSize; o++)
|
||||
for(size_t o=1; o < histSize; o++)
|
||||
{
|
||||
histSum += histogram[o];
|
||||
if(histSum >= n/2)
|
||||
@@ -225,6 +239,57 @@ void calcStats(const T *data, size_t n, size_t w, RawImage::Stats &stats)
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr(std::is_floating_point_v<T>)
|
||||
{
|
||||
T mmin = *std::min_element(min, min + 4);
|
||||
T mmax = *std::max_element(max, max + 4);
|
||||
|
||||
T a = 1.0 / (mmax - mmin);
|
||||
T b = -mmin / (mmax - mmin);
|
||||
|
||||
auto histFunc = [&](T d, int x)
|
||||
{
|
||||
uint16_t idx = std::clamp((T)(d * a + b) * histSize, (T)0.0, (T)65535.0);
|
||||
histogram[x][idx]++;
|
||||
};
|
||||
|
||||
// calculate histogram again
|
||||
if(mmin < 0.0 || mmax > 1.0)
|
||||
{
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
histogram[i].clear();
|
||||
histogram[i].resize(histSize, 0);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < n; i++)
|
||||
{
|
||||
histFunc(data[i*ch], 0);
|
||||
if constexpr(ch >= 3)
|
||||
{
|
||||
histFunc(data[i*ch + 1], 1);
|
||||
histFunc(data[i*ch + 2], 2);
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr(ch == 1)
|
||||
{
|
||||
size_t h = (n / w) & (SIZE_MAX-1);
|
||||
w &= (SIZE_MAX-1);
|
||||
for(size_t y=0; y<h; y+=2)
|
||||
{
|
||||
for(size_t x=0; x<w; x+=2)
|
||||
{
|
||||
histFunc(data[y*w+x], 1);
|
||||
histFunc(data[y*w+x+1], 2);
|
||||
histFunc(data[(y+1)*w+x], 2);
|
||||
histFunc(data[(y+1)*w+x+1], 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
stats.m_min[i] = min[i];
|
||||
@@ -234,7 +299,8 @@ void calcStats(const T *data, size_t n, size_t w, RawImage::Stats &stats)
|
||||
double sum2 = (double)sum[i] * sum[i];
|
||||
stats.m_stdDev[i] = std::sqrt((sumSq[i] - sum2 / na[i]) / (na[i] - 1));
|
||||
|
||||
uint32_t median = findMedian(histogram[i], na[i]);
|
||||
size_t naclip = na[i] - histogram[i][0];
|
||||
uint32_t median = findMedian(histogram[i], naclip);
|
||||
stats.m_median[i] = median;
|
||||
std::vector<uint32_t> madHist(histSize, 0);
|
||||
madHist[0] = histogram[i][median];
|
||||
@@ -243,7 +309,7 @@ void calcStats(const T *data, size_t n, size_t w, RawImage::Stats &stats)
|
||||
if(median + o < histSize)madHist[o] += histogram[i][median + o];
|
||||
if(o <= median)madHist[o] += histogram[i][median - o];
|
||||
}
|
||||
stats.m_mad[i] = findMedian(madHist, na[i]);
|
||||
stats.m_mad[i] = findMedian(madHist, naclip);
|
||||
if constexpr(!std::numeric_limits<T>::is_integer)
|
||||
{
|
||||
stats.m_median[i] /= 65535.0;
|
||||
@@ -338,6 +404,11 @@ uint32_t RawImage::norm() const
|
||||
}
|
||||
|
||||
uint32_t RawImage::widthBytes() const
|
||||
{
|
||||
return m_ch * m_width * typeSize(m_type);
|
||||
}
|
||||
|
||||
uint32_t RawImage::widthSamples() const
|
||||
{
|
||||
return m_ch * m_width;
|
||||
}
|
||||
@@ -408,14 +479,26 @@ void RawImage::convertToThumbnail()
|
||||
|
||||
if(m_channels == 1)
|
||||
{
|
||||
if(scale == 1.0f)
|
||||
out[idx] = out[idx + 1] = out[idx + 2] = (F16)(in[idx2]);
|
||||
else
|
||||
out[idx] = out[idx + 1] = out[idx + 2] = (F16)(in[idx2] * scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(scale == 1.0f)
|
||||
{
|
||||
out[idx] = (F16)(in[idx2]);
|
||||
out[idx + 1] = (F16)(in[idx2 + 1]);
|
||||
out[idx + 2] = (F16)(in[idx2 + 2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
out[idx] = (F16)(in[idx2] * scale);
|
||||
out[idx + 1] = (F16)(in[idx2 + 1] * scale);
|
||||
out[idx + 2] = (F16)(in[idx2 + 2] * scale);
|
||||
}
|
||||
}
|
||||
out[idx + 3] = (F16)1.0f;
|
||||
}
|
||||
}
|
||||
@@ -439,7 +522,9 @@ void RawImage::convertToThumbnail()
|
||||
loop(out, reinterpret_cast<float*>(m_pixels.get()), 1.0f);
|
||||
break;
|
||||
default:
|
||||
#ifndef NO_QT
|
||||
qWarning() << "FLOAT64 should not happend";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -488,9 +573,9 @@ void convertType2(size_t size, const T *src, U *dst)
|
||||
|
||||
if constexpr(std::is_integral_v<T> && (std::is_floating_point_v<U> || std::is_same_v<U, F16>))
|
||||
{
|
||||
U scale = (U)(1.0 / (double)std::numeric_limits<T>::max());
|
||||
float scale = (float)(1.0 / (double)std::numeric_limits<T>::max());
|
||||
for(size_t i = 0; i < size; i++)
|
||||
dst[i] = (U)src[i] * scale;
|
||||
dst[i] = (U)(src[i] * scale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,6 +831,64 @@ void RawImage::resize(uint32_t w, uint32_t h)
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T, typename U>
|
||||
void integerResample(uint32_t w, uint32_t h, uint32_t ch, uint32_t oldw, uint32_t down, bool avg, const uint8_t *in_, uint8_t *out_)
|
||||
{
|
||||
const T *in = reinterpret_cast<const T*>(in_);
|
||||
T *out = reinterpret_cast<T*>(out_);
|
||||
const uint32_t down2 = down * down;
|
||||
|
||||
U m = std::numeric_limits<T>::max();
|
||||
if constexpr(std::is_floating_point_v<T>)m = down2;
|
||||
|
||||
for(uint64_t i = 0; i < h; i++)
|
||||
{
|
||||
for(uint64_t o = 0; o < w; o++)
|
||||
{
|
||||
for(uint64_t p = 0; p < ch; p++)
|
||||
{
|
||||
U pix = 0;
|
||||
for(uint32_t y = 0; y < down; y++)
|
||||
for(uint32_t x = 0; x < down; x++)
|
||||
pix += in[((i * down) + y) * oldw * ch + ((o * down) + x) * ch + p];
|
||||
|
||||
if (avg)
|
||||
out[(i * w + o) * ch + p] = pix / down2;
|
||||
else
|
||||
out[(i * w + o) * ch + p] = std::min(pix, m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RawImage::resizeInt(int downsample, bool avg)
|
||||
{
|
||||
uint32_t oldw = m_width;
|
||||
std::unique_ptr<PixelType[]> old_pixels = std::move(m_pixels);
|
||||
allocate(m_width / downsample, m_height / downsample, m_channels, m_type);
|
||||
|
||||
switch(m_type)
|
||||
{
|
||||
case RawImage::UINT8:
|
||||
integerResample<uint8_t, uint32_t>(m_width, m_height, m_ch, oldw, downsample, avg, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
case RawImage::UINT16:
|
||||
integerResample<uint16_t, uint32_t>(m_width, m_height, m_ch, oldw, downsample, avg, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
case RawImage::UINT32:
|
||||
integerResample<uint32_t, uint64_t>(m_width, m_height, m_ch, oldw, downsample, avg, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
case RawImage::FLOAT32:
|
||||
integerResample<float, double>(m_width, m_height, m_ch, oldw, downsample, avg, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
case RawImage::FLOAT64:
|
||||
integerResample<double, double>(m_width, m_height, m_ch, oldw, downsample, avg, old_pixels.get(), m_pixels.get());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<float, float> RawImage::unitScale() const
|
||||
{
|
||||
float min = *std::min_element(m_stats.m_min, m_stats.m_min + 4);
|
||||
@@ -758,7 +901,7 @@ std::pair<float, float> RawImage::unitScale() const
|
||||
}
|
||||
|
||||
if(min < 0.0f || max > 1.0f)
|
||||
return {1.0f / (max - min), min / (max - min)};
|
||||
return {1.0f / (max - min), -min / (max - min)};
|
||||
else
|
||||
return {1.0f, 0.0f};
|
||||
}
|
||||
@@ -922,11 +1065,13 @@ bool RawImage::valid() const
|
||||
return m_width > 0 && m_height > 0;
|
||||
}
|
||||
|
||||
#ifndef NO_QT
|
||||
void RawImage::setICCProfile(const QByteArray &icc)
|
||||
{
|
||||
if(icc.size())
|
||||
m_iccProfile = std::vector<uint8_t>(icc.begin(), icc.end());
|
||||
}
|
||||
#endif
|
||||
|
||||
void RawImage::setICCProfile(const LibXISF::ByteArray &icc)
|
||||
{
|
||||
@@ -973,12 +1118,12 @@ void RawImage::convertTosRGB()
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed to create color transform";
|
||||
//qDebug() << "Failed to create color transform";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed to open icc profile";
|
||||
//qDebug() << "Failed to open icc profile";
|
||||
}
|
||||
|
||||
cmsCloseProfile(inProfile);
|
||||
@@ -1022,13 +1167,13 @@ void RawImage::generateLUT()
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed to create color transform";
|
||||
//qDebug() << "Failed to create color transform";
|
||||
m_lut.clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Failed to open icc profile";
|
||||
//qDebug() << "Failed to open icc profile";
|
||||
m_lut.clear();
|
||||
}
|
||||
|
||||
@@ -1036,6 +1181,115 @@ void RawImage::generateLUT()
|
||||
cmsCloseProfile(outProfile);
|
||||
}
|
||||
|
||||
void RawImage::applySTF(const MTFParam &mtfParams)
|
||||
{
|
||||
auto applyMTF = [&](auto *src) -> void
|
||||
{
|
||||
float s = 1.0f;
|
||||
if constexpr(std::numeric_limits<std::remove_reference_t<decltype(*src)>>::is_integer)
|
||||
s = (float)std::numeric_limits<std::remove_reference_t<decltype(*src)>>::max();
|
||||
|
||||
auto unit = unitScale();
|
||||
float iscale = 1.0f / s;
|
||||
size_t len = size() * m_ch;
|
||||
for(size_t i = 0; i < len; i++)
|
||||
{
|
||||
float x;
|
||||
if constexpr(std::numeric_limits<std::remove_reference_t<decltype(*src)>>::is_integer)x = src[i] * iscale;
|
||||
else x = src[i] * unit.first + unit.second;
|
||||
x = (x - mtfParams.blackPoint[0]) / (mtfParams.whitePoint[0] - mtfParams.blackPoint[0]);
|
||||
x = std::clamp(x, 0.0f, 1.0f);
|
||||
x = ((mtfParams.midPoint[0] - 1.0f) * x) / ((2.0f * mtfParams.midPoint[0] - 1.0f) * x - mtfParams.midPoint[0]);
|
||||
src[i] = x * s;
|
||||
}
|
||||
};
|
||||
|
||||
switch(m_type)
|
||||
{
|
||||
case UINT8:
|
||||
applyMTF(reinterpret_cast<uint8_t*>(m_pixels.get()));
|
||||
break;
|
||||
case UINT16:
|
||||
applyMTF(reinterpret_cast<uint16_t*>(m_pixels.get()));
|
||||
break;
|
||||
case UINT32:
|
||||
applyMTF(reinterpret_cast<uint32_t*>(m_pixels.get()));
|
||||
break;
|
||||
case FLOAT32:
|
||||
applyMTF(reinterpret_cast<float*>(m_pixels.get()));
|
||||
break;
|
||||
case FLOAT64:
|
||||
applyMTF(reinterpret_cast<double*>(m_pixels.get()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
MTFParam RawImage::calcMTFParams(bool linked, bool debayer) const
|
||||
{
|
||||
const float BLACK_POINT_SIGMA = -2.8f;
|
||||
const float MAD_TO_SIGMA = 1.4826f;
|
||||
const float TARGET_BACKGROUND = 0.25f;
|
||||
|
||||
auto MTF = [](float x, float m)
|
||||
{
|
||||
if(x < 0)return 0.0f;
|
||||
if(x > 1)return 1.0f;
|
||||
return ((m - 1) * x) / ((2 * m - 1) * x - m);
|
||||
};
|
||||
|
||||
MTFParam mtfParam;
|
||||
|
||||
int i = 0;
|
||||
int ch = m_channels;
|
||||
int o = 0;
|
||||
if(debayer)
|
||||
{
|
||||
i = 1;
|
||||
ch = 4;
|
||||
o = 1;
|
||||
}
|
||||
|
||||
float bp2 = 0;
|
||||
float mid2 = 0;
|
||||
float max2 = 0;
|
||||
for(; i < ch; i++)
|
||||
{
|
||||
double median, mad, max;
|
||||
median = m_stats.m_median[i];
|
||||
mad = m_stats.m_mad[i];
|
||||
median /= norm();
|
||||
bool a = median > 0.5 ? true : false;
|
||||
mad /= norm();
|
||||
max = 1.0f;
|
||||
float bp = a || mad == 0.0f ? 0.0f : std::clamp(median + mad * BLACK_POINT_SIGMA * MAD_TO_SIGMA, 0.0, 1.0);
|
||||
if(a && mad != 0.0f)
|
||||
max = std::clamp(median - mad * BLACK_POINT_SIGMA * MAD_TO_SIGMA, 0.0, 1.0);
|
||||
|
||||
float mid = !a ? MTF(median - bp, TARGET_BACKGROUND) : MTF(TARGET_BACKGROUND, max - median);
|
||||
mtfParam.blackPoint[i-o] = bp;
|
||||
mtfParam.midPoint[i-o] = mid;
|
||||
mtfParam.whitePoint[i-o] = max;
|
||||
bp2 += bp;
|
||||
mid2 += mid;
|
||||
max2 = max > max2 ? max : max2;
|
||||
}
|
||||
if(ch == 1)
|
||||
{
|
||||
mtfParam.blackPoint[1] = mtfParam.blackPoint[2] = mtfParam.blackPoint[0];
|
||||
mtfParam.midPoint[1] = mtfParam.midPoint[2] = mtfParam.midPoint[0];
|
||||
mtfParam.whitePoint[1] = mtfParam.whitePoint[2] = mtfParam.whitePoint[0];
|
||||
}
|
||||
if(linked)
|
||||
{
|
||||
mtfParam.blackPoint[0] = mtfParam.blackPoint[1] = mtfParam.blackPoint[2] = bp2 / ch;
|
||||
mtfParam.midPoint[0] = mtfParam.midPoint[1] = mtfParam.midPoint[2] = mid2 / ch;
|
||||
mtfParam.whitePoint[0] = mtfParam.whitePoint[1] = mtfParam.whitePoint[2] = max2;
|
||||
}
|
||||
return mtfParam;
|
||||
}
|
||||
|
||||
const std::vector<uint16_t> &RawImage::getLUT() const
|
||||
{
|
||||
return m_lut;
|
||||
|
||||
+11
@@ -7,7 +7,10 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#ifndef NO_QT
|
||||
#include <QImage>
|
||||
#endif
|
||||
#include "mtfparam.h"
|
||||
|
||||
extern int THUMB_SIZE;
|
||||
extern int THUMB_SIZE_BORDER;
|
||||
@@ -83,7 +86,9 @@ public:
|
||||
RawImage(uint32_t w, uint32_t h, uint32_t ch, DataType type);
|
||||
RawImage(const RawImage &d);
|
||||
RawImage(RawImage &&d);
|
||||
#ifndef NO_QT
|
||||
RawImage(const QImage &img);
|
||||
#endif
|
||||
const RawImage::Stats& imageStats() const;
|
||||
void calcStats();
|
||||
uint32_t width() const;
|
||||
@@ -93,6 +98,7 @@ public:
|
||||
DataType type() const;
|
||||
uint32_t norm() const;
|
||||
uint32_t widthBytes() const;
|
||||
uint32_t widthSamples() const;
|
||||
void* data();
|
||||
const void* data() const;
|
||||
void* data(uint32_t row, uint32_t col = 0);
|
||||
@@ -107,6 +113,7 @@ public:
|
||||
float thumbAspect() const;
|
||||
bool pixel(int x, int y, double &r, double &g, double &b) const;
|
||||
void resize(uint32_t w, uint32_t h);
|
||||
void resizeInt(int downsample, bool avg);
|
||||
std::pair<float, float> unitScale() const;
|
||||
void flip();
|
||||
|
||||
@@ -116,10 +123,14 @@ public:
|
||||
static size_t typeSize(DataType type);
|
||||
std::vector<RawImage> split() const;
|
||||
bool valid() const;
|
||||
#ifndef NO_QT
|
||||
void setICCProfile(const QByteArray &icc);
|
||||
#endif
|
||||
void setICCProfile(const LibXISF::ByteArray &icc);
|
||||
void convertTosRGB();
|
||||
void generateLUT();
|
||||
void applySTF(const MTFParam &mtfParams);
|
||||
MTFParam calcMTFParams(bool linked = false, bool debayer = false) const;
|
||||
const std::vector<uint16_t>& getLUT() const;
|
||||
|
||||
};
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#include "rawimage.h"
|
||||
|
||||
#ifdef __SSE2__
|
||||
#include <x86intrin.h>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
template<typename T, int ch>
|
||||
void fromPlanarSSE(const void *in, void *out, size_t count)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
@@ -16,14 +16,17 @@
|
||||
<file>grbg.png</file>
|
||||
<file>gbrg.png</file>
|
||||
<file>space.nouspiro.tenmon.png</file>
|
||||
<file>../translations/tenmon_pt_BR.qm</file>
|
||||
<file alias="help">../about/help_en</file>
|
||||
<file>colormap.png</file>
|
||||
</qresource>
|
||||
<qresource lang="en" prefix="/">
|
||||
<qresource prefix="/" lang="en">
|
||||
<file alias="help">../about/help_en</file>
|
||||
</qresource>
|
||||
<qresource lang="sk" prefix="/">
|
||||
<qresource prefix="/" lang="sk">
|
||||
<file alias="help">../about/help_sk</file>
|
||||
</qresource>
|
||||
<qresource lang="fr" prefix="/">
|
||||
<qresource prefix="/" lang="fr">
|
||||
<file alias="help">../about/help_fr</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
+18
-13
@@ -6,10 +6,10 @@
|
||||
#include <QJsonValue>
|
||||
#include "loadrunable.h"
|
||||
#include "rawimage.h"
|
||||
#include "loadrunable.h"
|
||||
#include "loadimage.h"
|
||||
#include "batchprocessing.h"
|
||||
#include <fitsio2.h>
|
||||
#include "libXISF/libxisf.h"
|
||||
#include "libxisf.h"
|
||||
#ifdef PLATESOLVER
|
||||
#include "solver.h"
|
||||
#endif // PLATESOLVER
|
||||
@@ -17,9 +17,9 @@
|
||||
namespace Script
|
||||
{
|
||||
|
||||
ScriptEngine::ScriptEngine(BatchProcessing *parent)
|
||||
ScriptEngine::ScriptEngine(Database *database, BatchProcessing *parent)
|
||||
: _jsEngine(new QJSEngine(this))
|
||||
, _database(new Database(this))
|
||||
, _database(database)
|
||||
, _parent(parent)
|
||||
, _pool(new QThreadPool(this))
|
||||
{
|
||||
@@ -27,7 +27,6 @@ ScriptEngine::ScriptEngine(BatchProcessing *parent)
|
||||
_jsEngine->globalObject().setProperty("core", core);
|
||||
QJSValue fitsRecordObject = _jsEngine->newQMetaObject(&FITSRecordModify::staticMetaObject);
|
||||
_jsEngine->globalObject().setProperty("FITSRecordModify", fitsRecordObject);
|
||||
_database->init(QLatin1String("scriptengine"));
|
||||
_semaphore.release(_pool->maxThreadCount());
|
||||
_pool->setThreadPriority(QThread::LowPriority);
|
||||
|
||||
@@ -73,17 +72,22 @@ void ScriptEngine::log(const QString &message)
|
||||
|
||||
void ScriptEngine::mark(File *file)
|
||||
{
|
||||
_database->mark(file->absoluteFilePath());
|
||||
QString path = file->absoluteFilePath();
|
||||
QMetaObject::invokeMethod(_database, [this, path](){ _database->mark(path); }, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void ScriptEngine::unmark(File *file)
|
||||
{
|
||||
_database->unmark(file->absoluteFilePath());
|
||||
QString path = file->absoluteFilePath();
|
||||
QMetaObject::invokeMethod(_database, [this, path](){ _database->unmark(path); }, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
bool ScriptEngine::isMarked(const File *file) const
|
||||
bool ScriptEngine::isMarked(const File *file)
|
||||
{
|
||||
return _database->isMarked(file->absoluteFilePath());
|
||||
bool ret;
|
||||
QString path = file->absoluteFilePath();
|
||||
QMetaObject::invokeMethod(_database, [this, path](){ return _database->isMarked(path); }, Qt::BlockingQueuedConnection, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ScriptEngine::setMaxThread(int maxthread)
|
||||
@@ -166,6 +170,7 @@ bool ScriptEngine::convert(File *file, QString &outpath, const QString &format,
|
||||
#ifdef PLATESOLVER
|
||||
void ScriptEngine::setSolverProfile(int index)
|
||||
{
|
||||
index -= 1;
|
||||
if(_solver && index >= SSolver::Parameters::DEFAULT && index < SSolver::Parameters::BIG_STARS)
|
||||
{
|
||||
_solver->setParameters((SSolver::Parameters::ParametersProfile)index);
|
||||
@@ -519,7 +524,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
||||
{
|
||||
fitsfile *file;
|
||||
int status = 0;
|
||||
QString path = makeMaxPath(_path);
|
||||
QString path = makeUNCPath(_path);
|
||||
fits_open_diskfile(&file, path.toLocal8Bit().data(), READWRITE, &status);
|
||||
int num = 0;
|
||||
fits_get_num_hdus(file, &num, &status);
|
||||
@@ -643,7 +648,7 @@ bool File::modifyFITSRecords(const FITSRecordModify *modify)
|
||||
try
|
||||
{
|
||||
LibXISF::XISFModify modifyXISF;
|
||||
QString in = makeMaxPath(absoluteFilePath());
|
||||
QString in = makeUNCPath(absoluteFilePath());
|
||||
QString out = in + "~";
|
||||
modifyXISF.open(in.toLocal8Bit().data());
|
||||
qDebug() << "modify" << in << out;
|
||||
@@ -764,11 +769,11 @@ QJSValue File::extractStars(bool hfr)
|
||||
}
|
||||
#endif // PLATESOLVER
|
||||
|
||||
ScriptEngineThread::ScriptEngineThread(BatchProcessing *parent) : QObject(parent)
|
||||
ScriptEngineThread::ScriptEngineThread(Database *database, BatchProcessing *parent) : QObject(parent)
|
||||
{
|
||||
_thread = new QThread();
|
||||
_thread->setObjectName("ScriptEngine");
|
||||
_engine = new ScriptEngine(parent);
|
||||
_engine = new ScriptEngine(database, parent);
|
||||
_engine->moveToThread(_thread);
|
||||
connect(_engine, &ScriptEngine::finished, _thread, &QThread::quit);
|
||||
connect(_engine, &ScriptEngine::newMessage, this, &ScriptEngineThread::newMessage);
|
||||
|
||||
+3
-3
@@ -31,7 +31,7 @@ class ScriptEngine : public QObject
|
||||
QList<QPair<QString, QString>> _paths;
|
||||
Solver *_solver = nullptr;
|
||||
public:
|
||||
explicit ScriptEngine(BatchProcessing *parent = nullptr);
|
||||
explicit ScriptEngine(Database *database, BatchProcessing *parent = nullptr);
|
||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
||||
void reportError(const QString &message);
|
||||
const QString& outputDir() const;
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
Q_INVOKABLE void log(const QString &message);
|
||||
Q_INVOKABLE void mark(File *file);
|
||||
Q_INVOKABLE void unmark(File *file);
|
||||
Q_INVOKABLE bool isMarked(const File *file) const;
|
||||
Q_INVOKABLE bool isMarked(const File *file);
|
||||
Q_INVOKABLE void setMaxThread(int maxthread);
|
||||
Q_INVOKABLE void sync();
|
||||
Q_INVOKABLE QJSValue getString(const QString &label = QString(), const QString &text = QString()) const;
|
||||
@@ -71,7 +71,7 @@ class ScriptEngineThread : public QObject
|
||||
QThread *_thread;
|
||||
ScriptEngine *_engine;
|
||||
public:
|
||||
ScriptEngineThread(BatchProcessing *parent = nullptr);
|
||||
ScriptEngineThread(Database *database, BatchProcessing *parent = nullptr);
|
||||
~ScriptEngineThread();
|
||||
void setParams(const QString &scriptPath, const QList<QPair<QString, QString>> &paths, const QString &outputDir);
|
||||
void start();
|
||||
|
||||
@@ -4,11 +4,18 @@
|
||||
#include <QLabel>
|
||||
#include <QSettings>
|
||||
#include <QApplication>
|
||||
#include <QProcess>
|
||||
#include <QCoreApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QDir>
|
||||
#include <QPushButton>
|
||||
#include "rawimage.h"
|
||||
|
||||
extern int DEFAULT_WIDTH;
|
||||
extern double SATURATION;
|
||||
extern int FILTERING;
|
||||
extern bool BESTFIT;
|
||||
|
||||
class EvenNumber : public QSpinBox
|
||||
{
|
||||
@@ -75,6 +82,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
|
||||
m_qualityThumbnail->setChecked(QUALITY_RESIZE);
|
||||
m_qualityThumbnail->setToolTip(tr("Use box filter when downsampling thumbnails instead of nearest. Slightly slower."));
|
||||
|
||||
m_bestFit = new QCheckBox(tr("Best Fit on image load"));
|
||||
m_bestFit->setToolTip(tr("Set Best Fit zoom level when opening new image."));
|
||||
m_bestFit->setChecked(BESTFIT);
|
||||
|
||||
|
||||
layout->addRow(tr("Image preload count"), m_preloadImages);
|
||||
layout->addRow(tr("Thumbnails size"), m_thumSize);
|
||||
layout->addRow(tr("Saturation"), m_saturation);
|
||||
@@ -82,8 +94,17 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
|
||||
layout->addRow(tr("Image interpolation"), m_filtering);
|
||||
layout->addRow(m_qualityThumbnail);
|
||||
layout->addRow(m_useNativeDialog);
|
||||
layout->addRow(m_bestFit);
|
||||
|
||||
#ifdef Q_OS_WIN64
|
||||
QPushButton *installThumbnailer = new QPushButton(tr("Install"), this);
|
||||
installThumbnailer->setToolTip(tr("This will install thumnail generation for FITS and XISF files in File Explorer"));
|
||||
connect(installThumbnailer, &QPushButton::clicked, this, &SettingsDialog::installThumbnailer);
|
||||
layout->addRow(tr("Install thumbnailer"), installThumbnailer);
|
||||
#endif
|
||||
//layout->addRow(new QLabel(tr("Changes in settings will take effect after program restart.")));
|
||||
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
||||
buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
@@ -103,6 +124,7 @@ void SettingsDialog::loadSettings()
|
||||
SATURATION = settings.value("settings/saturation", 95.0).toDouble() / 100.0;
|
||||
FILTERING = settings.value("settings/filtering", FILTERING).toInt();
|
||||
QUALITY_RESIZE = settings.value("settings/qualitythumbnail", QUALITY_RESIZE).toBool();
|
||||
BESTFIT = settings.value("settings/bestfit", BESTFIT).toBool();
|
||||
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, settings.value("settings/dontusenativedialogs", false).toBool());
|
||||
}
|
||||
|
||||
@@ -116,6 +138,25 @@ bool SettingsDialog::loadThumbsizes()
|
||||
return OLD_THUMB_SIZE != THUMB_SIZE;
|
||||
}
|
||||
|
||||
void SettingsDialog::installThumbnailer()
|
||||
{
|
||||
#ifdef Q_OS_WIN64
|
||||
QString path = QCoreApplication::instance()->applicationDirPath() + "/tenmonthumbnailer.dll";
|
||||
if(!QFileInfo::exists(path))
|
||||
{
|
||||
QMessageBox::critical(this, tr("Missing dll"), tr("Can't find ") + path);
|
||||
return;
|
||||
}
|
||||
|
||||
QProcess regsvr;
|
||||
int ret = regsvr.execute("regsvr32.exe", {"/s", path});
|
||||
if(ret)
|
||||
{
|
||||
QMessageBox::critical(this, tr("Error"), tr("Failed to register thumbnailer. %1").arg(ret));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void SettingsDialog::saveSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
@@ -127,7 +168,9 @@ void SettingsDialog::saveSettings()
|
||||
settings.setValue("settings/qualitythumbnail", m_qualityThumbnail->isChecked());
|
||||
QUALITY_RESIZE = m_qualityThumbnail->isChecked();
|
||||
FILTERING = m_filtering->currentIndex();
|
||||
BESTFIT = m_bestFit->isChecked();
|
||||
settings.setValue("settings/filtering", FILTERING);
|
||||
settings.setValue("settings/bestfit", BESTFIT);
|
||||
SATURATION = m_saturation->value() / 100.0;
|
||||
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs, m_useNativeDialog->isChecked());
|
||||
if(DEFAULT_WIDTH != m_preloadImages->value())
|
||||
|
||||
@@ -13,6 +13,8 @@ public:
|
||||
explicit SettingsDialog(QWidget *parent = nullptr);
|
||||
static void loadSettings();
|
||||
static bool loadThumbsizes();
|
||||
public slots:
|
||||
void installThumbnailer();
|
||||
signals:
|
||||
void preloadChanged(int witdth);
|
||||
private:
|
||||
@@ -25,6 +27,7 @@ private:
|
||||
QCheckBox *m_useNativeDialog;
|
||||
QCheckBox *m_qualityThumbnail;
|
||||
QComboBox *m_filtering;
|
||||
QCheckBox *m_bestFit;
|
||||
};
|
||||
|
||||
#endif // SETTINGSDIALOG_H
|
||||
|
||||
+5
-11
@@ -1,5 +1,6 @@
|
||||
uniform sampler2D qt_Texture0;
|
||||
uniform sampler3D lut_table;
|
||||
uniform sampler2DArray colormap;
|
||||
uniform vec3 mtf_param[3];
|
||||
uniform vec2 unit_scale;
|
||||
uniform bool bw;
|
||||
@@ -7,6 +8,7 @@ uniform bool invert;
|
||||
uniform bool srgb;
|
||||
uniform bool false_color;
|
||||
uniform int filtering;
|
||||
uniform int colormapIdx;
|
||||
in vec2 qt_TexCoord0;
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
@@ -26,17 +28,9 @@ vec4 MTF(vec4 x, vec4 low, vec4 mid, vec4 high)
|
||||
|
||||
vec3 falsecolor(float color)
|
||||
{
|
||||
const vec3 pallete[] = vec3[](
|
||||
vec3(1.0, 0.0, 1.0), //magneta
|
||||
vec3(0.0, 0.0, 1.0), //blue
|
||||
vec3(0.0, 1.0, 1.0), //cyan
|
||||
vec3(0.0, 1.0, 0.0), //green
|
||||
vec3(1.0, 1.0, 0.0), //yellow
|
||||
vec3(1.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0));//red
|
||||
color *= 5.0;
|
||||
int i = int(color);
|
||||
float f = fract(color);
|
||||
return mix(pallete[i], pallete[i+1], f);// * (f * 0.5 + 0.5);
|
||||
color *= 255.0 / 256.0;
|
||||
color += 0.5 / 256.0;
|
||||
return texture(colormap, vec3(color, 0.5, colormapIdx)).rgb;
|
||||
}
|
||||
|
||||
vec3 checker()
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
#include <wcslib/wcshdr.h>
|
||||
#include <wcslib/wcsutil.h>
|
||||
#include "rawimage.h"
|
||||
#include "loadrunable.h"
|
||||
#include "loadimage.h"
|
||||
#include "scriptengine.h"
|
||||
|
||||
Solver::Solver(QObject *parent) : QObject(parent)
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
<li>Convert CFA images to colour - debayer</li>
|
||||
<li>Color space aware</li>
|
||||
<li>Histogram</li>
|
||||
<li>Scripting</li>
|
||||
</ul>
|
||||
</description>
|
||||
<categories>
|
||||
@@ -57,6 +58,26 @@
|
||||
</screenshots>
|
||||
<content_rating type="oars-1.1"/>
|
||||
<releases>
|
||||
<release version="20250318" date="2025-03-18">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Fix OpenGL ES drawings</li>
|
||||
<li>Fix mark/unmark files from script</li>
|
||||
<li>Fix stretching of float images with values outside of 0-1 range</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="20250302" date="2025-03-02">
|
||||
<description>
|
||||
<ul>
|
||||
<li>Add resize and binning to script</li>
|
||||
<li>Auto stretch to script</li>
|
||||
<li>Fix opening UNC paths starting</li>
|
||||
<li>Add more color maps for false color</li>
|
||||
<li>Open image with best fit</li>
|
||||
</ul>
|
||||
</description>
|
||||
</release>
|
||||
<release version="20250126" date="2025-01-26">
|
||||
<description>
|
||||
<ul>
|
||||
|
||||
-299
@@ -1,299 +0,0 @@
|
||||
#include "starfit.h"
|
||||
#include <gsl/gsl_blas.h>
|
||||
#include <QDebug>
|
||||
#include <iostream>
|
||||
|
||||
const int PARAM_AM = 0;
|
||||
const int PARAM_X0 = 1;
|
||||
const int PARAM_Y0 = 2;
|
||||
const int PARAM_SX = 3;
|
||||
const int PARAM_SY = 4;
|
||||
const int PARAM_TH = 5;
|
||||
|
||||
const int MAX_ITER = 20;
|
||||
const double TOL = 1.0e-3;
|
||||
|
||||
struct StarData
|
||||
{
|
||||
size_t size;
|
||||
std::vector<double> val;
|
||||
};
|
||||
|
||||
// a * exp(-0.5*((x-x0)/sx)^2 + ((y-y0)/sy)^2)
|
||||
double gauss_model(double a, double x0, double y0, double sx, double sy, double x, double y)
|
||||
{
|
||||
double _x = (x-x0)/sx;
|
||||
double _y = (y-y0)/sy;
|
||||
return a*exp(-0.5*(_x*_x + _y*_y));
|
||||
}
|
||||
|
||||
int func_f(const gsl_vector *X, void *params, gsl_vector *f)
|
||||
{
|
||||
StarData *d = static_cast<StarData*>(params);
|
||||
double am = gsl_vector_get(X, PARAM_AM);
|
||||
double x0 = gsl_vector_get(X, PARAM_X0);
|
||||
double y0 = gsl_vector_get(X, PARAM_Y0);
|
||||
double sx = gsl_vector_get(X, PARAM_SX);
|
||||
double sy = gsl_vector_get(X, PARAM_SY);
|
||||
|
||||
int i = 0;
|
||||
for(size_t y=0;y<d->size;y++)
|
||||
{
|
||||
for(size_t x=0;x<d->size;x++)
|
||||
{
|
||||
double v = gauss_model(am, x0, y0, sx, sy, x, y);
|
||||
gsl_vector_set(f, i, d->val[i] - v);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return GSL_SUCCESS;
|
||||
}
|
||||
|
||||
int func_df(const gsl_vector *X, void *params, gsl_matrix *J)
|
||||
{
|
||||
StarData *d = static_cast<StarData*>(params);
|
||||
double am = gsl_vector_get(X, PARAM_AM);
|
||||
double x0 = gsl_vector_get(X, PARAM_X0);
|
||||
double y0 = gsl_vector_get(X, PARAM_Y0);
|
||||
double sx = gsl_vector_get(X, PARAM_SX);
|
||||
double sy = gsl_vector_get(X, PARAM_SY);
|
||||
|
||||
int i = 0;
|
||||
for(size_t y=0;y<d->size;y++)
|
||||
{
|
||||
for(size_t x=0;x<d->size;x++)
|
||||
{
|
||||
double tx = x-x0;
|
||||
double ty = y-y0;
|
||||
double e = gauss_model(am, x0, y0, sx, sy, x, y);
|
||||
|
||||
gsl_matrix_set(J, i, PARAM_AM, -e/am);
|
||||
gsl_matrix_set(J, i, PARAM_X0, -e*(tx/(sx*sx)));
|
||||
gsl_matrix_set(J, i, PARAM_Y0, -e*(ty/(sy*sy)));
|
||||
gsl_matrix_set(J, i, PARAM_SX, -e*(tx*tx/(sx*sx*sx)));
|
||||
gsl_matrix_set(J, i, PARAM_SY, -e*(ty*ty/(sy*sy*sy)));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return GSL_SUCCESS;
|
||||
}
|
||||
|
||||
int func_f_an(const gsl_vector *X, void *params, gsl_vector *f)
|
||||
{
|
||||
StarData *d = static_cast<StarData*>(params);
|
||||
double am = gsl_vector_get(X, PARAM_AM);
|
||||
double x0 = gsl_vector_get(X, PARAM_X0);
|
||||
double y0 = gsl_vector_get(X, PARAM_Y0);
|
||||
double sx = gsl_vector_get(X, PARAM_SX);
|
||||
double sy = gsl_vector_get(X, PARAM_SY);
|
||||
double th = gsl_vector_get(X, PARAM_TH);
|
||||
|
||||
int i = 0;
|
||||
double a = sin(th);
|
||||
double b = cos(th);
|
||||
for(size_t y=0;y<d->size;y++)
|
||||
{
|
||||
for(size_t x=0;x<d->size;x++)
|
||||
{
|
||||
double v = gauss_model(am, x0, y0, sx, sy, x*b-y*a, x*a+y*b);
|
||||
gsl_vector_set(f, i, d->val[i] - v);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return GSL_SUCCESS;
|
||||
}
|
||||
|
||||
int func_df_af(const gsl_vector *X, void *params, gsl_matrix *J)
|
||||
{
|
||||
StarData *d = static_cast<StarData*>(params);
|
||||
double am = gsl_vector_get(X, PARAM_AM);
|
||||
double x0 = gsl_vector_get(X, PARAM_X0);
|
||||
double y0 = gsl_vector_get(X, PARAM_Y0);
|
||||
double sx = gsl_vector_get(X, PARAM_SX);
|
||||
double sy = gsl_vector_get(X, PARAM_SY);
|
||||
|
||||
int i = 0;
|
||||
for(size_t y=0;y<d->size;y++)
|
||||
{
|
||||
for(size_t x=0;x<d->size;x++)
|
||||
{
|
||||
double tx = x-x0;
|
||||
double ty = y-y0;
|
||||
double e = gauss_model(am, x0, y0, sx, sy, x, y);
|
||||
|
||||
gsl_matrix_set(J, i, PARAM_AM, -e/am);
|
||||
gsl_matrix_set(J, i, PARAM_X0, -e*(tx/(sx*sx)));
|
||||
gsl_matrix_set(J, i, PARAM_Y0, -e*(ty/(sy*sy)));
|
||||
gsl_matrix_set(J, i, PARAM_SX, -e*(tx*tx/(sx*sx*sx)));
|
||||
gsl_matrix_set(J, i, PARAM_SY, -e*(ty*ty/(sy*sy*sy)));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return GSL_SUCCESS;
|
||||
}
|
||||
|
||||
//int func_fvv(const gsl_vector *x, const gsl_vector * v, void *params, gsl_vector *fvv)
|
||||
//{
|
||||
// return GSL_SUCCESS;
|
||||
//}
|
||||
|
||||
void callback(const size_t iter, void *, const gsl_multifit_nlinear_workspace *w)
|
||||
{
|
||||
double rcond;
|
||||
gsl_vector *x = gsl_multifit_nlinear_position(w);
|
||||
gsl_multifit_nlinear_rcond(&rcond, w);
|
||||
QString r = "Iter: " + QString::number(iter)
|
||||
+ " Am: " + QString::number(gsl_vector_get(x, PARAM_AM))
|
||||
+ " X0: " + QString::number(gsl_vector_get(x, PARAM_X0))
|
||||
+ " Y0: " + QString::number(gsl_vector_get(x, PARAM_Y0))
|
||||
+ " SX: " + QString::number(gsl_vector_get(x, PARAM_SX))
|
||||
+ " SY: " + QString::number(gsl_vector_get(x, PARAM_SY))
|
||||
+ " J(X) :" + QString::number(1.0/rcond)
|
||||
+ " av: " + QString::number(gsl_multifit_nlinear_avratio(w));
|
||||
std::cout << r.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void callback_an(const size_t iter, void *, const gsl_multifit_nlinear_workspace *w)
|
||||
{
|
||||
double rcond;
|
||||
gsl_vector *x = gsl_multifit_nlinear_position(w);
|
||||
gsl_multifit_nlinear_rcond(&rcond, w);
|
||||
qDebug() << "Iter:" << iter << "Am:" << gsl_vector_get(x, PARAM_AM)
|
||||
<< "X0:" << gsl_vector_get(x, PARAM_X0)
|
||||
<< "Y0:" << gsl_vector_get(x, PARAM_Y0)
|
||||
<< "SX:" << gsl_vector_get(x, PARAM_SX)
|
||||
<< "SY:" << gsl_vector_get(x, PARAM_SY)
|
||||
<< "TH:" << gsl_vector_get(x, PARAM_TH)
|
||||
<< "J(X):" << 1.0/rcond
|
||||
<< "av:" << gsl_multifit_nlinear_avratio(w);
|
||||
}
|
||||
|
||||
Star::Star()
|
||||
{
|
||||
m_am = m_x = m_y = m_sx = m_sy = NAN;
|
||||
}
|
||||
|
||||
bool Star::valid() const
|
||||
{
|
||||
return !isnan(m_am);
|
||||
}
|
||||
|
||||
//half width at half maximum = sqrt(2*ln(2))
|
||||
double Star::hwhmX() const
|
||||
{
|
||||
return 1.177410023*m_sx;
|
||||
}
|
||||
|
||||
double Star::hwhmY() const
|
||||
{
|
||||
return 1.177410023*m_sy;
|
||||
}
|
||||
|
||||
// half width at 1/20 maximum
|
||||
double Star::hw20X() const
|
||||
{
|
||||
return 2.447746831*m_sx;
|
||||
}
|
||||
|
||||
double Star::hw20Y() const
|
||||
{
|
||||
return 2.447746831*m_sy;
|
||||
}
|
||||
|
||||
// full width at half maximum
|
||||
double Star::fwhmX() const
|
||||
{
|
||||
return 2.354820045*m_sx;
|
||||
}
|
||||
|
||||
double Star::fwhmY() const
|
||||
{
|
||||
return 2.354820045*m_sy;
|
||||
}
|
||||
|
||||
bool Star::operator<(const Star &d) const
|
||||
{
|
||||
return m_am < d.m_am;
|
||||
}
|
||||
|
||||
StarFit::StarFit(int size)
|
||||
{
|
||||
m_size = size;
|
||||
m_fdf_params = gsl_multifit_nlinear_default_parameters();
|
||||
m_fdf_params.trs = gsl_multifit_nlinear_trs_lmaccel;
|
||||
|
||||
m_fdf.f = func_f;
|
||||
m_fdf.df = func_df;
|
||||
m_fdf.fvv = nullptr;
|
||||
m_fdf.n = size*size;
|
||||
m_fdf.p = 5;//number of model parameters amplitude, x, y, fwhm_x, fwhm_y
|
||||
|
||||
m_fdf_an.f = func_f_an;
|
||||
m_fdf_an.df = nullptr;
|
||||
m_fdf_an.fvv = nullptr;
|
||||
m_fdf_an.n = size*size;
|
||||
m_fdf_an.p = 6;//number of model parameters amplitude, x, y, sigma_x, sigma_y, angle
|
||||
|
||||
gsl_set_error_handler_off();
|
||||
}
|
||||
|
||||
StarFit::~StarFit()
|
||||
{
|
||||
}
|
||||
|
||||
Star StarFit::fitStar(const std::vector<double> &data, bool angle)
|
||||
{
|
||||
gsl_multifit_nlinear_fdf *fdf = angle ? &m_fdf_an : &m_fdf;
|
||||
Star star;
|
||||
StarData d;
|
||||
d.val = data;
|
||||
d.size = m_size;
|
||||
d.val = data;
|
||||
fdf->params = &d;
|
||||
int info;
|
||||
|
||||
double min = *std::min_element(data.begin(), data.end());
|
||||
double max = *std::max_element(data.begin(), data.end()) - min;
|
||||
for(double &v : d.val)
|
||||
{
|
||||
v -= min;
|
||||
}
|
||||
|
||||
gsl_vector *start = gsl_vector_alloc(fdf->p);
|
||||
gsl_vector_set(start, PARAM_AM, max);
|
||||
gsl_vector_set(start, PARAM_X0, m_size/2);
|
||||
gsl_vector_set(start, PARAM_Y0, m_size/2);
|
||||
gsl_vector_set(start, PARAM_SX, 1.0);
|
||||
gsl_vector_set(start, PARAM_SY, 1.0);
|
||||
if(angle)
|
||||
gsl_vector_set(start, PARAM_TH, 0.0);
|
||||
|
||||
gsl_multifit_nlinear_workspace *workspace = gsl_multifit_nlinear_alloc(gsl_multifit_nlinear_trust, &m_fdf_params, fdf->n, fdf->p);
|
||||
|
||||
int ret = gsl_multifit_nlinear_init(start, fdf, workspace);
|
||||
if(ret)return star;
|
||||
|
||||
ret = gsl_multifit_nlinear_driver(MAX_ITER, TOL, TOL, TOL, nullptr, nullptr, &info, workspace);
|
||||
|
||||
if(ret==0)
|
||||
{
|
||||
gsl_vector *y = gsl_multifit_nlinear_position(workspace);
|
||||
star.m_am = gsl_vector_get(y, PARAM_AM);
|
||||
star.m_x = gsl_vector_get(y, PARAM_X0);
|
||||
star.m_y = gsl_vector_get(y, PARAM_Y0);
|
||||
star.m_sx = gsl_vector_get(y, PARAM_SX);
|
||||
star.m_sy = gsl_vector_get(y, PARAM_SY);
|
||||
if(angle)
|
||||
star.m_theta = gsl_vector_get(y, PARAM_TH);
|
||||
//qDebug() << "finished" << star.m_am << star.m_sx << star.m_sy;
|
||||
}
|
||||
|
||||
gsl_vector_free(start);
|
||||
gsl_multifit_nlinear_free(workspace);
|
||||
|
||||
return star;
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#ifndef STARFIT_H
|
||||
#define STARFIT_H
|
||||
|
||||
#include "rawimage.h"
|
||||
#include <gsl/gsl_multifit_nlinear.h>
|
||||
|
||||
double gauss_model(double a, double x0, double y0, double sx, double sy, double x, double y);
|
||||
|
||||
struct Star
|
||||
{
|
||||
double m_am;
|
||||
double m_x,m_y;
|
||||
double m_sx,m_sy;
|
||||
double m_theta;
|
||||
Star();
|
||||
bool valid() const;
|
||||
double hwhmX() const;
|
||||
double hwhmY() const;
|
||||
double hw20X() const;
|
||||
double hw20Y() const;
|
||||
double fwhmX() const;
|
||||
double fwhmY() const;
|
||||
bool operator<(const Star &d) const;
|
||||
};
|
||||
|
||||
class StarFit
|
||||
{
|
||||
int m_size;
|
||||
gsl_multifit_nlinear_fdf m_fdf;
|
||||
gsl_multifit_nlinear_fdf m_fdf_an;
|
||||
gsl_multifit_nlinear_parameters m_fdf_params;
|
||||
gsl_vector *m_vector;
|
||||
public:
|
||||
StarFit(int size);
|
||||
~StarFit();
|
||||
Star fitStar(const std::vector<double> &data, bool angle);
|
||||
};
|
||||
|
||||
#endif // STARFIT_H
|
||||
+3
-45
@@ -3,6 +3,7 @@
|
||||
#include <QDebug>
|
||||
#include <QToolButton>
|
||||
#include <QSettings>
|
||||
#include <QStyle>
|
||||
#include "imageringlist.h"
|
||||
|
||||
const float BLACK_POINT_SIGMA = -2.8f;
|
||||
@@ -106,54 +107,11 @@ void StretchToolbar::stretchImage(Image *img)
|
||||
{
|
||||
if(img && img->rawImage())
|
||||
{
|
||||
const RawImage::Stats &stats = img->rawImage()->imageStats();
|
||||
int i = 0;
|
||||
int ch = 1;
|
||||
int o = 0;
|
||||
if(m_stack->currentIndex() == 1 && img->rawImage()->channels() == 1 && m_debayer->isChecked())
|
||||
{
|
||||
i = 1;
|
||||
ch = 4;
|
||||
o = 1;
|
||||
}
|
||||
if(img->rawImage()->channels() >= 3)
|
||||
ch = 3;
|
||||
m_mtfParam = img->rawImage()->calcMTFParams(m_stack->currentIndex() == 0,
|
||||
m_stack->currentIndex() == 1 && img->rawImage()->channels() == 1 && m_debayer->isChecked());
|
||||
|
||||
float bp2 = 0;
|
||||
float mid2 = 0;
|
||||
float max2 = 0;
|
||||
for(; i < ch; i++)
|
||||
{
|
||||
double median, mad, max;
|
||||
median = stats.m_median[i];
|
||||
mad = stats.m_mad[i];
|
||||
max = stats.m_max[i];
|
||||
median /= img->rawImage()->norm();
|
||||
bool a = median > 0.5 ? true : false;
|
||||
mad /= img->rawImage()->norm();
|
||||
max = 1.0f;// /= img->rawImage()->norm();
|
||||
float bp = a || mad == 0.0f ? 0.0f : std::clamp(median + mad * BLACK_POINT_SIGMA * MAD_TO_SIGMA, 0.0, 1.0);
|
||||
if(a && mad != 0.0f)
|
||||
max = std::clamp(median - mad * BLACK_POINT_SIGMA * MAD_TO_SIGMA, 0.0, 1.0);
|
||||
float mid = !a ? MTF(median - bp, TARGET_BACKGROUND) : MTF(TARGET_BACKGROUND, max - median);
|
||||
m_mtfParam.blackPoint[i-o] = bp;
|
||||
m_mtfParam.midPoint[i-o] = mid;// / max;
|
||||
m_mtfParam.whitePoint[i-o] = max;
|
||||
bp2 += bp;
|
||||
mid2 += mid;
|
||||
max2 = max > max2 ? max : max2;
|
||||
}
|
||||
if(ch == 1)
|
||||
{
|
||||
m_mtfParam.blackPoint[1] = m_mtfParam.blackPoint[2] = m_mtfParam.blackPoint[0];
|
||||
m_mtfParam.midPoint[1] = m_mtfParam.midPoint[2] = m_mtfParam.midPoint[0];
|
||||
m_mtfParam.whitePoint[1] = m_mtfParam.whitePoint[2] = m_mtfParam.whitePoint[0];
|
||||
}
|
||||
if(m_stack->currentIndex() == 0)
|
||||
{
|
||||
m_mtfParam.blackPoint[0] = m_mtfParam.blackPoint[1] = m_mtfParam.blackPoint[2] = bp2 / ch;
|
||||
m_mtfParam.midPoint[0] = m_mtfParam.midPoint[1] = m_mtfParam.midPoint[2] = mid2 / ch;
|
||||
m_mtfParam.whitePoint[0] = m_mtfParam.whitePoint[1] = m_mtfParam.whitePoint[2] = max2;
|
||||
m_stfSlider->setMTFParams(m_mtfParam.blackPoint[0], m_mtfParam.midPoint[0], m_mtfParam.whitePoint[0]);
|
||||
}
|
||||
else
|
||||
|
||||
+1
-7
@@ -4,16 +4,10 @@
|
||||
#include <QToolBar>
|
||||
#include <QStackedWidget>
|
||||
#include "stfslider.h"
|
||||
#include "mtfparam.h"
|
||||
|
||||
class Image;
|
||||
|
||||
struct MTFParam
|
||||
{
|
||||
float blackPoint[3] = {0.0f, 0.0f, 0.0f};
|
||||
float midPoint[3] = {0.5f, 0.5f, 0.5f};
|
||||
float whitePoint[3] = {1.0f, 1.0f, 1.0f};
|
||||
};
|
||||
|
||||
class StretchToolbar : public QToolBar
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#ifndef TFLOAT16_H
|
||||
#define TFLOAT16_H
|
||||
|
||||
// crude implementation of float16 for platforms that do not support _Float16
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class TFloat16
|
||||
{
|
||||
uint16_t b16;
|
||||
public:
|
||||
TFloat16(){ b16 = 0; }
|
||||
explicit inline TFloat16(float f)
|
||||
{
|
||||
uint32_t i = *reinterpret_cast<uint32_t*>(&f);
|
||||
uint32_t sign = (i >> 16) & 0x8000;
|
||||
uint32_t exp = (i >> 23) & 0xff;
|
||||
uint32_t mantisa = (i & 0x7fffff) >> 13;
|
||||
|
||||
b16 = 0;
|
||||
if(exp < 111)
|
||||
{
|
||||
// do nothing it map to 0
|
||||
}
|
||||
else if(exp == 111)
|
||||
{
|
||||
b16 |= sign;
|
||||
b16 |= mantisa;
|
||||
}
|
||||
else if(exp == 255)//inf or nan
|
||||
{
|
||||
b16 = 0x7c00;
|
||||
b16 |= sign;
|
||||
b16 |= mantisa;
|
||||
}
|
||||
else if(exp > 142)
|
||||
{
|
||||
b16 = 0x7c00;// inf
|
||||
b16 |= sign;
|
||||
}
|
||||
else
|
||||
{
|
||||
b16 |= sign;
|
||||
b16 |= (exp - 112) << 10;
|
||||
b16 |= mantisa;
|
||||
}
|
||||
}
|
||||
friend TFloat16 operator*(TFloat16 a, TFloat16 b)
|
||||
{
|
||||
return TFloat16(static_cast<float>(a) * static_cast<float>(b));
|
||||
}
|
||||
operator float() const
|
||||
{
|
||||
uint32_t i = 0;
|
||||
uint32_t sign = b16 & 0x8000;
|
||||
uint32_t exp = (b16 & 0x7c00) >> 10;
|
||||
if(b16)
|
||||
{
|
||||
i |= sign << 16;
|
||||
if(exp==31)i |= 0x7f800000;
|
||||
else i |= (exp + 112) << 23;
|
||||
i |= (b16 & 0x3ff) << 13;
|
||||
}
|
||||
return *reinterpret_cast<float*>(&i);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TFLOAT16_H
|
||||
@@ -0,0 +1,31 @@
|
||||
option(BUILD_THUMBNAILER "Build generator of thumbnails" OFF)
|
||||
|
||||
if(BUILD_THUMBNAILER)
|
||||
if(WIN32)
|
||||
add_library(tenmonthumbnailer SHARED
|
||||
Dll.cpp
|
||||
loadxisf.cpp
|
||||
TenmonThumbnailProvider.cpp
|
||||
../rawimage.h
|
||||
../rawimage.cpp
|
||||
../rawimage_sse.cpp)
|
||||
set_target_properties(tenmonthumbnailer PROPERTIES PREFIX "")
|
||||
|
||||
target_compile_definitions(tenmonthumbnailer PRIVATE NO_QT)
|
||||
target_include_directories(tenmonthumbnailer PRIVATE ../libXISF)
|
||||
target_link_libraries(tenmonthumbnailer PRIVATE shlwapi ${LCMS2_LIB} ${FITS_LIB} XISF)
|
||||
target_link_options(tenmonthumbnailer PRIVATE "-static")
|
||||
else(WIN32)
|
||||
qt_add_executable(tenmonthumbnailer
|
||||
main.cpp
|
||||
../loadimage.cpp
|
||||
../rawimage.cpp
|
||||
../rawimage_sse.cpp
|
||||
../imageinfodata.cpp)
|
||||
|
||||
target_link_libraries(tenmonthumbnailer PRIVATE Qt6::Core Qt6::Gui ${EXIF_LIB} ${FITS_LIB} ${RAW_LIB} ${WCS_LIB} ${LCMS2_LIB} XISF)
|
||||
|
||||
target_include_directories(tenmonthumbnailer PRIVATE ../libXISF)
|
||||
endif(WIN32)
|
||||
endif(BUILD_THUMBNAILER)
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
#include <objbase.h>
|
||||
#include <shlwapi.h>
|
||||
#include <thumbcache.h> // For IThumbnailProvider.
|
||||
#include <shlobj.h> // For SHChangeNotify
|
||||
#include <new>
|
||||
|
||||
extern HRESULT TenmonThumbnailer_CreateInstance(REFIID riid, void **ppv);
|
||||
|
||||
#define SZ_CLSID_TENMONTHUMBHANDLER L"{0f3881d7-c9f0-45cb-aadb-40192aead2b4}"
|
||||
#define SZ_TENMONTHUMBHANDLER L"Tenmon Thumbnail Handler"
|
||||
|
||||
const CLSID CLSID_TenmonThumbHandler = {0x0f3881d7, 0xc9f0, 0x45cb, {0xaa, 0xdb, 0x40, 0x19, 0x2a, 0xea, 0xd2, 0xb4}};
|
||||
|
||||
typedef HRESULT (*PFNCREATEINSTANCE)(REFIID riid, void **ppvObject);
|
||||
struct CLASS_OBJECT_INIT
|
||||
{
|
||||
const CLSID *pClsid;
|
||||
PFNCREATEINSTANCE pfnCreate;
|
||||
};
|
||||
|
||||
// add classes supported by this module here
|
||||
const CLASS_OBJECT_INIT c_rgClassObjectInit[] =
|
||||
{
|
||||
{ &CLSID_TenmonThumbHandler, TenmonThumbnailer_CreateInstance }
|
||||
};
|
||||
|
||||
|
||||
long g_cRefModule = 0;
|
||||
|
||||
// Handle the the DLL's module
|
||||
HINSTANCE g_hInst = NULL;
|
||||
|
||||
// Standard DLL functions
|
||||
STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, void *)
|
||||
{
|
||||
if (dwReason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
g_hInst = hInstance;
|
||||
DisableThreadLibraryCalls(hInstance);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI DllCanUnloadNow()
|
||||
{
|
||||
// Only allow the DLL to be unloaded after all outstanding references have been released
|
||||
return (g_cRefModule == 0) ? S_OK : S_FALSE;
|
||||
}
|
||||
|
||||
void DllAddRef()
|
||||
{
|
||||
InterlockedIncrement(&g_cRefModule);
|
||||
}
|
||||
|
||||
void DllRelease()
|
||||
{
|
||||
InterlockedDecrement(&g_cRefModule);
|
||||
}
|
||||
|
||||
class CClassFactory : public IClassFactory
|
||||
{
|
||||
public:
|
||||
static HRESULT CreateInstance(REFCLSID clsid, const CLASS_OBJECT_INIT *pClassObjectInits, size_t cClassObjectInits, REFIID riid, void **ppv)
|
||||
{
|
||||
*ppv = NULL;
|
||||
HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
|
||||
for (size_t i = 0; i < cClassObjectInits; i++)
|
||||
{
|
||||
if (clsid == *pClassObjectInits[i].pClsid)
|
||||
{
|
||||
IClassFactory *pClassFactory = new (std::nothrow) CClassFactory(pClassObjectInits[i].pfnCreate);
|
||||
hr = pClassFactory ? S_OK : E_OUTOFMEMORY;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = pClassFactory->QueryInterface(riid, ppv);
|
||||
pClassFactory->Release();
|
||||
}
|
||||
break; // match found
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
CClassFactory(PFNCREATEINSTANCE pfnCreate) : _cRef(1), _pfnCreate(pfnCreate)
|
||||
{
|
||||
DllAddRef();
|
||||
}
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHODIMP QueryInterface(REFIID riid, void ** ppv)
|
||||
{
|
||||
static const QITAB qit[] =
|
||||
{
|
||||
QITABENT(CClassFactory, IClassFactory),
|
||||
{ 0 }
|
||||
};
|
||||
return QISearch(this, qit, riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) AddRef()
|
||||
{
|
||||
return InterlockedIncrement(&_cRef);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) Release()
|
||||
{
|
||||
long cRef = InterlockedDecrement(&_cRef);
|
||||
if (cRef == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
return cRef;
|
||||
}
|
||||
|
||||
// IClassFactory
|
||||
IFACEMETHODIMP CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
|
||||
{
|
||||
return punkOuter ? CLASS_E_NOAGGREGATION : _pfnCreate(riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP LockServer(BOOL fLock)
|
||||
{
|
||||
if (fLock)
|
||||
{
|
||||
DllAddRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
DllRelease();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
~CClassFactory()
|
||||
{
|
||||
DllRelease();
|
||||
}
|
||||
|
||||
long _cRef;
|
||||
PFNCREATEINSTANCE _pfnCreate;
|
||||
};
|
||||
|
||||
STDAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void **ppv)
|
||||
{
|
||||
return CClassFactory::CreateInstance(clsid, c_rgClassObjectInit, ARRAYSIZE(c_rgClassObjectInit), riid, ppv);
|
||||
}
|
||||
|
||||
// A struct to hold the information required for a registry entry
|
||||
|
||||
struct REGISTRY_ENTRY
|
||||
{
|
||||
HKEY hkeyRoot;
|
||||
PCWSTR pszKeyName;
|
||||
PCWSTR pszValueName;
|
||||
PCWSTR pszData;
|
||||
};
|
||||
|
||||
// Creates a registry key (if needed) and sets the default value of the key
|
||||
|
||||
HRESULT CreateRegKeyAndSetValue(const REGISTRY_ENTRY *pRegistryEntry)
|
||||
{
|
||||
HKEY hKey;
|
||||
HRESULT hr = HRESULT_FROM_WIN32(RegCreateKeyExW(pRegistryEntry->hkeyRoot, pRegistryEntry->pszKeyName,
|
||||
0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, pRegistryEntry->pszValueName, 0, REG_SZ,
|
||||
(LPBYTE) pRegistryEntry->pszData,
|
||||
((DWORD) wcslen(pRegistryEntry->pszData) + 1) * sizeof(WCHAR)));
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
//
|
||||
// Registers this COM server
|
||||
//
|
||||
STDAPI DllRegisterServer()
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
WCHAR szModuleName[MAX_PATH];
|
||||
|
||||
if (!GetModuleFileNameW(g_hInst, szModuleName, ARRAYSIZE(szModuleName)))
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
else
|
||||
{
|
||||
// List of registry entries we want to create
|
||||
const REGISTRY_ENTRY rgRegistryEntries[] =
|
||||
{
|
||||
// RootKey KeyName ValueName Data
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" SZ_CLSID_TENMONTHUMBHANDLER, NULL, SZ_TENMONTHUMBHANDLER},
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" SZ_CLSID_TENMONTHUMBHANDLER L"\\InProcServer32", NULL, szModuleName},
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\CLSID\\" SZ_CLSID_TENMONTHUMBHANDLER L"\\InProcServer32", L"ThreadingModel", L"Apartment"},
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\.xisf\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}", NULL, SZ_CLSID_TENMONTHUMBHANDLER},
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\.fits\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}", NULL, SZ_CLSID_TENMONTHUMBHANDLER},
|
||||
{HKEY_CURRENT_USER, L"Software\\Classes\\.fit\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}", NULL, SZ_CLSID_TENMONTHUMBHANDLER},
|
||||
};
|
||||
|
||||
hr = S_OK;
|
||||
for (int i = 0; i < ARRAYSIZE(rgRegistryEntries) && SUCCEEDED(hr); i++)
|
||||
{
|
||||
hr = CreateRegKeyAndSetValue(&rgRegistryEntries[i]);
|
||||
}
|
||||
}
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// This tells the shell to invalidate the thumbnail cache. This is important because any .xisf files
|
||||
// viewed before registering this handler would otherwise show cached blank thumbnails.
|
||||
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
//
|
||||
// Unregisters this COM server
|
||||
//
|
||||
STDAPI DllUnregisterServer()
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
const PCWSTR rgpszKeys[] =
|
||||
{
|
||||
L"Software\\Classes\\CLSID\\" SZ_CLSID_TENMONTHUMBHANDLER,
|
||||
L"Software\\Classes\\.xisf\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}"
|
||||
L"Software\\Classes\\.fits\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}"
|
||||
L"Software\\Classes\\.fit\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}"
|
||||
};
|
||||
|
||||
// Delete the registry entries
|
||||
for (int i = 0; i < ARRAYSIZE(rgpszKeys) && SUCCEEDED(hr); i++)
|
||||
{
|
||||
hr = HRESULT_FROM_WIN32(RegDeleteTreeW(HKEY_CURRENT_USER, rgpszKeys[i]));
|
||||
if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
|
||||
{
|
||||
// If the registry entry has already been deleted, say S_OK.
|
||||
hr = S_OK;
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
#include <shlwapi.h>
|
||||
#include <thumbcache.h> // For IThumbnailProvider.
|
||||
#include <new>
|
||||
#include "libxisf.h"
|
||||
|
||||
bool loadXISF(const LibXISF::ByteArray &data, HBITMAP *hbmp, UINT thumbSize);
|
||||
bool loadFITS(const LibXISF::ByteArray &data, HBITMAP *hbmp, UINT thumbSize);
|
||||
|
||||
class TenmonThumbProvider : public IInitializeWithStream,
|
||||
public IThumbnailProvider
|
||||
{
|
||||
public:
|
||||
TenmonThumbProvider() : _cRef(1), _pStream(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~TenmonThumbProvider()
|
||||
{
|
||||
if (_pStream)
|
||||
{
|
||||
_pStream->Release();
|
||||
}
|
||||
}
|
||||
|
||||
// IUnknown
|
||||
IFACEMETHODIMP QueryInterface(REFIID riid, void **ppv)
|
||||
{
|
||||
static const QITAB qit[] =
|
||||
{
|
||||
QITABENT(TenmonThumbProvider, IInitializeWithStream),
|
||||
QITABENT(TenmonThumbProvider, IThumbnailProvider),
|
||||
{ 0 },
|
||||
};
|
||||
return QISearch(this, qit, riid, ppv);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) AddRef()
|
||||
{
|
||||
return InterlockedIncrement(&_cRef);
|
||||
}
|
||||
|
||||
IFACEMETHODIMP_(ULONG) Release()
|
||||
{
|
||||
ULONG cRef = InterlockedDecrement(&_cRef);
|
||||
if (!cRef)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
return cRef;
|
||||
}
|
||||
|
||||
// IInitializeWithStream
|
||||
IFACEMETHODIMP Initialize(IStream *pStream, DWORD grfMode);
|
||||
|
||||
// IThumbnailProvider
|
||||
IFACEMETHODIMP GetThumbnail(UINT cx, HBITMAP *phbmp, WTS_ALPHATYPE *pdwAlpha);
|
||||
|
||||
private:
|
||||
|
||||
long _cRef;
|
||||
IStream *_pStream; // provided during initialization.
|
||||
};
|
||||
|
||||
HRESULT TenmonThumbnailer_CreateInstance(REFIID riid, void **ppv)
|
||||
{
|
||||
TenmonThumbProvider *pNew = new (std::nothrow) TenmonThumbProvider();
|
||||
HRESULT hr = pNew ? S_OK : E_OUTOFMEMORY;
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = pNew->QueryInterface(riid, ppv);
|
||||
pNew->Release();
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
// IInitializeWithStream
|
||||
IFACEMETHODIMP TenmonThumbProvider::Initialize(IStream *pStream, DWORD)
|
||||
{
|
||||
HRESULT hr = E_UNEXPECTED; // can only be inited once
|
||||
if (_pStream == NULL)
|
||||
{
|
||||
// take a reference to the stream if we have not been inited yet
|
||||
hr = pStream->QueryInterface(&_pStream);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
// IThumbnailProvider
|
||||
IFACEMETHODIMP TenmonThumbProvider::GetThumbnail(UINT cx, HBITMAP *phbmp, WTS_ALPHATYPE *pdwAlpha)
|
||||
{
|
||||
LibXISF::ByteArray data;
|
||||
ULONG readSize = 0;
|
||||
ULONG read;
|
||||
data.resize(1024*1024);
|
||||
|
||||
while(_pStream->Read(data.data() + readSize, data.size() - readSize, &read) == S_OK)
|
||||
{
|
||||
readSize += read;
|
||||
data.resize(data.size() + 1024*1024);
|
||||
}
|
||||
readSize += read;
|
||||
|
||||
*pdwAlpha = WTSAT_RGB;
|
||||
|
||||
data.resize(readSize);
|
||||
if(data[0] == 'X' && data[1] == 'I' && data[2] == 'S' && data[3] == 'F')
|
||||
{
|
||||
if(loadXISF(data, phbmp, cx))
|
||||
return S_OK;
|
||||
else
|
||||
return E_FAIL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(loadFITS(data, phbmp, cx))
|
||||
return S_OK;
|
||||
else
|
||||
return E_FAIL;
|
||||
}
|
||||
return E_FAIL;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "genthumbnail.h"
|
||||
#include "../rawimage.h"
|
||||
#include "../loadimage.h"
|
||||
|
||||
|
||||
int generateThumbnail(const QString &input, const QString &output, uint32_t size)
|
||||
{
|
||||
ImageInfoData info;
|
||||
std::shared_ptr<RawImage> rawImage;
|
||||
if(!loadImage(input, info, rawImage))
|
||||
return 2;
|
||||
|
||||
if(!rawImage)
|
||||
return 3;
|
||||
|
||||
QSize rect(rawImage->width(), rawImage->height());
|
||||
rect.scale(size, size, Qt::KeepAspectRatio);
|
||||
rawImage->calcStats();
|
||||
rawImage->resize(rect.width(), rect.height());
|
||||
if(rawImage->imageStats().m_median[0] < rawImage->norm() * 0.2f)
|
||||
{
|
||||
MTFParam mtfParams = rawImage->calcMTFParams(true);
|
||||
rawImage->applySTF(mtfParams);
|
||||
}
|
||||
rawImage->convertToType(RawImage::UINT8);
|
||||
|
||||
QImage img;
|
||||
if(rawImage->channels() == 1)
|
||||
img = QImage((const uchar*)rawImage->data(), rawImage->width(), rawImage->height(), rawImage->widthBytes(), QImage::Format_Grayscale8);
|
||||
else
|
||||
img = QImage((const uchar*)rawImage->data(), rawImage->width(), rawImage->height(), rawImage->widthBytes(), QImage::Format_RGBA8888);
|
||||
|
||||
if(!img.save(output, "png"))
|
||||
return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef GENTHUMBNAIL_H
|
||||
#define GENTHUMBNAIL_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
int generateThumbnail(const QString &input, const QString &output, uint32_t size);
|
||||
|
||||
#endif // GENTHUMBNAIL_H
|
||||
@@ -0,0 +1,237 @@
|
||||
#include "libxisf.h"
|
||||
#include <thumbcache.h>
|
||||
#include "../rawimage.h"
|
||||
#include <fitsio2.h>
|
||||
|
||||
bool OpenGLES = false;
|
||||
|
||||
void RawImageToHTBITMAP(std::shared_ptr<RawImage> &rawImage, HBITMAP *hbmp, UINT thumbSize)
|
||||
{
|
||||
rawImage->calcStats();
|
||||
|
||||
DWORD thre = 10;
|
||||
DWORD dataSize = 4;
|
||||
//HRESULT hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_CURRENT_USER, L"SOFTWARE\\nou\\Tenmon\\settings", L"thumbnailstretchthreshold", RRF_RT_DWORD, NULL, &thre, &dataSize));
|
||||
|
||||
float thref = 0.1f;
|
||||
/*if(hr == S_OK)
|
||||
thref = thre / 100.0f;*/
|
||||
|
||||
if(rawImage->imageStats().m_mean[0] < rawImage->norm() * thref)
|
||||
{
|
||||
//OutputDebugStringA("Stretch image");
|
||||
MTFParam params = rawImage->calcMTFParams();
|
||||
rawImage->applySTF(params);
|
||||
}
|
||||
|
||||
UINT w = rawImage->width();
|
||||
UINT h = rawImage->height();
|
||||
|
||||
UINT cw = thumbSize;
|
||||
UINT ch = thumbSize;
|
||||
if (w > h)
|
||||
ch = h * thumbSize / w;
|
||||
else
|
||||
cw = w * thumbSize / h;
|
||||
|
||||
|
||||
rawImage->resize(cw, ch);
|
||||
rawImage->convertToType(RawImage::UINT8);
|
||||
|
||||
BITMAPINFO bmi = {};
|
||||
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
|
||||
bmi.bmiHeader.biWidth = cw;
|
||||
bmi.bmiHeader.biHeight = -static_cast<LONG>(ch);
|
||||
bmi.bmiHeader.biPlanes = 1;
|
||||
bmi.bmiHeader.biBitCount = 32;
|
||||
bmi.bmiHeader.biCompression = BI_RGB;
|
||||
UINT lw = cw * 4;
|
||||
|
||||
BYTE *pBits;
|
||||
HBITMAP bmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, reinterpret_cast<void **>(&pBits), NULL, 0);
|
||||
|
||||
const unsigned char *p = (const unsigned char*)rawImage->data();
|
||||
const unsigned short *ps = (const unsigned short*)rawImage->data();
|
||||
if(rawImage->channels() == 1)
|
||||
{
|
||||
for(UINT y = 0; y < ch; y++)
|
||||
{
|
||||
for(UINT x = 0; x < cw; x++)
|
||||
{
|
||||
pBits[(y * lw) + x * 4 + 0] = p[y * cw + x];
|
||||
pBits[(y * lw) + x * 4 + 1] = p[y * cw + x];
|
||||
pBits[(y * lw) + x * 4 + 2] = p[y * cw + x];
|
||||
pBits[(y * lw) + x * 4 + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(UINT y = 0; y < ch; y++)
|
||||
{
|
||||
for(UINT x = 0; x < cw; x++)
|
||||
{
|
||||
pBits[(y * lw) + x * 4 + 0] = p[y * cw * 4 + x * 4 + 2];
|
||||
pBits[(y * lw) + x * 4 + 1] = p[y * cw * 4 + x * 4 + 1];
|
||||
pBits[(y * lw) + x * 4 + 2] = p[y * cw * 4 + x * 4 + 0];
|
||||
pBits[(y * lw) + x * 4 + 3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*hbmp = bmp;
|
||||
}
|
||||
|
||||
bool loadXISF(const LibXISF::ByteArray &data, HBITMAP *hbmp, UINT thumbSize)
|
||||
{
|
||||
try
|
||||
{
|
||||
LibXISF::XISFReader xisf;
|
||||
xisf.open(data);
|
||||
|
||||
const LibXISF::Image &xisfImage = xisf.getImage(0);
|
||||
|
||||
RawImage::DataType type;
|
||||
switch(xisfImage.sampleFormat())
|
||||
{
|
||||
case LibXISF::Image::UInt8: type = RawImage::UINT8; break;
|
||||
case LibXISF::Image::UInt16: type = RawImage::UINT16; break;
|
||||
case LibXISF::Image::UInt32: type = RawImage::UINT32; break;
|
||||
case LibXISF::Image::Float32: type = RawImage::FLOAT32; break;
|
||||
case LibXISF::Image::Float64: type = RawImage::FLOAT64; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
LibXISF::Image tmpImage = xisfImage;
|
||||
tmpImage.convertPixelStorageTo(LibXISF::Image::Planar);
|
||||
std::shared_ptr<RawImage> rawImage;
|
||||
|
||||
if(tmpImage.colorSpace() == LibXISF::Image::ColorSpace::Gray)
|
||||
{
|
||||
rawImage = std::make_shared<RawImage>(tmpImage.width(), tmpImage.height(), 1, type);
|
||||
std::memcpy(rawImage->data(), tmpImage.imageData(), tmpImage.imageDataSize() / tmpImage.channelCount());
|
||||
}
|
||||
else if(tmpImage.channelCount() == 3 || tmpImage.channelCount() == 4)
|
||||
{
|
||||
rawImage = RawImage::fromPlanar(tmpImage.imageData(), tmpImage.width(), tmpImage.height(), tmpImage.channelCount(), type);
|
||||
}
|
||||
|
||||
RawImageToHTBITMAP(rawImage, hbmp, thumbSize);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (LibXISF::Error &err)
|
||||
{
|
||||
char text[1024];
|
||||
sprintf_s(text, 1000, "Failed to open XISF image %s", err.what());
|
||||
OutputDebugStringA(text);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool loadFITS(const LibXISF::ByteArray &data, HBITMAP *hbmp, UINT thumbSize)
|
||||
{
|
||||
fitsfile *file;
|
||||
|
||||
int status = 0;
|
||||
int type = -1;
|
||||
int num = 0;
|
||||
long naxes[3] = {0};
|
||||
|
||||
auto checkError = [&status]()
|
||||
{
|
||||
char err[100];
|
||||
char text[1000];
|
||||
fits_get_errstatus(status, err);
|
||||
sprintf_s(text, 1000, "Failed to load FITS file %s", err);
|
||||
OutputDebugStringA(text);
|
||||
return false;
|
||||
};
|
||||
|
||||
const void *dataPtr = data.data();
|
||||
size_t size = data.size();
|
||||
fits_open_memfile(&file, "file.fits", READONLY, (void**)&dataPtr, &size, 0, nullptr, &status);
|
||||
if(status)return checkError();
|
||||
fits_get_num_hdus(file, &num, &status);
|
||||
if(status)return checkError();
|
||||
|
||||
int imgtype;
|
||||
int naxis;
|
||||
for(int i=1; i <= num; i++)
|
||||
{
|
||||
fits_movabs_hdu(file, i, IMAGE_HDU, &status);if(status)return checkError();
|
||||
fits_get_hdu_type(file, &type, &status);if(status)return checkError();
|
||||
fits_get_img_param(file, 3, &imgtype, &naxis, naxes, &status);if(status)return checkError();
|
||||
fits_get_img_equivtype(file, &imgtype, &status);if(status)return checkError();
|
||||
|
||||
if(type == IMAGE_HDU && naxis >= 2 && naxis <= 3 && status == 0)
|
||||
{
|
||||
RawImage::DataType type;
|
||||
int fitstype;
|
||||
long fpixel[3] = {1,1,1};
|
||||
switch(imgtype)
|
||||
{
|
||||
case BYTE_IMG:
|
||||
type = RawImage::UINT8;
|
||||
fitstype = TBYTE;
|
||||
break;
|
||||
case SHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TSHORT;
|
||||
break;
|
||||
case USHORT_IMG:
|
||||
type = RawImage::UINT16;
|
||||
fitstype = TUSHORT;
|
||||
break;
|
||||
case ULONG_IMG:
|
||||
type = RawImage::UINT32;
|
||||
fitstype = TUINT;
|
||||
break;
|
||||
case FLOAT_IMG:
|
||||
type = RawImage::FLOAT32;
|
||||
fitstype = TFLOAT;
|
||||
break;
|
||||
case DOUBLE_IMG:
|
||||
type = RawImage::FLOAT64;
|
||||
fitstype = TDOUBLE;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t size = naxes[0]*naxes[1];
|
||||
size_t w = naxes[0];
|
||||
size_t h = naxes[1];
|
||||
|
||||
RawImage img(w, h, naxis == 2 ? 1 : naxes[2], type);
|
||||
uint8_t *data = static_cast<uint8_t*>(img.data());
|
||||
for (int i=1; i==1 || i<=naxes[2]; i++)
|
||||
{
|
||||
fpixel[2] = i;
|
||||
fits_read_pix(file, fitstype, fpixel, size, NULL, data + img.size() * RawImage::typeSize(type) * (i-1), NULL, &status);
|
||||
if(status)return checkError();
|
||||
}
|
||||
if(fitstype == TSHORT)
|
||||
{
|
||||
uint16_t *s = static_cast<uint16_t*>(img.data());
|
||||
size_t size = img.size() * img.channels();
|
||||
for(size_t i=0; i<size; i++)
|
||||
s[i] -= INT16_MIN;
|
||||
}
|
||||
|
||||
std::shared_ptr<RawImage> image;
|
||||
if(img.channels() == 1)
|
||||
image = std::make_shared<RawImage>(std::move(img));
|
||||
else
|
||||
image = RawImage::fromPlanar(img);
|
||||
|
||||
RawImageToHTBITMAP(image, hbmp, thumbSize);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include "../rawimage.h"
|
||||
#include "../loadimage.h"
|
||||
|
||||
bool OpenGLES = false;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.addOption({{"s", "size"}, "Size of the thumbnail in pixels (default: 128)", "size", "128"});
|
||||
parser.addPositionalArgument("input", "Input image file");
|
||||
parser.addPositionalArgument("output", "Output image file");
|
||||
parser.addHelpOption();
|
||||
|
||||
parser.process(a);
|
||||
|
||||
QStringList args = parser.positionalArguments();
|
||||
|
||||
if(args.size() < 2)
|
||||
return 1;
|
||||
|
||||
QString input = args[0];
|
||||
QString output = args[1];
|
||||
|
||||
ImageInfoData info;
|
||||
std::shared_ptr<RawImage> rawImage;
|
||||
if(!loadImage(input, info, rawImage))
|
||||
return 2;
|
||||
|
||||
if(!rawImage)
|
||||
return 3;
|
||||
|
||||
bool ok;
|
||||
int size = parser.value("s").toInt(&ok);
|
||||
if(!ok)
|
||||
size = 128;
|
||||
|
||||
QSize rect(rawImage->width(), rawImage->height());
|
||||
rect.scale(size, size, Qt::KeepAspectRatio);
|
||||
rawImage->calcStats();
|
||||
rawImage->resize(rect.width(), rect.height());
|
||||
if(rawImage->imageStats().m_median[0] < rawImage->norm() * 0.2f)
|
||||
{
|
||||
MTFParam mtfParams = rawImage->calcMTFParams(true);
|
||||
rawImage->applySTF(mtfParams);
|
||||
}
|
||||
rawImage->convertToType(RawImage::UINT8);
|
||||
|
||||
QImage img;
|
||||
if(rawImage->channels() == 1)
|
||||
img = QImage((const uchar*)rawImage->data(), rawImage->width(), rawImage->height(), rawImage->widthBytes(), QImage::Format_Grayscale8);
|
||||
else
|
||||
img = QImage((const uchar*)rawImage->data(), rawImage->width(), rawImage->height(), rawImage->widthBytes(), QImage::Format_RGBA8888);
|
||||
|
||||
if(!img.save(output, "png"))
|
||||
return 4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
+214
-176
File diff suppressed because it is too large
Load Diff
+221
-183
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
+215
-173
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user