5 #include <cvd/convert_image.h> 6 #include <cvd/exceptions.h> 7 #include <cvd/internal/load_and_save.h> 8 #include <cvd/internal/name_CVD_rgb_types.h> 9 #include <cvd/internal/name_builtin_types.h> 14 #include <type_traits> 16 #include <cvd/internal/io/bmp.h> 17 #include <cvd/internal/io/cvdimage.h> 18 #include <cvd/internal/io/fits.h> 19 #include <cvd/internal/io/jpeg.h> 20 #include <cvd/internal/io/png.h> 21 #include <cvd/internal/io/pnm_grok.h> 22 #include <cvd/internal/io/save_postscript.h> 23 #include <cvd/internal/io/text.h> 24 #include <cvd/internal/io/tiff.h> 82 #if DOXYGEN_INCLUDE_ONLY_FOR_DOCS 118 Image<C> img_load(
const std::string& i);
125 using AllImageTypes = std::tuple<PNM::Reader, JPEG::Reader, TIFF::Reader, PNG::Reader, BMP::Reader, FITS::Reader, CVDimage::Reader, TEXT::Reader>;
129 template <
class I,
class ImageTypeList,
int N = 0>
130 void img_load_tuple(
Image<I>& im, std::istream& i, [[maybe_unused]]
int c)
132 if constexpr(N == std::tuple_size_v<ImageTypeList>)
138 using ImageReader = std::tuple_element_t<N, ImageTypeList>;
140 if(ImageReader::first_byte_matches(c))
141 CVD::Internal::readImage<I, ImageReader>(im, i);
143 img_load_tuple<I, ImageTypeList, N + 1>(im, i, c);
147 template <
class... T>
150 using type = std::tuple<T...>;
153 template <
class... T>
156 using type = std::tuple<T...>;
161 template <
class I,
class Head = Internal::AllImageTypes,
class... ImageTypes>
162 void img_load(
Image<I>& im, std::istream& i)
169 if((fs = dynamic_cast<std::ifstream*>(&i)) && !fs->is_open())
179 Internal::img_load_tuple<I,
typename Internal::as_tuple<Head, ImageTypes...>::type>(im, i, c);
182 template <
class I,
class Head = Internal::AllImageTypes,
class... ImageTypes>
183 void img_load(
Image<I>& im,
const std::string& s)
185 std::ifstream i(s.c_str(), std::ios::in | std::ios::binary);
189 img_load<I, Head, ImageTypes...>(im, i);
192 #ifndef DOXYGEN_IGNORE_INTERNAL 195 template <
class... ImageTypes>
200 template <
class... ImageTypes>
212 img_load<C, ImageTypes...>(im, i);
216 template <
class... ImageTypes>
221 template <
class... ImageTypes>
229 const std::string& s;
233 img_load<C, ImageTypes...>(im, s);
239 template <
class... ImageTypes>
245 template <
class... ImageTypes>
279 template <
class PixelType>
288 Internal::writeImage<PixelType, PNM::Writer>(im, o, p);
291 Internal::writeImage<PixelType, JPEG::writer>(im, o, p);
294 Internal::writeImage<PixelType, PNG::png_writer>(im, o, p);
297 Internal::writeImage<PixelType, TIFF::tiff_writer>(im, o, p);
300 Internal::writeImage<PixelType, FITS::writer>(im, o, p);
303 Internal::writeImage<PixelType, BMP::Writer>(im, o, p);
306 Internal::writeImage<PixelType, TEXT::writer>(im, o, p);
309 Internal::writeImage<PixelType, PS::writer>(im, o, p);
312 Internal::writeImage<PixelType, PS::eps_writer>(im, o, p);
315 Internal::writeImage<PixelType, CVDimage::writer>(im, o, p);
320 template <
class PixelType>
323 std::ofstream out(name.c_str(), std::ios::out | std::ios::binary);
337 template <
class PixelType>
354 template <
class PixelType>
376 template <
class PixelType>
415 template <
class PixelType>
The ifstream which the file is being read from is not open.
Definition: load_and_save.h:55
TIFF image format.
Definition: image_io.h:55
void output_eps_footer(std::ostream &o)
Outputs an EPS footer to an ostream.
Postscript format.
Definition: image_io.h:63
All classes and functions are within the CVD namespace.
Definition: argb.h:6
ImageRef size() const
What is the size of this image?
Definition: image.h:557
PNM image format (PBM, PGM or PPM).
Definition: image_io.h:43
FITS images.
Definition: image_io.h:78
void pnm_load(Image< PixelType > &im, std::istream &i)
Load a PNM image from a stream.
Definition: image_io.h:377
void pnm_save(const BasicImage< PixelType > &im, std::ostream &o)
Save an image to a stream as a PNM.
Definition: image_io.h:355
void img_save(const BasicImage< PixelType > &im, std::ostream &o, ImageType::ImageType t, const std::map< std::string, Parameter<>> &p=std::map< std::string, Parameter<>>())
Save an image to a stream.
Definition: image_io.h:280
Error in opening file.
Definition: load_and_save.h:119
This image type is not supported.
Definition: load_and_save.h:41
Placeholder type telling save_image to deduce the type from the filename.
Definition: image_io.h:38
Definition: image_io.h:148
Definition: load_and_save.h:159
The file ended before the image.
Definition: load_and_save.h:48
JPEG image format.
Definition: image_io.h:46
Plain text format.
Definition: image_io.h:69
Definition: image_ref.h:29
Definition: image_io.h:217
void output_eps_header(std::ostream &o, int xs, int ys)
Outputs an EPS header to an ostream.
Windows BMP (or DIB) format. Uncompressed 8 bit grey scale and 24 bit RGB are supported.
Definition: image_io.h:48
ImageType::ImageType string_to_image_type(const std::string &name)
Deduce an image type from a filename suffix.
Definition: image_io.cc:89
A generic image class to manage a block of arbitrarily padded data as an image.
Definition: image.h:273
EPS format. This outputs a complete EPS (Encapsulated PostScript) figure.
Definition: image_io.h:65
Unknown image type (can be returned by string_to_image_type.
Definition: image_io.h:40
Definition: image_io.h:196
A full image which manages its own data.
Definition: image.h:623
PNG image format.
Definition: image_io.h:51
Class for holding parameters for image savers, with type erasure.
Definition: parameter.h:18
ImageType
Possible image types.
Definition: image_io.h:35
CVD image format.
Definition: image_io.h:75