/* allocate dynamic memory large enough to hold in-file and app cells * Rmalloc allocates memory to hold nrOfCells * cells in both the in-file and app cell representation. Allocation * is done by malloc for other users. Our own (utrecht university) applications * calls ChkMalloc. Freeing memory allocated by Rmalloc is done by free (or Free). * * NOTE * Note that a possible RuseAs call must be done BEFORE Rmalloc. * * returns * a pointer the allocated memory or * NULL * if the request fails * * example * .so examples/_row.tr */ void *Rmalloc( const MAP *m, /* map handle */ size_t nrOfCells) /* number of cells allocated memory must hold */ { CSF_CR inFileCR = RgetCellRepr(m); CSF_CR largestCellRepr = LOG_CELLSIZE(m->appCR) > LOG_CELLSIZE(inFileCR) ? m->appCR : inFileCR; return CSF_MALLOC((size_t)CSFSIZEOF(nrOfCells, largestCellRepr)); }
/* read a stream of cells * RgetSomeCells views a raster as one linear stream of * cells, with row i+1 placed after row i. * In this stream any sequence can be read by specifying an * offset and the number of cells to be read * returns the number of cells read, just as fread * * example * .so examples/somecell.tr */ size_t RgetSomeCells( MAP *map, /* map handle */ size_t offset, /* offset from pixel (row,col) = (0,0) */ size_t nrCells, /* number of cells to be read */ void *buf)/* write-only. Buffer large enough to * hold nrCells cells in the in-file cell representation * or the in-app cell representation. */ { CSF_FADDR readAt; size_t cellsRead; UINT2 inFileCR = RgetCellRepr(map); offset <<= LOG_CELLSIZE(inFileCR); readAt = ADDR_DATA + (CSF_FADDR)offset; fseek(map->fp, (long)readAt, SEEK_SET); cellsRead = map->read(buf, (size_t)CELLSIZE(inFileCR), (size_t)nrCells, map->fp); PRECOND(map->file2app != NULL); map->file2app(nrCells, buf); return(cellsRead); }
/* write a stream of cells * RputSomeCells views a raster as one linear stream of * cells, with row i+1 placed after row i. * In this stream any sequence can be written by specifying an * offset and the number of cells to be written * returns the number of cells written, just as fwrite * * example * .so examples/somecell.tr */ size_t RputSomeCells( MAP *map, /* map handle */ size_t offset, /* offset from pixel (row,col) = (0,0) */ size_t nrCells, /* number of cells to be read */ void *buf)/* read-write. Buffer large enough to * hold nrCells cells in the in-file cell representation * or the in-app cell representation. * If these types are not equal then the buffer is * converted from the in-app to the in-file * cell representation. */ { CSF_FADDR writeAt; CSF_CR cr = map->raster.cellRepr; /* convert */ map->app2file(nrCells, buf); if (map->minMaxStatus == MM_KEEPTRACK) { const DF detMinMaxFunc[12] = { (DF)DetMinMaxUINT1, (DF)DetMinMaxUINT2, (DF)DetMinMaxUINT4, NULL /* 0x03 */ , (DF)DetMinMaxINT1 , (DF)DetMinMaxINT2 , (DF)DetMinMaxINT4 , NULL /* 0x07 */ , NULL /* 0x08 */ , NULL /* 0x09 */ , (DF)DetMinMaxREAL4, (DF)DetMinMaxREAL8 }; void *min = &(map->raster.minVal); void *max = &(map->raster.maxVal); PRECOND(CSF_UNIQ_CR_MASK(cr) < 12); PRECOND(detMinMaxFunc[CSF_UNIQ_CR_MASK(cr)] != NULL); detMinMaxFunc[CSF_UNIQ_CR_MASK(cr)](min, max, nrCells, buf); } else map->minMaxStatus = MM_WRONGVALUE; writeAt = ((CSF_FADDR)offset) << LOG_CELLSIZE(cr); writeAt += ADDR_DATA; if( csf_fseek(map->fp, writeAt, SEEK_SET) != 0 ) return 0; return(map->write(buf, (size_t)CELLSIZE(cr), (size_t)nrCells, map->fp)); }