1 #include "csf.h" 2 #include "csfimpl.h" 3 4 /* read a stream of cells 5 * RgetSomeCells views a raster as one linear stream of 6 * cells, with row i+1 placed after row i. 7 * In this stream any sequence can be read by specifying an 8 * offset and the number of cells to be read 9 * returns the number of cells read, just as fread 10 * 11 * example 12 * .so examples/somecell.tr RgetRow(MAP * map,size_t rowNr,void * buf)13 */ 14 size_t RgetSomeCells( 15 MAP *map, /* map handle */ 16 size_t offset, /* offset from pixel (row,col) = (0,0) */ 17 size_t nrCells, /* number of cells to be read */ 18 void *buf)/* write-only. Buffer large enough to 19 * hold nrCells cells in the in-file cell representation 20 * or the in-app cell representation. 21 */ 22 { 23 24 CSF_FADDR readAt; 25 size_t cellsRead; 26 UINT2 inFileCR = RgetCellRepr(map); 27 28 offset <<= LOG_CELLSIZE(inFileCR); 29 readAt = ADDR_DATA + (CSF_FADDR)offset; 30 if(csf_fseek(map->fp, readAt, SEEK_SET) != 0 ) 31 return 0; 32 cellsRead = map->read(buf, (size_t)CELLSIZE(inFileCR), 33 (size_t)nrCells, map->fp); 34 35 PRECOND(map->file2app != NULL); 36 map->file2app(nrCells, buf); 37 38 return(cellsRead); 39 } 40