PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_band rt_band_duplicate ( rt_band  band)

Create a new band duplicated from source band.

Memory is allocated for band path (if band is offline) or band data (if band is online). The caller is responsible for freeing the memory when the returned rt_band is destroyed.

Parameters
the band to duplicate
Returns
an rt_band or NULL on failure

Memory is allocated for band path (if band is offline) or band data (if band is online). The caller is responsible for freeing the memory when the returned rt_band is destroyed.

Parameters
the band to copy
Returns
an rt_band or NULL on failure

Definition at line 1594 of file rt_api.c.

References ovdump::data, rt_band_t::data, rt_band_t::hasnodata, rt_band_t::height, rt_band_t::mem, rt_band_t::nodataval, rt_band_t::offline, rt_band_t::pixtype, rt_band_new_inline(), rt_band_new_offline(), rt_band_set_ownsdata_flag(), rt_pixtype_size(), rtalloc(), rterror(), and rt_band_t::width.

Referenced by rt_raster_copy_band().

1594  {
1595  rt_band rtn = NULL;
1596 
1597  assert(band != NULL);
1598 
1599  /* offline */
1600  if (band->offline) {
1601  rtn = rt_band_new_offline(
1602  band->width, band->height,
1603  band->pixtype,
1604  band->hasnodata, band->nodataval,
1605  band->data.offline.bandNum, (const char *) band->data.offline.path
1606  );
1607  }
1608  /* online */
1609  else {
1610  uint8_t *data = NULL;
1611  data = rtalloc(rt_pixtype_size(band->pixtype) * band->width * band->height);
1612  if (data == NULL) {
1613  rterror("rt_band_duplicate: Out of memory allocating online band data");
1614  return NULL;
1615  }
1616  memcpy(data, band->data.mem, rt_pixtype_size(band->pixtype) * band->width * band->height);
1617 
1618  rtn = rt_band_new_inline(
1619  band->width, band->height,
1620  band->pixtype,
1621  band->hasnodata, band->nodataval,
1622  data
1623  );
1624  rt_band_set_ownsdata_flag(rtn, 1); /* we DO own this data!!! */
1625  }
1626 
1627  if (rtn == NULL) {
1628  rterror("rt_band_duplicate: Could not copy band");
1629  return NULL;
1630  }
1631 
1632  return rtn;
1633 }
tuple data
Definition: ovdump.py:103
rt_pixtype pixtype
Definition: rt_api.h:2239
uint16_t height
Definition: rt_api.h:2242
rt_band rt_band_new_inline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t *data)
Create an in-db rt_band with no data.
Definition: rt_api.c:1466
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_api.c:1097
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_api.c:1936
rt_band rt_band_new_offline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t bandNum, const char *path)
Create an out-db rt_band.
Definition: rt_api.c:1527
double nodataval
Definition: rt_api.h:2246
uint16_t width
Definition: rt_api.h:2241
union rt_band_t::@14 data
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
int32_t offline
Definition: rt_api.h:2240
void * mem
Definition: rt_api.h:2252
int32_t hasnodata
Definition: rt_api.h:2243

Here is the call graph for this function:

Here is the caller graph for this function: