Return this raster in serialized form.
Memory (band data included) is copied from rt_raster.
Serialized form is documented in doc/RFC1-SerializedFormat.
Definition at line 522 of file rt_serialize.c.
522 {
523 uint32_t size = 0;
524 uint8_t* ret = NULL;
525 uint8_t* ptr = NULL;
526 uint16_t i = 0;
527
528 assert(NULL != raster);
529
531 ret = (uint8_t*)
rtalloc(size);
532 if (!ret) {
533 rterror(
"rt_raster_serialize: Out of memory allocating %d bytes for serializing a raster", size);
534 return NULL;
535 }
536 memset(ret, '-', size);
537 ptr = ret;
538
539 RASTER_DEBUGF(3,
"sizeof(struct rt_raster_serialized_t):%lu",
543 RASTER_DEBUGF(3,
"serialized size:%lu", (
long unsigned) size);
544
545
546
547
548
549
551
552
554
555
557
558 RASTER_DEBUG(3,
"Start hex dump of raster being serialized using 0x2D to mark non-written bytes");
559
560#if POSTGIS_DEBUG_LEVEL > 2
561 uint8_t* dbg_ptr = ptr;
562 d_print_binary_hex("HEADER", dbg_ptr, size);
563#endif
564
566
567
568 for (i = 0; i <
raster->numBands; ++i) {
570 assert(NULL != band);
571
574 if (pixbytes < 1) {
575 rterror(
"rt_raster_serialize: Corrupted band: unknown pixtype");
577 return NULL;
578 }
579
580
581 *ptr =
band->pixtype;
583#ifdef POSTGIS_RASTER_DISABLE_OFFLINE
584 rterror(
"rt_raster_serialize: offdb raster support disabled at compile-time");
585 return NULL;
586#endif
588 }
589 if (
band->hasnodata) {
591 }
592
593 if (
band->isnodata) {
595 }
596
597#if POSTGIS_DEBUG_LEVEL > 2
598 d_print_binary_hex(
"PIXTYPE", dbg_ptr,
size);
599#endif
600
601 ptr += 1;
602
603
604 if (pixbytes > 1) {
605 memset(ptr, '\0', pixbytes - 1);
606 ptr += pixbytes - 1;
607 }
608
609#if POSTGIS_DEBUG_LEVEL > 2
610 d_print_binary_hex(
"PADDING", dbg_ptr,
size);
611#endif
612
613
614 assert(!((ptr - ret) % pixbytes));
615
616
617 switch (pixtype) {
622 uint8_t v =
band->nodataval;
623 *ptr = v;
624 ptr += 1;
625 break;
626 }
628 int8_t v =
band->nodataval;
629 *ptr = (uint8_t)v;
630 ptr += 1;
631 break;
632 }
634 int16_t v =
band->nodataval;
635 memcpy(ptr, &v, 2);
636 ptr += 2;
637 break;
638 }
640 uint16_t v =
band->nodataval;
641 memcpy(ptr, &v, 2);
642 ptr += 2;
643 break;
644 }
646 int32_t v =
band->nodataval;
647 memcpy(ptr, &v, 4);
648 ptr += 4;
649 break;
650 }
652 uint32_t v =
band->nodataval;
653 memcpy(ptr, &v, 4);
654 ptr += 4;
655 break;
656 }
659 memcpy(ptr, &v, 2);
660 ptr += 2;
661 break;
662 }
664 float v =
band->nodataval;
665 memcpy(ptr, &v, 4);
666 ptr += 4;
667 break;
668 }
670 memcpy(ptr, &
band->nodataval, 8);
671 ptr += 8;
672 break;
673 }
674 default:
675 rterror(
"rt_raster_serialize: Fatal error caused by unknown pixel type. Aborting.");
677 return NULL;
678 }
679
680
681 assert(!((ptr - ret) % pixbytes));
682
683#if POSTGIS_DEBUG_LEVEL > 2
684 d_print_binary_hex(
"nodata", dbg_ptr,
size);
685#endif
686
688
689 *ptr =
band->data.offline.bandNum;
690 ptr += 1;
691
692
693 strcpy((
char*) ptr,
band->data.offline.path);
694 ptr += strlen(
band->data.offline.path) + 1;
695 }
696 else {
697
698 uint32_t datasize =
raster->width *
raster->height * pixbytes;
699 memcpy(ptr,
band->data.mem, datasize);
700 ptr += datasize;
701 }
702
703#if POSTGIS_DEBUG_LEVEL > 2
704 d_print_binary_hex(
"BAND", dbg_ptr,
size);
705#endif
706
707
708 while ((ptr-ret) % 8) {
709 *ptr = 0;
710 ++ptr;
711 }
712
713
714 assert(!((ptr - ret) % pixbytes));
715 }
716
717#if POSTGIS_DEBUG_LEVEL > 2
718 d_print_binary_hex(
"SERIALIZED RASTER", dbg_ptr,
size);
719#endif
720 return ret;
721}
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.
#define RASTER_DEBUG(level, msg)
#define RASTER_DEBUGF(level, msg,...)
uint16_t rt_util_float_to_float16(float value)
void rtdealloc(void *mem)
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
static uint32_t rt_raster_serialized_size(rt_raster raster)
#define BANDTYPE_FLAG_HASNODATA
#define BANDTYPE_FLAG_OFFDB
#define BANDTYPE_FLAG_ISNODATA
References BANDTYPE_FLAG_HASNODATA, BANDTYPE_FLAG_ISNODATA, BANDTYPE_FLAG_OFFDB, PT_16BF, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, RASTER_DEBUG, RASTER_DEBUGF, rt_pixtype_size(), rt_raster_serialized_size(), rt_util_float_to_float16(), rtalloc(), rtdealloc(), rterror(), and rt_raster_serialized_t::size.
Referenced by RASTER_addBand(), RASTER_addBandOutDB(), RASTER_addBandRasterArray(), RASTER_asRaster(), RASTER_band(), RASTER_clip(), RASTER_colorMap(), RASTER_copyBand(), RASTER_fromGDALRaster(), RASTER_fromHexWKB(), RASTER_fromWKB(), RASTER_GDALWarp(), RASTER_in(), RASTER_InterpolateRaster(), RASTER_intersectionFractions(), RASTER_makeEmpty(), RASTER_mapAlgebra2(), RASTER_mapAlgebraExpr(), RASTER_mapAlgebraFct(), RASTER_mapAlgebraFctNgb(), RASTER_nMapAlgebra(), RASTER_nMapAlgebraExpr(), RASTER_noop(), RASTER_reclass(), RASTER_reclass_exact(), RASTER_setBandIsNoData(), RASTER_setBandNoDataValue(), RASTER_setBandPath(), RASTER_setGeotransform(), RASTER_setPixelValue(), RASTER_setPixelValuesArray(), RASTER_setPixelValuesGeomval(), RASTER_setRotation(), RASTER_setScale(), RASTER_setScaleXY(), RASTER_setSkew(), RASTER_setSkewXY(), RASTER_setSRID(), RASTER_setUpperLeftXY(), RASTER_tile(), RASTER_union_finalfn(), and test_raster_wkb().