1 /*-------------------------------------------------------------- 2 IP-format file I/O class Header Include File 3 Written by H.Goto , Jan. 1994 4 Modified by H.Goto , Feb. 1997 5 Modified by H.Goto , Apr. 2000 6 --------------------------------------------------------------*/ 7 8 /*-------------------------------------------------------------------- 9 Copyright (C) 1994-2000 Hideaki Goto 10 11 All Rights Reserved 12 13 Permission to use, copy, modify, and distribute this software and 14 its documentation for any purpose is hereby granted without fee, 15 provided that (i) the above copyright notice and this permission 16 notice appear in all copies and in supporting documentation, (ii) 17 the name of the author, Hideaki Goto, may not be used in any 18 advertising or otherwise to promote the sale, use or other 19 dealings in this software without prior written authorization 20 from the author, (iii) this software may not be used for 21 commercial products without prior written permission from the 22 author, and (iv) the notice of the modification is specified in 23 case of that the modified copies of this software are distributed. 24 25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 26 THE AUTHOR WILL NOT BE RESPONSIBLE FOR ANY DAMAGE CAUSED BY THIS 27 SOFTWARE. 28 --------------------------------------------------------------------*/ 29 30 31 #ifndef ipIO_h 32 #define ipIO_h 33 34 #include "utypes.h" 35 36 37 /*------------------------------------------------------ 38 IP-format file Load Class 39 ------------------------------------------------------*/ 40 41 class IPLOAD { 42 private: 43 FILE *fp; 44 int line; 45 int width,height,pixel; 46 int linebytes; 47 int byteorder,headersize; 48 uchar *linebuffer; 49 struct { 50 ushort width_bytes; 51 ushort height; 52 } ip_header; 53 struct { 54 uint32 width_bytes; 55 uint32 height; 56 } ip_header4; 57 int filetype; /* = 0 : 1bit/pixel */ 58 /* 1 : 8bit grayscale */ 59 uchar fgcol,bgcol; 60 void wordswap(ushort *d); 61 protected: 62 void convert_1to8(uchar *src,uchar *dst,int size); 63 public: 64 int setmode(int byteorder,int headersize); 65 /* byteorder = 0 : MSB First */ 66 /* 1 : LSB First */ 67 /* headersize = 2 : WORD */ 68 /* 4 : DWORD */ 69 int fileopen(char *path); 70 int fileclose(void); 71 int readLine(void *buf); 72 int readLine_gray(void *buf); getWidth(void)73 int getWidth(void) { return width; } getHeight(void)74 int getHeight(void) { return height; } getFiletype(void)75 int getFiletype(void) { return filetype; } 76 IPLOAD(void); 77 virtual ~IPLOAD(void); 78 }; 79 80 81 82 83 /*------------------------------------------------------ 84 IP-format file Save Class 85 ------------------------------------------------------*/ 86 87 class IPSAVE { 88 private: 89 FILE *fp; 90 char wfname[256]; 91 int width,height,pixel; 92 int linebytes; 93 int byteorder,headersize; 94 uchar *linebuffer; 95 struct { 96 ushort width_bytes; 97 ushort height; 98 } ip_header; 99 int filetype; /* = 0 : 1bit/pixel */ 100 /* 1 : 8bit grayscale */ 101 protected: 102 void convert_8to1(uchar *src,uchar *dst,int size,uchar threshold); 103 public: 104 int setmode(int byteorder,int headersize); 105 /* This function is now dummy. */ 106 int filecreat(char *path,int filetype,int width,int height); 107 int fileclose(void); 108 int writeLine(void *buf); 109 int writeLine_mono(void *buf,int threshold); 110 IPSAVE(void); 111 virtual ~IPSAVE(void); 112 }; 113 114 115 #endif // ipIO_h 116 117