30 #define __attribute__(x) 37 #include "boost/serialization/shared_ptr.hpp" 38 #include "boost/serialization/binary_object.hpp" 39 #include "boost/serialization/nvp.hpp" 41 #include <boost/archive/text_oarchive.hpp> 42 #include <boost/archive/text_iarchive.hpp> 43 #include <boost/archive/binary_oarchive.hpp> 44 #include <boost/archive/binary_iarchive.hpp> 54 LOG_LOGGER _log =
LOG_GET(
"afw.ImageFormatter");
57 using boost::serialization::make_nvp;
69 namespace formatters {
71 template <
typename ImagePixelT>
103 template <
typename ImagePixelT>
107 template <
typename ImagePixelT>
111 template <
typename ImagePixelT>
119 template <
typename ImagePixelT>
123 LOGL_DEBUG(_log,
"ImageFormatter write start");
131 LOGL_DEBUG(_log,
"ImageFormatter write BoostStorage");
132 boost->getOArchive() & *ip;
138 LOGL_DEBUG(_log,
"ImageFormatter write XmlStorage");
139 xml->getOArchive() & make_nvp(
"img", *ip);
145 LOGL_DEBUG(_log,
"ImageFormatter write FitsStorage");
148 if (additionalData) {
152 LOGLS_WARN(_log,
"Unable to construct image write options (" 153 << exc.
what() <<
"); writing with default options");
167 template <
typename ImagePixelT>
170 LOGL_DEBUG(_log,
"ImageFormatter read start");
174 LOGL_DEBUG(_log,
"ImageFormatter read BoostStorage");
176 boost->getIArchive() & *ip;
182 LOGL_DEBUG(_log,
"ImageFormatter read XmlStorage");
184 xml->getIArchive() & make_nvp(
"img", *ip);
190 LOGL_DEBUG(_log,
"ImageFormatter read FitsStorage");
192 if (additionalData->exists(
"llcX")) {
193 int llcX = additionalData->
get<
int>(
"llcX");
194 int llcY = additionalData->
get<
int>(
"llcY");
195 int width = additionalData->
get<
int>(
"width");
196 int height = additionalData->
get<
int>(
"height");
200 if (additionalData->exists(
"imageOrigin")) {
202 if (originStr ==
"LOCAL") {
204 }
else if (originStr ==
"PARENT") {
208 (boost::format(
"Unknown ImageOrigin type %s specified in additional" 209 "data for retrieving Image from fits") %
229 template <
typename ImagePixelT>
235 template <
typename ImagePixelT>
236 template <
class Archive>
238 LOGL_DEBUG(_log,
"ImageFormatter delegateSerialize start");
244 if (Archive::is_saving::value) {
248 ar& make_nvp(
"width", width) & make_nvp(
"height", height);
249 if (Archive::is_loading::value) {
252 ar& make_nvp(
"array", boost::serialization::make_array(array.getData(), array.getNumElements()));
255 ndarray::Array<ImagePixelT, 2, 2> array = ndarray::dynamic_dimension_cast<2>(ip->
getArray());
256 if (array.empty()) array = ndarray::copy(ip->
getArray());
257 ar& make_nvp(
"array", boost::serialization::make_array(array.getData(), array.getNumElements()));
261 template <
typename ImagePixelT>
267 #define InstantiateFormatter(ImagePixelT) \ 268 template class ImageFormatter<ImagePixelT>; \ 269 template void ImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_oarchive&, int const, \ 271 template void ImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::text_iarchive&, int const, \ 273 template void ImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::xml_oarchive&, int const, \ 275 template void ImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::xml_iarchive&, int const, \ 277 template void ImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_oarchive&, \ 278 int const, Persistable*); \ 279 template void ImageFormatter<ImagePixelT>::delegateSerialize(boost::archive::binary_iarchive&, \ 280 int const, Persistable*); 288 #undef InstantiateSerializer #define LOGLS_WARN(logger, message)
int getHeight() const
Return the number of rows in the image.
Options for writing an image to FITS.
void writeFits(std::string const &fileName, std::shared_ptr< lsst::daf::base::PropertySet const > metadata=std::shared_ptr< lsst::daf::base::PropertySet const >(), std::string const &mode="w") const
Write an image to a regular FITS file.
#define LOGL_DEBUG(logger, message...)
A base class for image defects.
T dynamic_pointer_cast(T... args)
#define LSST_EXCEPT(type,...)
int getWidth() const
Return the number of columns in the image.
A class to represent a 2-dimensional array of pixels.