PostGIS  2.4.9dev-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 186 of file rt_band.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().

186  {
187  rt_band rtn = NULL;
188 
189  assert(band != NULL);
190 
191  /* offline */
192  if (band->offline) {
193  rtn = rt_band_new_offline(
194  band->width, band->height,
195  band->pixtype,
196  band->hasnodata, band->nodataval,
197  band->data.offline.bandNum, (const char *) band->data.offline.path
198  );
199  }
200  /* online */
201  else {
202  uint8_t *data = NULL;
203  data = rtalloc(rt_pixtype_size(band->pixtype) * band->width * band->height);
204  if (data == NULL) {
205  rterror("rt_band_duplicate: Out of memory allocating online band data");
206  return NULL;
207  }
208  memcpy(data, band->data.mem, rt_pixtype_size(band->pixtype) * band->width * band->height);
209 
210  rtn = rt_band_new_inline(
211  band->width, band->height,
212  band->pixtype,
213  band->hasnodata, band->nodataval,
214  data
215  );
216  rt_band_set_ownsdata_flag(rtn, 1); /* we DO own this data!!! */
217  }
218 
219  if (rtn == NULL) {
220  rterror("rt_band_duplicate: Could not copy band");
221  return NULL;
222  }
223 
224  return rtn;
225 }
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:119
rt_pixtype pixtype
Definition: librtcore.h:2265
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
data
Definition: ovdump.py:103
uint16_t height
Definition: librtcore.h:2268
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:534
union rt_band_t::@6 data
double nodataval
Definition: librtcore.h:2272
uint16_t width
Definition: librtcore.h:2267
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
int32_t offline
Definition: librtcore.h:2266
void * mem
Definition: librtcore.h:2278
int32_t hasnodata
Definition: librtcore.h:2269
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:58
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: