PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rt_raster_serialized_size()

static uint32_t rt_raster_serialized_size ( rt_raster  raster)
static

Definition at line 462 of file rt_serialize.c.

References ovdump::band, rt_raster_t::bands, rt_band_t::data, rt_raster_t::height, rt_raster_t::numBands, rt_band_t::offline, rt_band_t::pixtype, RASTER_DEBUGF, rt_pixtype_size(), rterror(), rt_raster_serialized_t::size, and rt_raster_t::width.

Referenced by rt_raster_serialize().

462  {
463  uint32_t size = sizeof (struct rt_raster_serialized_t);
464  uint16_t i = 0;
465 
466  assert(NULL != raster);
467 
468  RASTER_DEBUGF(3, "Serialized size with just header:%d - now adding size of %d bands",
469  size, raster->numBands);
470 
471  for (i = 0; i < raster->numBands; ++i) {
472  rt_band band = raster->bands[i];
473  rt_pixtype pixtype = band->pixtype;
474  int pixbytes = rt_pixtype_size(pixtype);
475 
476  if (pixbytes < 1) {
477  rterror("rt_raster_serialized_size: Corrupted band: unknown pixtype");
478  return 0;
479  }
480 
481  /* Add space for band type, hasnodata flag and data padding */
482  size += pixbytes;
483 
484  /* Add space for nodata value */
485  size += pixbytes;
486 
487  if (band->offline) {
488  /* Add space for band number */
489  size += 1;
490 
491  /* Add space for null-terminated path */
492  size += strlen(band->data.offline.path) + 1;
493  }
494  else {
495  /* Add space for raster band data */
496  size += pixbytes * raster->width * raster->height;
497  }
498 
499  RASTER_DEBUGF(3, "Size before alignment is %d", size);
500 
501  /* Align size to 8-bytes boundary (trailing padding) */
502  /* XXX jorgearevalo: bug here. If the size is actually 8-bytes aligned,
503  this line will add 8 bytes trailing padding, and it's not necessary */
504  /*size += 8 - (size % 8);*/
505  if (size % 8)
506  size += 8 - (size % 8);
507 
508  RASTER_DEBUGF(3, "Size after alignment is %d", size);
509  }
510 
511  return size;
512 }
uint16_t numBands
Definition: librtcore.h:2241
rt_pixtype pixtype
Definition: librtcore.h:2265
band
Definition: ovdump.py:57
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
rt_pixtype
Definition: librtcore.h:185
uint16_t height
Definition: librtcore.h:2253
unsigned int uint32_t
Definition: uthash.h:78
uint16_t width
Definition: librtcore.h:2252
union rt_band_t::@6 data
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
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
Struct definitions.
Definition: librtcore.h:2201
rt_band * bands
Definition: librtcore.h:2254
Here is the call graph for this function:
Here is the caller graph for this function: