Skip to content

Commit

Permalink
XISF support
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcg31 committed Sep 1, 2021
1 parent f9583ff commit d7a1cae
Show file tree
Hide file tree
Showing 9 changed files with 713 additions and 10 deletions.
1 change: 1 addition & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{
"name": "Linux",
"includePath": [
"${env:PCLINCDIR}",
"${workspaceFolder}/gui/include",
"${workspaceFolder}/image/raster/include",
"${workspaceFolder}/image/fits/include",
Expand Down
4 changes: 4 additions & 0 deletions fits-army-knife.pro
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ SOURCES += \
image/fits/src/fitsexception.cpp \
image/fits/src/fitsimage.cpp \
image/fits/src/fitstantrum.cpp \
image/xisf/src/xisfexception.cpp \
image/xisf/src/xisfimage.cpp \
image/raster/src/imageloadexception.cpp \
image/raster/src/image.cpp \
image/raster/src/pixelvisitortypemismatch.cpp \
Expand All @@ -46,6 +48,8 @@ HEADERS += \
image/fits/include/fitstantrum.h \
image/fits/include/fitsimage.h \
$$PCL_INCLUDE_DIR/pcl/XISF.h \
image/xisf/include/xisfexception.h \
image/xisf/include/xisfimage.h \
image/raster/include/imageloadexception.h \
image/raster/include/image.h \
image/raster/include/rastertypes.h \
Expand Down
7 changes: 3 additions & 4 deletions image/fits/include/fitsimage.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#pragma once

#include <fitsio.h>
#include <inttypes.h>

#include "image.h"
#include "pixelvisitor.h"
#include "rastertypes.h"
#include <fitsio.h>
#include <inttypes.h>

namespace ELS
{
Expand Down Expand Up @@ -33,7 +34,6 @@ namespace ELS
bool isColor,
int width,
int height,
int64_t pixelCount,
void* pixels);

template <typename PixelT>
Expand All @@ -51,7 +51,6 @@ namespace ELS
bool _isColor;
int _width;
int _height;
int64_t _pixelCount;
void* _pixels;
};

Expand Down
3 changes: 0 additions & 3 deletions image/fits/src/fitsimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ namespace ELS
isColor,
width,
height,
pixelCount,
pixels);
}

Expand All @@ -132,14 +131,12 @@ namespace ELS
bool isColor,
int width,
int height,
int64_t pixelCount,
void* pixels)
: _sampleFormat(sampleFormat),
_format(format),
_isColor(isColor),
_width(width),
_height(height),
_pixelCount(pixelCount),
_pixels(pixels)
{
}
Expand Down
7 changes: 4 additions & 3 deletions image/raster/src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "imageloadexception.h"
#include "image.h"
#include "fitsimage.h"
#include "xisfimage.h"

namespace ELS
{
Expand Down Expand Up @@ -46,7 +47,7 @@ namespace ELS
case FT_FITS:
return FITSImage::load(filename);
case FT_XISF:
throw new ImageLoadException("XISF support not quite here yet!");
return XISFImage::load(filename);
case FT_UNKNOWN:
default:
throw new ImageLoadException("Could not determine image type from filename extension");
Expand All @@ -68,9 +69,9 @@ namespace ELS
}
break;
case FT_XISF:
if (error != 0)
if (checkMagic(filename, &g_xisfMagic, error))
{
sprintf(error, "XISF support coming soon!");
return FT_XISF;
}
break;
case FT_UNKNOWN:
Expand Down
26 changes: 26 additions & 0 deletions image/xisf/include/xisfexception.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "imageloadexception.h"

namespace ELS
{

class XISFException : public ImageLoadException
{
public:
XISFException(const char* errText);
virtual ~XISFException();

virtual const char* getErrText() const;

protected:
XISFException();

protected:
static const int g_bufSize = 200;

protected:
char _errText[g_bufSize];
};

}
94 changes: 94 additions & 0 deletions image/xisf/include/xisfimage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#pragma once

// Need to define this properly, but it's all linux all the time right now
#define __PCL_LINUX

// Suppress the MANY warnings from PCL
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wdangling-else"
#include <pcl/XISF.h>
#pragma GCC diagnostic pop

#include <inttypes.h>

#include "image.h"
#include "pixelvisitor.h"
#include "rastertypes.h"

namespace ELS
{

class XISFImage : public Image
{
public:
static XISFImage* load(const char* filename);

public:
virtual ~XISFImage() override;

virtual bool isColor() const override;

virtual int getWidth() const override;
virtual int getHeight() const override;

virtual RasterFormat getRasterFormat() const override;
virtual SampleFormat getSampleFormat() const override;

virtual void visitPixels(PixelVisitor* visitor) const override;

private:
XISFImage(SampleFormat sampleFormat,
bool isColor,
int width,
int height,
pcl::UInt8Image* img);
XISFImage(SampleFormat sampleFormat,
bool isColor,
int width,
int height,
pcl::UInt16Image* img);
XISFImage(SampleFormat sampleFormat,
bool isColor,
int width,
int height,
pcl::UInt32Image* img);
XISFImage(SampleFormat sampleFormat,
bool isColor,
int width,
int height,
pcl::FImage* img);
XISFImage(SampleFormat sampleFormat,
bool isColor,
int width,
int height,
pcl::DImage* img);

void visitPixels(pcl::UInt8Image* img,
PixelVisitor* visitor) const;
void visitPixels(pcl::UInt16Image* img,
PixelVisitor* visitor) const;
void visitPixels(pcl::UInt32Image* img,
PixelVisitor* visitor) const;
void visitPixels(pcl::FImage* img,
PixelVisitor* visitor) const;
void visitPixels(pcl::DImage* img,
PixelVisitor* visitor) const;

private:
SampleFormat _sampleFormat;
bool _isColor;
int _width;
int _height;
union
{
pcl::UInt8Image* u8;
pcl::UInt16Image* u16;
pcl::UInt32Image* u32;
pcl::FImage* f;
pcl::DImage* d;
} _pixels;
};

}
29 changes: 29 additions & 0 deletions image/xisf/src/xisfexception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <string.h>

#include "xisfexception.h"

namespace ELS
{

XISFException::XISFException(const char* errText)
{
strncpy(_errText, errText, g_bufSize - 1);
_errText[g_bufSize - 1] = 0;
}

/* virtual */
XISFException::~XISFException() {}

/* virtual */
const char* XISFException::getErrText() const
{
return _errText;
}

/* protected */
XISFException::XISFException()
{
_errText[g_bufSize - 1] = 0;
}

}
Loading

0 comments on commit d7a1cae

Please sign in to comment.