1 /* Base type for supported image formats. Subclass this to add a new 2 * format. 3 */ 4 5 /* 6 7 This file is part of VIPS. 8 9 VIPS is free software; you can redistribute it and/or modify 10 it under the terms of the GNU Lesser General Public License as published by 11 the Free Software Foundation; either version 2 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Lesser General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22 02110-1301 USA 23 24 */ 25 26 /* 27 28 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk 29 30 */ 31 32 #ifndef IM_FORMAT_H 33 #define IM_FORMAT_H 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif /*__cplusplus*/ 38 39 #define VIPS_TYPE_FORMAT (vips_format_get_type()) 40 #define VIPS_FORMAT( obj ) \ 41 (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ 42 VIPS_TYPE_FORMAT, VipsFormat )) 43 #define VIPS_FORMAT_CLASS( klass ) \ 44 (G_TYPE_CHECK_CLASS_CAST( (klass), \ 45 VIPS_TYPE_FORMAT, VipsFormatClass)) 46 #define VIPS_IS_FORMAT( obj ) \ 47 (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_FORMAT )) 48 #define VIPS_IS_FORMAT_CLASS( klass ) \ 49 (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_FORMAT )) 50 #define VIPS_FORMAT_GET_CLASS( obj ) \ 51 (G_TYPE_INSTANCE_GET_CLASS( (obj), \ 52 VIPS_TYPE_FORMAT, VipsFormatClass )) 53 54 /* Image file properties. 55 */ 56 typedef enum { 57 VIPS_FORMAT_NONE = 0, /* No flags set */ 58 VIPS_FORMAT_PARTIAL = 1, /* Lazy read OK (eg. tiled tiff) */ 59 VIPS_FORMAT_BIGENDIAN = 2 /* Most-significant byte first */ 60 } VipsFormatFlags; 61 62 /* Don't instantiate these things, just use the class stuff. 63 */ 64 65 typedef struct _VipsFormat { 66 VipsObject parent_object; 67 /*< public >*/ 68 69 } VipsFormat; 70 71 typedef struct _VipsFormatClass { 72 VipsObjectClass parent_class; 73 74 /*< public >*/ 75 /* Is a file in this format. 76 */ 77 gboolean (*is_a)( const char * ); 78 79 /* Read just the header into the VipsImage. 80 */ 81 int (*header)( const char *, VipsImage * ); 82 83 /* Load the whole image. 84 */ 85 int (*load)( const char *, VipsImage * ); 86 87 /* Write the VipsImage to the file in this format. 88 */ 89 int (*save)( VipsImage *, const char * ); 90 91 /* Get the flags for this file in this format. 92 */ 93 VipsFormatFlags (*get_flags)( const char * ); 94 95 /* Loop over formats in this order, default 0. We need this because 96 * some formats can be read by several loaders (eg. tiff can be read 97 * by the libMagick loader as well as by the tiff loader), and we want 98 * to make sure the better loader comes first. 99 */ 100 int priority; 101 102 /* Null-terminated list of allowed suffixes, eg. ".tif", ".tiff". 103 */ 104 const char **suffs; 105 } VipsFormatClass; 106 107 GType vips_format_get_type( void ); 108 109 /* Map over and find formats. This uses type introspection to loop over 110 * subclasses of VipsFormat. 111 */ 112 void *vips_format_map( VipsSListMap2Fn fn, void *a, void *b ); 113 VipsFormatClass *vips_format_for_file( const char *filename ); 114 VipsFormatClass *vips_format_for_name( const char *filename ); 115 116 VipsFormatFlags vips_format_get_flags( VipsFormatClass *format, 117 const char *filename ); 118 119 /* Read/write an image convenience functions. 120 */ 121 int vips_format_read( const char *filename, VipsImage *out ); 122 int vips_format_write( VipsImage *in, const char *filename ); 123 124 /* Low-level read/write operations. 125 */ 126 int im_jpeg2vips( const char *filename, VipsImage *out ); 127 int im_bufjpeg2vips( void *buf, size_t len, 128 VipsImage *out, gboolean header_only ); 129 int im_vips2jpeg( VipsImage *in, const char *filename ); 130 int im_vips2mimejpeg( VipsImage *in, int qfac ); 131 int im_vips2bufjpeg( VipsImage *in, VipsImage *out, 132 int qfac, char **obuf, int *olen ); 133 134 int im_tiff2vips( const char *filename, VipsImage *out ); 135 int im_vips2tiff( VipsImage *in, const char *filename ); 136 int im_tile_cache( VipsImage *in, VipsImage *out, 137 int tile_width, int tile_height, int max_tiles ); 138 139 int im_magick2vips( const char *filename, VipsImage *out ); 140 int im_bufmagick2vips( void *buf, size_t len, 141 VipsImage *out, gboolean header_only ); 142 143 int im_exr2vips( const char *filename, VipsImage *out ); 144 145 int im_ppm2vips( const char *filename, VipsImage *out ); 146 int im_vips2ppm( VipsImage *in, const char *filename ); 147 148 int im_analyze2vips( const char *filename, VipsImage *out ); 149 150 int im_csv2vips( const char *filename, VipsImage *out ); 151 int im_vips2csv( VipsImage *in, const char *filename ); 152 153 int im_png2vips( const char *filename, VipsImage *out ); 154 int im_vips2png( VipsImage *in, const char *filename ); 155 int im_vips2bufpng( VipsImage *in, VipsImage *out, 156 int compression, int interlace, char **obuf, size_t *olen ); 157 158 int im_webp2vips( const char *filename, VipsImage *out ); 159 int im_vips2webp( VipsImage *in, const char *filename ); 160 161 int im_raw2vips( const char *filename, VipsImage *out, 162 int width, int height, int bpp, int offset ); 163 int im_vips2raw( VipsImage *in, int fd ); 164 165 int im_mat2vips( const char *filename, VipsImage *out ); 166 167 int im_rad2vips( const char *filename, VipsImage *out ); 168 int im_vips2rad( VipsImage *in, const char *filename ); 169 170 int im_fits2vips( const char *filename, VipsImage *out ); 171 int im_vips2fits( VipsImage *in, const char *filename ); 172 173 int im_vips2dz( VipsImage *in, const char *filename ); 174 175 #ifdef __cplusplus 176 } 177 #endif /*__cplusplus*/ 178 179 #endif /*IM_FORMAT_H*/ 180