NCBI C++ ToolKit
image_io.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_IMAGE___IMAGE_READER__HPP
2 #define GUI_IMAGE___IMAGE_READER__HPP
3 
4 /* $Id: image_io.hpp 33815 2007-05-04 17:18:18Z kazimird $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  * CImageIO -- framework for reading/writing images
33  */
34 
35 
36 #include <corelib/ncbistd.hpp>
37 #include <util/image/image.hpp>
38 
39 
41 
42 class CImageIOHandler;
43 
44 
45 //
46 // class CImageIO defines a static interface for reading and writing images
47 // from files.
48 //
49 // This class is a front end to a variety of format-specific readers and
50 // writers, and supported importing and exporing images in JPEG, PNG, GIF, BMP,
51 // SGI, and TIFF formats. In addition, this class supports importing and
52 // exporting sub-regions of images.
53 //
54 
56 {
57 public:
58 
59  // enumerated list of recognized image types
60  enum EType {
69  eRaw
70  };
71 
72  // enumerated list of compression grades
73  enum ECompress {
78 
79  eCompress_Min = eCompress_None,
80  eCompress_Max = eCompress_High,
81  eCompress_Default = eCompress_Medium
82  };
83 
84  // retrieve an image type from its magic number
85  static EType GetTypeFromMagic(CNcbiIstream& istr);
86  static EType GetTypeFromMagic(const string& file);
87 
88  // retrieve an image type from its file name
89  // this uses the provided extension as a hint to guess the expected file
90  // type
91  static EType GetTypeFromFileName(const string& file);
92 
93  // read an image from a file, returning the object for user management
94  static CImage* ReadImage(const string& file,
95  EType type = CImageIO::eUnknown);
96  static CImage* ReadImage(CNcbiIstream& istr,
97  EType type = CImageIO::eUnknown);
98 
99  static bool ReadImageInfo(const string& file,
100  size_t* width, size_t* height, size_t* depth,
101  EType* type);
102  static bool ReadImageInfo(CNcbiIstream& istr,
103  size_t* width, size_t* height, size_t* depth,
104  EType* type);
105 
106  // read only part of an image from a file
107  static CImage* ReadSubImage(CNcbiIstream& istr,
108  size_t x, size_t y, size_t w, size_t h,
109  EType type = CImageIO::eUnknown);
110  static CImage* ReadSubImage(const string& file,
111  size_t x, size_t y, size_t w, size_t h,
112  EType type = CImageIO::eUnknown);
113 
114  // write an image to a file in a specified format. If the format type is
115  // eUnknown, it will be guessed from the file extension.
116  static bool WriteImage(const CImage& image, CNcbiOstream& ostr,
117  EType type,
118  ECompress compress = eCompress_Default);
119  static bool WriteImage(const CImage& image, const string& file,
120  EType type = eUnknown,
121  ECompress compress = eCompress_Default);
122 
123  // write only part of an image to a file
124  static bool WriteSubImage(const CImage& image, CNcbiOstream& ostr,
125  size_t x, size_t y, size_t w, size_t h,
126  EType type,
127  ECompress compress = eCompress_Default);
128  static bool WriteSubImage(const CImage& image, const string& file,
129  size_t x, size_t y, size_t w, size_t h,
130  EType type = eUnknown,
131  ECompress compress = eCompress_Default);
132 
133 private:
134 
135  // retrieve an image I/O handler for a given type
136  static CImageIOHandler* x_GetHandler(EType type);
137 };
138 
139 
141 
142 #endif // GUI_IMAGE___IMAGE_READER__HPP
class CImageIOHandler This is the base class for all image I/O handlers, and defines the standard int...
@ eUnknown
Definition: image_io.hpp:61
@ eCompress_Low
Definition: image_io.hpp:75
@ eCompress_Medium
Definition: image_io.hpp:76
@ eCompress_High
Definition: image_io.hpp:77
@ eCompress_None
Definition: image_io.hpp:74
CImage –.
Definition: Image.hpp:66
Include a standard set of the NCBI C++ Toolkit most basic headers.
static unsigned char depth[2 *(256+1+29)+1]
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
Definition: ncbistre.hpp:146
#define NCBI_XIMAGE_EXPORT
Definition: ncbi_export.h:1147
@ eRaw
Definition: types.hpp:81
FILE * file
Definition: type.c:6
#define compress
Definition: zconf_cf.h:39
Modified on Fri Sep 20 14:57:15 2024 by modify_doxy.py rev. 669887