PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ rt_band_duplicate()

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 438 of file rt_band.c.

438  {
439  rt_band rtn = NULL;
440 
441  assert(band != NULL);
442 
443  /* offline */
444  if (band->offline) {
445  rtn = rt_band_new_offline(
446  band->width, band->height,
447  band->pixtype,
448  band->hasnodata, band->nodataval,
449  band->data.offline.bandNum, (const char *) band->data.offline.path
450  );
451  }
452  /* online */
453  else {
454  uint8_t *data = NULL;
455  data = rtalloc((size_t)rt_pixtype_size(band->pixtype) * band->width * band->height);
456  if (data == NULL) {
457  rterror("rt_band_duplicate: Out of memory allocating online band data");
458  return NULL;
459  }
460  memcpy(data, band->data.mem, (size_t)rt_pixtype_size(band->pixtype) * band->width * band->height);
461 
462  rtn = rt_band_new_inline(
463  band->width, band->height,
464  band->pixtype,
465  band->hasnodata, band->nodataval,
466  data
467  );
468  rt_band_set_ownsdata_flag(rtn, 1); /* we DO own this data!!! */
469  }
470 
471  if (rtn == NULL) {
472  rterror("rt_band_duplicate: Could not copy band");
473  return NULL;
474  }
475 
476  return rtn;
477 }
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
band
Definition: ovdump.py:58
data
Definition: ovdump.py:104
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_band.c:63
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:818
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_band.c:275

References ovdump::band, ovdump::data, rt_band_new_inline(), rt_band_new_offline(), rt_band_set_ownsdata_flag(), rt_pixtype_size(), rtalloc(), and rterror().

Referenced by rt_raster_copy_band().

Here is the call graph for this function:
Here is the caller graph for this function: