[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libcvd-members] libcvd cvd/documentation.h cvd/internal/io/fits...
From: |
Edward Rosten |
Subject: |
[libcvd-members] libcvd cvd/documentation.h cvd/internal/io/fits... |
Date: |
Thu, 08 Jan 2009 18:02:59 +0000 |
CVSROOT: /cvsroot/libcvd
Module name: libcvd
Changes by: Edward Rosten <edrosten> 09/01/08 18:02:59
Modified files:
cvd : documentation.h
cvd/internal/io: fits.h
pnm_src : fits.cc
Log message:
Support for 16 bit unisigned images using the convention of BZERO=32768
on 16 bit images. This is the only nonzero value of BZERO supported.
Other
values throw.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/documentation.h?cvsroot=libcvd&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/internal/io/fits.h?cvsroot=libcvd&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/libcvd/pnm_src/fits.cc?cvsroot=libcvd&r1=1.1&r2=1.2
Patches:
Index: cvd/documentation.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/documentation.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- cvd/documentation.h 1 Jan 2009 22:29:28 -0000 1.23
+++ cvd/documentation.h 8 Jan 2009 18:02:58 -0000 1.24
@@ -47,15 +47,14 @@
- Native
- PNM
- BMP
- - FITS
- - Support for FITS images of 1, 2 or 3 dimensions
(reading only).
+ - FITS (reading only)
- PS (saving only)
- EPS (saving only)
- External libraries required
- JPEG
- TIFF
- PNG
- - 1/8/16 bit integer and 32/64 bit floating point images in
greyscale, RGB and RGBA.
+ - 1/8/16/32 bit integer and 32/64 bit floating point images in
greyscale, RGB and RGBA.
- Optimum bit depth and colour depth selected automatically
- Image grabbing from video sources:
- Linux
Index: cvd/internal/io/fits.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/internal/io/fits.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- cvd/internal/io/fits.h 1 Jan 2009 22:29:29 -0000 1.1
+++ cvd/internal/io/fits.h 8 Jan 2009 18:02:58 -0000 1.2
@@ -55,18 +55,21 @@
void get_raw_pixel_line(unsigned char*);
void get_raw_pixel_line(signed short*);
+ void get_raw_pixel_line(unsigned short*);
void get_raw_pixel_line(signed int*);
void get_raw_pixel_line(float*);
void get_raw_pixel_line(double*);
void get_raw_pixel_line(Rgb<unsigned char>*);
void get_raw_pixel_line(Rgb<signed short>*);
+ void get_raw_pixel_line(Rgb<unsigned short>*);
void get_raw_pixel_line(Rgb<signed int>*);
void get_raw_pixel_line(Rgb<float>*);
void get_raw_pixel_line(Rgb<double>*);
void get_raw_pixel_line(Rgba<unsigned char>*);
void get_raw_pixel_line(Rgba<signed short>*);
+ void get_raw_pixel_line(Rgba<unsigned short>*);
void get_raw_pixel_line(Rgba<signed int>*);
void get_raw_pixel_line(Rgba<float>*);
void get_raw_pixel_line(Rgba<double>*);
@@ -77,20 +80,23 @@
typedef TypeList<byte,
TypeList<signed short,
+ TypeList<unsigned short,
TypeList<signed int,
TypeList<float,
TypeList<double,
TypeList<Rgb<byte>,
TypeList<Rgb<signed short>,
+ TypeList<Rgb<unsigned short>,
TypeList<Rgb<signed int>,
TypeList<Rgb<float>,
TypeList<Rgb<double>,
TypeList<Rgba<byte>,
TypeList<Rgba<signed short>,
+ TypeList<Rgba<unsigned short>,
TypeList<Rgba<signed int>,
TypeList<Rgba<float>,
TypeList<Rgba<double>,
- Head> > > > > > >
> > > > > > > > Types;
+ Head> > > > > > >
> > > > > > > > > > > Types;
private:
ReadPimpl* t;
Index: pnm_src/fits.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/pnm_src/fits.cc,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- pnm_src/fits.cc 1 Jan 2009 22:29:29 -0000 1.1
+++ pnm_src/fits.cc 8 Jan 2009 18:02:58 -0000 1.2
@@ -89,7 +89,7 @@
istringstream is(s);
is >> i;
- if(is.bad())
+ if(s.size() == 0 || is.bad())
throw(Exceptions::Image_IO::MalformedImage("Invalid integer: `"
+ s + "'"));
return i;
}
@@ -100,11 +100,23 @@
istringstream is(s);
is >> i;
- if(is.bad())
+ if(s.size() == 0 || is.bad())
throw(Exceptions::Image_IO::MalformedImage("Invalid unsigned
integer: `" + s + "'"));
return i;
}
+static double get_double(const string& s)
+{
+ double i;
+ istringstream is(s);
+ is >> i;
+
+ if(s.size() == 0 || is.bad())
+ throw(Exceptions::Image_IO::MalformedImage("Invalid double: `"
+ s + "'"));
+ return i;
+}
+
+
////////////////////////////////////////////////////////////////////////////////
//
// Private implementation of FITS reading
@@ -119,6 +131,11 @@
string datatype();
template<class C> void get_raw_pixel_line(C* data);
+ template<class C> void
convert_raw_pixel_line(unsigned char*, C* data);
+ template<template<class> class C> void
convert_raw_pixel_line(unsigned char*, C<unsigned short>* data);
+ void
convert_raw_pixel_line(unsigned char*, unsigned short* data);
+
+
private:
istream& i;
unsigned long row;
@@ -197,11 +214,36 @@
if(row > (unsigned long)my_size.y)
throw InternalLibraryError("CVD", "Read past end of image.");
+
unsigned char* rowp = &data[row * bytes_per_pixel * my_size.x];
row++;
+
+ convert_raw_pixel_line(rowp, d);
+}
+
+template<class T> void ReadPimpl::convert_raw_pixel_line(unsigned char* rowp,
T* d)
+{
copy(rowp, rowp + my_size.x * bytes_per_pixel, (unsigned char*)(d));
}
+template<template<class> class T> void
ReadPimpl::convert_raw_pixel_line(unsigned char* rowp, T<unsigned short>* d)
+{
+ unsigned short* ds = (unsigned short*)d;
+ int elements=my_size.x * sizeof(T<unsigned short>)/sizeof(unsigned
short);
+ for(int i=0; i < elements; i++)
+ ds[i] = (unsigned short)(static_cast<int>( ((short*)(rowp))[i])
+ 32768);
+}
+
+
+void ReadPimpl::convert_raw_pixel_line(unsigned char* rowp, unsigned short* d)
+{
+ for(int i=0; i < my_size.x; i++)
+ d[i] = (unsigned short)(static_cast<int>( ((short*)(rowp))[i])
+ 32768);
+}
+
+
+
+
string ReadPimpl::datatype()
{
return type;
@@ -270,22 +312,12 @@
a3 = get_uint(get_numeric_field());
}
}
-
- //Figure out the colourspace
- if(a3 == 1)
- type = type;
- else if(a3 == 2)
- type = "CVD::GreyAlpha<" + type + ">";
- else if(a3 == 3)
- type = "CVD::Rgb<" + type + ">";
- else if(a3 == 4)
- type = "CVD::Rgba<" + type + ">";
- else
- throw Exceptions::Image_IO::UnsupportedImageSubType("FITS",
"3rd axis (colour planes) has"+ get_numeric_field() + " elements(1, 2, 3 or 4
supported).");
-
my_size.x = a1;
my_size.y = a2;
+ double add_for_zero=0;
+ string bzero;
+
//Read the rest of the header
//The last useful card has END as the first keyword, but no separator.
//The remaining cards in the current stack should be blank.
@@ -294,9 +326,35 @@
for(;;)
{
next_card();
- if(get_keyword() == "END")
+ if(get_keyword() == "BZERO")
+ {
+ check_for_seperator();
+ add_for_zero = get_double(bzero=get_numeric_field());
+ }
+ else if(get_keyword() == "END")
break;
}
+cerr << add_for_zero << endl;
+ if(add_for_zero == 0) //OK
+ {}
+ else if(add_for_zero == 32768. && bpp == 16)
+ type = "unsigned short";
+ else
+ throw Exceptions::Image_IO::UnsupportedImageSubType("FITS",
"BZERO is " + bzero + ". Only 0 or 32768 (for int16 images) supported");
+
+
+ //Figure out the colourspace
+ if(a3 == 1)
+ type = type;
+ else if(a3 == 2)
+ type = "CVD::GreyAlpha<" + type + ">";
+ else if(a3 == 3)
+ type = "CVD::Rgb<" + type + ">";
+ else if(a3 == 4)
+ type = "CVD::Rgba<" + type + ">";
+ else
+ throw Exceptions::Image_IO::UnsupportedImageSubType("FITS",
"3rd axis (colour planes) has"+ get_numeric_field() + " elements(1, 2, 3 or 4
supported).");
+
//We should really use BZERO, too.
@@ -370,6 +428,7 @@
GEN3(unsigned char)
GEN3(signed short)
+GEN3(unsigned short)
GEN3(signed int)
GEN3(float)
GEN3(double)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libcvd-members] libcvd cvd/documentation.h cvd/internal/io/fits...,
Edward Rosten <=