Return a raster from a serialized form.
Serialized form is documented in doc/RFC1-SerializedFormat.
NOTE: the raster will contain pointer to the serialized form (including band data), which must be kept alive.
Definition at line 732 of file rt_serialize.c.
732 {
734 const uint8_t *ptr = NULL;
735 const uint8_t *beg = NULL;
736 uint16_t i = 0;
737 uint16_t j = 0;
738#ifdef WORDS_BIGENDIAN
740#else
741 uint8_t littleEndian =
LW_TRUE;
742#endif
743
744 assert(NULL != serialized);
745
747
748
749
750
751
752
753
754 RASTER_DEBUG(3,
"rt_raster_deserialize: Allocating memory for deserialized raster header");
756 if (!rast) {
757 rterror(
"rt_raster_deserialize: Out of memory allocating raster for deserialization");
758 return NULL;
759 }
760
761
762 RASTER_DEBUG(3,
"rt_raster_deserialize: Deserialize raster header");
764
765 if (0 ==
rast->numBands || header_only) {
768 }
769
770 beg = (const uint8_t*) serialized;
771
772
773 RASTER_DEBUG(3,
"rt_raster_deserialize: Allocating memory for bands");
775 if (
rast->bands == NULL) {
776 rterror(
"rt_raster_deserialize: Out of memory allocating bands");
778 return NULL;
779 }
780
782
783
784 ptr = beg;
786
787
788 for (i = 0; i <
rast->numBands; ++i) {
791 int pixbytes = 0;
792
794 if (!band) {
795 rterror(
"rt_raster_deserialize: Out of memory allocating rt_band during deserialization");
798 return NULL;
799 }
800
802
804 ptr++;
806
808
816
817
819 ptr += pixbytes - 1;
820
821
822 switch (
band->pixtype) {
825 break;
826 }
829 break;
830 }
833 break;
834 }
837 break;
838 }
841 break;
842 }
845 break;
846 }
849 break;
850 }
853 break;
854 }
857 break;
858 }
861 break;
862 }
865 break;
866 }
869 break;
870 }
871 default: {
872 rterror(
"rt_raster_deserialize: Unknown pixeltype %d",
band->pixtype);
875 return NULL;
876 }
877 }
878
881
882
883 assert(!((ptr - beg) % pixbytes));
884
886 int pathlen = 0;
887
888
889 band->data.offline.bandNum = *ptr;
890 ptr += 1;
891
892
893 pathlen = strlen((char*) ptr);
894 band->data.offline.path =
rtalloc(
sizeof(
char) * (pathlen + 1));
895 if (
band->data.offline.path == NULL) {
896 rterror(
"rt_raster_deserialize: Could not allocate memory for offline band path");
899 return NULL;
900 }
901
902 memcpy(
band->data.offline.path, ptr, pathlen);
903 band->data.offline.path[pathlen] =
'\0';
904 ptr += pathlen + 1;
905
906 band->data.offline.mem = NULL;
907 }
908 else {
909
910 const uint32_t datasize =
rast->width *
rast->height * pixbytes;
911 band->data.mem = (uint8_t*) ptr;
912 ptr += datasize;
913 }
914
915
916#if POSTGIS_DEBUG_LEVEL > 0
917 const uint8_t *padbeg = ptr;
918#endif
919 while (0 != ((ptr - beg) % 8)) {
920 ++ptr;
921 }
922
923 RASTER_DEBUGF(3,
"rt_raster_deserialize: skip %ld bytes of 8-bytes boundary padding", ptr - padbeg);
924
925
926 assert(!((ptr - beg) % pixbytes));
927 }
928
930}
#define LW_TRUE
Return types for functions with status returns.
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,...)
float rt_util_float16_to_float(uint16_t value)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
const char * rt_pixtype_name(rt_pixtype pixtype)
void rt_band_destroy(rt_band band)
Destroy a raster band.
void rtdealloc(void *mem)
struct rt_raster_t * rt_raster
Types definitions.
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
uint8_t read_uint8(const uint8_t **from)
double read_float64(const uint8_t **from, uint8_t littleEndian)
float read_float32(const uint8_t **from, uint8_t littleEndian)
int8_t read_int8(const uint8_t **from)
int16_t read_int16(const uint8_t **from, uint8_t littleEndian)
int32_t read_int32(const uint8_t **from, uint8_t littleEndian)
uint32_t read_uint32(const uint8_t **from, uint8_t littleEndian)
uint16_t read_uint16(const uint8_t **from, uint8_t littleEndian)
#define BANDTYPE_HAS_NODATA(x)
#define BANDTYPE_IS_OFFDB(x)
#define BANDTYPE_IS_NODATA(x)
#define BANDTYPE_PIXTYPE_MASK
References BANDTYPE_HAS_NODATA, BANDTYPE_IS_NODATA, BANDTYPE_IS_OFFDB, BANDTYPE_PIXTYPE_MASK, LW_FALSE, LW_TRUE, 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, read_float32(), read_float64(), read_int16(), read_int32(), read_int8(), read_uint16(), read_uint32(), read_uint8(), rt_band_destroy(), rt_pixtype_name(), rt_pixtype_size(), rt_raster_destroy(), rt_util_float16_to_float(), rtalloc(), rtdealloc(), and rterror().
Referenced by RASTER_addBand(), RASTER_addBandOutDB(), RASTER_addBandRasterArray(), RASTER_asGDALRaster(), RASTER_asHexWKB(), RASTER_asWKB(), RASTER_band(), RASTER_bandIsNoData(), RASTER_bandmetadata(), RASTER_clip(), RASTER_colorMap(), RASTER_contains(), RASTER_containsProperly(), RASTER_Contour(), RASTER_convex_hull(), RASTER_copyBand(), RASTER_coveredby(), RASTER_covers(), RASTER_dfullywithin(), RASTER_dumpAsPolygons(), RASTER_dumpValues(), RASTER_dwithin(), RASTER_envelope(), RASTER_GDALWarp(), RASTER_getBandFileSize(), RASTER_getBandFileTimestamp(), RASTER_getBandNoDataValue(), RASTER_getBandPath(), RASTER_getBandPixelType(), RASTER_getBandPixelTypeName(), RASTER_getGeometryValues(), RASTER_getGeotransform(), RASTER_getHeight(), RASTER_getNumBands(), RASTER_getPixelCentroids(), RASTER_getPixelHeight(), RASTER_getPixelPolygons(), RASTER_getPixelValue(), RASTER_getPixelValueResample(), RASTER_getPixelWidth(), RASTER_getPolygon(), RASTER_getSRID(), RASTER_getWidth(), RASTER_getXScale(), RASTER_getXSkew(), RASTER_getXUpperLeft(), RASTER_getYScale(), RASTER_getYSkew(), RASTER_getYUpperLeft(), RASTER_hasNoBand(), RASTER_histogram(), RASTER_InterpolateRaster(), RASTER_intersectionFractions(), RASTER_intersects(), RASTER_isEmpty(), RASTER_mapAlgebra2(), RASTER_mapAlgebraExpr(), RASTER_mapAlgebraFct(), RASTER_mapAlgebraFctNgb(), RASTER_metadata(), RASTER_nearestValue(), RASTER_neighborhood(), RASTER_nMapAlgebra(), RASTER_noop(), RASTER_notSameAlignmentReason(), RASTER_out(), RASTER_overlaps(), RASTER_pixelOfValue(), RASTER_quantile(), RASTER_rasterToWorldCoord(), RASTER_reclass(), RASTER_reclass_exact(), RASTER_sameAlignment(), 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_summaryStats(), RASTER_summaryStats_transfn(), RASTER_summaryStatsCoverage(), RASTER_tile(), RASTER_to_bytea(), RASTER_touches(), RASTER_union_transfn(), RASTER_valueCount(), RASTER_valueCountCoverage(), RASTER_worldToRasterCoord(), rtpg_nmapalgebra_rastbandarg_process(), and test_raster_wkb().