]> www.wagner.pp.ru Git - oss/fgis.git/blob - include/epp.h
First checked in version
[oss/fgis.git] / include / epp.h
1 /* Epp file access definition */
2 # ifndef EPP_H
3 # define EPP_H
4 # include <stdio.h>
5 #ifndef EPPL_H
6 # include "eppl.h"
7 #endif
8 #ifndef EPP_ERR_H
9 # include "epp_err.h"
10 #endif
11 /* this structure defines internal representation of open EPP file */
12 typedef struct EPP { int fr,lr,fc,lc;
13                      double XLeft,YBottom,XRight,YTop;
14                      double cell_area;
15                      int offsite;
16                      int mode;
17                      unsigned short *widthtable, *row;
18                      int kind;
19                      FILE *F;
20                      int min,max;
21                      int width;
22                      int currentline;
23                      long filepos; 
24                      int cache_size;
25                      void *cache;
26                      int *counttable;
27                      unsigned char *packed_buffer;
28                      void (*position)(struct EPP* epp,int row);
29                      int modified;
30                     } EPP;
31 /*this structure used for simulatenouis operations on files with
32   different cell size*/
33 typedef struct { int ax,bx,cx,
34                      ay,by,cy;
35                } LINK_BUFFER,*EPP_LINK;
36
37 EPP *open_epp(char *pathname);
38 EPP *fopen_epp(FILE *f);
39 /* opens existing EPP file */
40 EPP *creat_epp(char *pathname,int first_col,int first_row,int last_col,
41                int last_row, double AXLeft,double AYTop, double AXRight, 
42                double AYBottom, int scale, int base, int offsite);
43 EPP *fcreat_epp(FILE *f,int first_col,int first_row,int last_col,
44                int last_row, double AXLeft,double AYTop, double AXRight, 
45                double AYBottom, int scale, int base, int offsite);
46                
47 /* creating epp file from scratch. All fields which are not defined as
48  parameters, are filled by default values. Kind depends of global variable
49  Create16bit */
50 extern int Create16bit; /* if non-zero, all created EPP files would be 16 bit*/
51 int set_epp_cache(EPP* epp,int lines);
52 /* set cache to lines lines. to keep accessed lines in memory.
53    affects only MAP_INPUT files*/
54 EPP* load_epp(char *filename);
55 /* loads EPP file given by name into memory. Keeps open file for saving*/
56 EPP* fload_epp(FILE *f);
57 /* loads EPP from given file. */
58 int load_new_epp(EPP *f);
59 /* fills write-only file with offsite and reopens it for read-write */
60 int save_epp(EPP* epp);
61 /* flushes file, loaded into memory
62    If file isn't modified, does nothing.
63  */
64
65 #define touch_epp(epp) ((epp)->mode|=MAP_MODIFIED)
66 /* marks file as modified to ensure that it would be actually written
67    by save_epp */
68
69 int save_epp_as(EPP* epp,char *newname);
70 /* saves loaded epp under new filename, making new stream default for this epp*/
71 int fsave_epp_as(EPP* epp,FILE *f);
72 /* saves loaded epp into new stream, making it default */
73 int epp_expand(EPP *epp);
74 /* converts loaded epp into file with greater depth */
75 EPP *creat_epp_as(char *pathname,EPP *pattern);
76 EPP *fcreat_epp_as(FILE *f,EPP *pattern);
77 /* creates new epp file, copiing a most header fields from given file */
78 void fast_convert_to_8bit(EPP *source,char *filename);
79 /* given a 16-bit epp file open for writing, writes a 8-bit epp file
80    containing low bytes from all pixels of source files. Closes both files
81    after that */
82 void get_epp_header(EPP* epp, EPPHEADER *h);
83 /* reads header of EPP file */
84 void change_epp_header(EPP* epp,EPPHEADER h);
85 /* changes several fields of EPP file */
86 void setcomment(EPP *epp,char *comment);
87 /* change comment of epp file, which was open by creat_epp or creat_epp_as */
88
89 char *getcomment(EPP *epp);
90 /* returns comment of EPP file (address of static buffer,which would be
91    overriden by next call */
92 int shift_epp(EPP *epp,int new_fr,int new_fc);
93 /* shifts row and col numbers to make fr and fc equial to fr and fc.
94    returns non-zero on success, zero, if some of boundaries hit signed short
95    limits */
96        
97 typedef int (*EPP_ITER_PROC)(int col,int row,int value);
98
99 int for_each_cell(EPP *epp, EPP_ITER_PROC action);
100 /* performs given operation for each non-offsite cell of existing EPP file
101    (terminated if action returns non-zero,
102    or performs operation for each cell of created EPP file, filling cell
103    by value, returned by action. value parameter in this case always containt
104    offsite of epp */
105 long count_cells(EPP *epp, EPP_ITER_PROC condition);
106 /* calls condition for each non-offsite cell in existing epp file, returns
107    count of cells, for which condition was non-zero */
108 extern int (*EndLineProc)(int row,int seqno,int total);
109 /* if not NULL, this function called from for_each_cell and count_cells
110    after processing of each line. If it returns non-zero, processing 
111    terminated */
112
113 void reset_epp(EPP *epp);
114 /* reopens epp file for reading. if file was in create mode, fills all non-filled
115 lines by offsite */
116
117 unsigned short int *epp_getline(EPP *epp,int x,int y);
118 /* returns pointer to array of integer, which represents line y of raster,
119    starting from col x. NULL if x<fr */
120 int  epp_get(EPP *epp,int x,int y);
121 /* returns value of given cell, offsite if cell is outside file boundaries */
122 void epp_put(EPP *epp,int x,int y,int value);
123 /* fills given cell by value. File must be in create mode. if line is not
124  current, does nothing if line above current or fills all lines between current
125  and specified by offsite */
126 void epp_putline(EPP *epp,int x1,int x2,int y,int value);
127 /* fills range of cells in same row by value. Shortcut for multiple epp_put */
128 /* fills given cell by value. File must be in create mode. if line is not */
129 int epp_contains(EPP *epp,int x,int y);
130 /* returns non-zero if <x,y> is within boundares of epp */
131 void close_epp(EPP *epp);
132 /*********** coordinate recalculation **********/
133 int epp_row(EPP *epp,double y);/* returns row by given alternate y */
134 int epp_col(EPP *epp,double x);/* returns col for given alternate x */
135 double alt_x(EPP *epp,int col);/* returns alternate x for given col */
136 double alt_y(EPP *epp,int row);/* returns alternate y for given row */
137 double alt_xc(EPP *epp,int col);/* returns alternate x for given col */
138 double alt_yc(EPP *epp,int row);/* returns alternate y for given row */
139 /**** this was private in pascal version ********/
140 void get_row(EPP *epp);/* reads and unpacks row of epp file */
141 void put_row(EPP *epp);/* packs and writes row */
142 /********* compatibility of files *************/
143 int compare_cell_size(EPP *f1,EPP *f2);
144 int is_aligned(EPP *f1,EPP *f2);
145 EPP_LINK link_epp(EPP *base,EPP *overlay);
146 int linked_row(EPP_LINK link,int row);
147 int linked_col(EPP_LINK link,int col);
148 # endif