/usr/include/OverlayUnidraw/ovimport.h is in ivtools-dev 1.2.11a1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | /*
* Copyright (c) 1996-1999 Vectaport Inc., R.B. Kissh & Associates
* Copyright (c) 1994-1995 Vectaport Inc.
* Copyright (c) 1990, 1991 Stanford University
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the names of the copyright holders not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. The copyright holders make
* no representations about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
* IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/*
* OvImportCmd - a command for importing graphical objects
*/
#ifndef ov_import_h
#define ov_import_h
#include <Unidraw/Commands/command.h>
#include <stdio.h>
#include <sys/types.h>
class Bitmap;
class Component;
class Editor;
class FileHelper;
class GraphicComp;
class ImportChooser;
class OverlayRaster;
class PortableImageHelper;
class Raster;
class RasterOvComp;
//: command for importing arbitrary graphical files.
// command for importing arbitrary graphical files: a wide variety of raster files,
// idraw "PostScript" and regular "PostScript", compressed or not compressed,
// by URL or pathname. Useful static methods for constructing components, as well
// as full-on command for hooking into a file menu.
class OvImportCmd : public Command {
public:
enum FileType { UnknownFile, RasterFile, PostScriptFile, IvtoolsFile, CompressedFile };
// types of files to be imported.
OvImportCmd(Editor* = nil, ImportChooser* = nil);
OvImportCmd(ControlInfo* = nil, ImportChooser* = nil);
virtual ~OvImportCmd();
void Init(ImportChooser*);
void instream(istream*);
// set istream to import file from.
void pathname(const char*, boolean popen=false);
// set pathname to import file from; if 'popen' treat the path as a command.
const char* pathname() { return path_; }
// return pointer to pathname.
void preserve_selection(boolean);
// set flag to import without changing current selection in editor.
virtual Command* Copy();
virtual ClassId GetClassId();
virtual boolean IsA(ClassId);
virtual void Execute();
// check for non-empty selection, pop-up dialog box to specify input path
// and other import parameters, then import and paste result.
virtual boolean Reversible();
// returns false.
virtual GraphicComp* PostDialog();
// method that pops-up the dialog box and constructs the imported component.
virtual GraphicComp* Import(const char*);
// import from pathname.
virtual GraphicComp* Import(istream&);
// import from istream.
virtual GraphicComp* Import(istream&, boolean& empty);
// import from istream, returning flag to indicate if anything happened.
static boolean changeComp(RasterOvComp* oldComp, RasterOvComp* newComp);
static void detach(RasterOvComp*);
static GraphicComp* DoImport(
istream& instrm, boolean& empty, FileHelper& helper, Editor* ed,
boolean is_strm, const char* pathname, int& pnmfd, boolean cmdflag
);
static GraphicComp* TIFF_Image(const char*);
// generate RasterOvComp from TIFF file.
static OverlayRaster* TIFF_Raster(const char*);
// generate raster from TIFF file.
static GraphicComp* PGM_Image(const char*);
// generate RasterOvComp from PGM file.
static OverlayRaster* PGM_Raster(
const char*, boolean delayed = false, OverlayRaster* = nil,
IntCoord xbeg=-1, IntCoord xend=-1, IntCoord ybeg=-1, IntCoord yend=-1
);
// generate raster from PGM file, with option to delay reading pixel data
// until needed for display, and ability to specify a subimage. This method
// supports pre-tiled rasters as well, indicated by a "# tile <width> <height>"
// comment in the PGM header.
static GraphicComp* PGM_Image(istream&, boolean ascii=false);
// generate RasterOvComp from PGM istream.
static OverlayRaster* PGM_Raster(istream&, boolean ascii=false);
// generate raster from PGM istream.
static GraphicComp* PPM_Image(const char*);
// generate RasterOvComp from PPM file.
static OverlayRaster* PPM_Raster(
const char*, boolean delayed = false, OverlayRaster* = nil,
IntCoord xbeg=-1, IntCoord xend=-1, IntCoord ybeg=-1, IntCoord yend=-1
);
// generate raster from PPM file, with option to delay reading pixel data
// until needed for display, and ability to specify a subimage. This method
// supports pre-tiled rasters as well, indicated by a "# tile <width> <height>"
// comment in the PPM header.
static GraphicComp* PPM_Image(istream&, boolean ascii=false);
// generate RasterOvComp from PPM istream.
static OverlayRaster* PPM_Raster(istream& in, boolean ascii=false);
// generate raster from PPM istream.
static GraphicComp* PNM_Image(istream&, const char* creator = nil);
// generate RasterOvComp from a PNM istream (PBM, PGM, or PPM).
static GraphicComp* PNM_Image_Filter(istream&, boolean return_fd, int& fd,
const char* filter = nil);
// generate RasterOvComp from a PNM istream (PBM, PGM, or PPM), using a
// specified filter to convert from another format to one of the PNM formats.
// if 'return_fd' is true this method sets up and returns a file handle
// to import a raw PPM image.
static int Pipe_Filter(istream& in, const char* filter);
// low-level mechanism to filter an istream using an arbitrary command line
// filter. Uses a double-pipe/double-fork mechanism, where a child process
// is set up to read the istream and pipe it to a grandchild process,
// which reads the other end of the pipe, runs the data through the filter,
// and writes the result to a pipe whose other end is indicated by the
// return value of this method. This double-pipe/double-fork architecture
// avoids the deadlock possible in a double-pipe/single-fork architecture,
// especially when decompressing the incoming istream.
static boolean Tiling(int& width, int& height);
// return on-the-fly tiling parameters from command line: -tile, -twidth w,
// and -theight. When enabled this causes large PGM or PNM images to be
// read in as a grid of sub-image components, and any subsequent export or
// save to disk will reflect this.
static GraphicComp* XBitmap_Image(const char*);
// generate StencilOvComp from a X Bitmap file.
static Bitmap* XBitmap_Bitmap(const char*);
// generate bitmap from a X Bitmap file.
static GraphicComp* PBM_Image(const char*);
// generate StencilOvComp from a PBM file.
static Bitmap* PBM_Bitmap(const char*);
// generate bitmap from a PBM file.
static GraphicComp* PBM_Image(istream&);
// generate StencilOvComp from a PBM istream.
static Bitmap* PBM_Bitmap(istream&);
// generate bitmap from a PBM istream.
static const char* ReadCreator(const char* pathname);
// read creator from 'pathname', returning one of "COMPRESS", "GZIP",
// "TIFF", "SUN", "PBM", "PGM", "PPM", "PBMA", "PGMA", "PPMA", "JPEG",
// "BM", "ATK", "MP", "X11", "PCX", "IFF", "GIF", "RLE", "PNG", "idraw",
// or something else for arbitrary "PostScript".
static const char* ReadCreator(istream& in, FileType& type);
// read creator from istream, returning one of "COMPRESS", "GZIP",
// "TIFF", "SUN", "PBM", "PGM", "PPM", "PBMA", "PGMA", "PPMA", "JPEG",
// "BM", "ATK", "MP", "X11", "PCX", "IFF", "GIF", "RLE", "PNG", "idraw",
// or something else for arbitrary "PostScript", plus a FileType enum.
// The bytes read to determine the creator are pushed back onto
// the istream.
static FILE* CheckCompression(
FILE* file, const char *pathname, boolean& compressed);
// check the compression status of a file specified by 'pathname'.
static OverlayRaster* CreatePlaceImage();
// create placeholder image when doing asynchronous incremental downloads.
boolean is_url();
// return flag that indicates import is from a URL.
static const char* Create_Tiled_File(
const char* ppmfile, const char* tilefile, int twidth, int theight
);
// utility method for creating an internally tiled PGM or PPM file.
static FILE* Portable_Raster_Open(
PortableImageHelper*&, const char* pathname, int ppm, int& ncols,
int& nrows, boolean& compressed, boolean& tiled, int& twidth,
int& theight
);
// utility method for tiled or untiled access of PGM and PPM disk files.
static void center_import(Editor* ed, GraphicComp* comp);
// center imported component in the viewer.
Component* component() { return comp_; }
// return pointer to imported component.
boolean is_popen() {return popen_;}
// return true if
protected:
static OverlayRaster* PI_Raster_Read(
PortableImageHelper*, FILE* file, int ncols, int nrows,
boolean compressed, boolean tiled, boolean delayed,
OverlayRaster* raster, IntCoord xbeg, IntCoord xend, IntCoord ybeg,
IntCoord yend
);
// utility method for tiled or untiled access of PGM and PPM disk files.
static void PI_Normal_Read(
PortableImageHelper*, FILE* file, OverlayRaster* raster, int ncols,
int nrows, int xbeg, int xend, int ybeg, int yend
);
// utility method for untiled access of PGM and PPM disk files.
static void PI_Tiled_Read(
PortableImageHelper*, FILE* file, OverlayRaster* raster, int ncols,
int nrows, int xbeg, int xend, int ybeg, int yend
);
// utility method for tiled access of PGM and PPM disk files.
static GraphicComp* Portable_Image_Tiled(
PortableImageHelper*, const char* pathname, int twidth, int theight,
int width, int height, boolean compressed, boolean tiled
);
// utility method for tiled access of PGM and PPM disk files.
static GraphicComp* Create_Comp(
PortableImageHelper* pih, FILE*, const char* pathname, int width,
int height, boolean compressed, boolean tiled, int twidth,
int theight
);
// utility method for tiled or untiled access of PGM and PPM disk files.
protected:
FileHelper* helper_;
ImportChooser* chooser_;
istream* inptr_;
char* path_;
boolean popen_;
boolean preserve_selection_;
Component* comp_;
};
//: helper class for reading PGM or PPM images.
class PortableImageHelper {
public:
PortableImageHelper(boolean is_ascii=false)
{ _is_ascii = is_ascii; _maxval = 255;}
virtual boolean ppm() = 0;
virtual int bytes_per_pixel() = 0;
virtual void read_write_pixel( FILE* in, FILE* out ) = 0;
virtual const char* magic() = 0;
virtual void read_poke( OverlayRaster*, FILE*, u_long x, u_long y ) = 0;
virtual OverlayRaster* create_raster( u_long w, u_long h ) = 0;
boolean is_ascii() { return _is_ascii; }
void maxval(int maxv) { _maxval = maxv; }
int maxval() { return _maxval; }
protected:
boolean _is_ascii;
int _maxval;
};
//: helper class for reading PGM images.
class PGM_Helper : public PortableImageHelper {
public:
PGM_Helper(boolean is_ascii=false);
virtual boolean ppm();
virtual int bytes_per_pixel();
virtual void read_write_pixel( FILE* in, FILE* out );
virtual const char* magic();
virtual void read_poke( OverlayRaster*, FILE*, u_long x, u_long y );
virtual OverlayRaster* create_raster( u_long w, u_long h );
};
//: helper class for reading PPM images.
class PPM_Helper : public PortableImageHelper {
public:
PPM_Helper(boolean is_ascii=false);
virtual boolean ppm();
virtual int bytes_per_pixel();
virtual void read_write_pixel( FILE* in, FILE* out );
virtual const char* magic();
virtual void read_poke( OverlayRaster*, FILE*, u_long x, u_long y );
virtual OverlayRaster* create_raster( u_long w, u_long h );
};
#endif
|