PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ rt_util_dbl_trunc_warning()

int rt_util_dbl_trunc_warning ( double  initialvalue,
int32_t  checkvalint,
uint32_t  checkvaluint,
float  checkvalfloat,
double  checkvaldouble,
rt_pixtype  pixtype 
)

Definition at line 676 of file rt_util.c.

681  {
682  int result = 0;
683 
684  switch (pixtype) {
685  case PT_1BB:
686  case PT_2BUI:
687  case PT_4BUI:
688  case PT_8BSI:
689  case PT_8BUI:
690  case PT_16BSI:
691  case PT_16BUI:
692  case PT_32BSI: {
693  if (fabs(checkvalint - initialvalue) >= 1) {
694 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
695  rtwarn("Value set for %s band got clamped from %f to %d",
696  rt_pixtype_name(pixtype),
697  initialvalue, checkvalint
698  );
699 #endif
700  result = 1;
701  }
702  else if (checkvalint != initialvalue)
703  {
704 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
705  rtwarn("Value set for %s band got truncated from %f to %d",
706  rt_pixtype_name(pixtype),
707  initialvalue, checkvalint
708  );
709 #endif
710  result = 1;
711  }
712  break;
713  }
714  case PT_32BUI: {
715  if (fabs(checkvaluint - initialvalue) >= 1) {
716 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
717  rtwarn("Value set for %s band got clamped from %f to %u",
718  rt_pixtype_name(pixtype),
719  initialvalue, checkvaluint
720  );
721 #endif
722  result = 1;
723  }
724  else if (checkvaluint != initialvalue)
725  {
726 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
727  rtwarn("Value set for %s band got truncated from %f to %u",
728  rt_pixtype_name(pixtype),
729  initialvalue, checkvaluint
730  );
731 #endif
732  result = 1;
733  }
734  break;
735  }
736  case PT_32BF: {
737  /*
738  For float, because the initial value is a double,
739  there is very often a difference between the desired value and the obtained one
740  */
741  if (FLT_NEQ(checkvalfloat, initialvalue)) {
742 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
743  rtwarn("Value set for %s band got converted from %f to %f",
744  rt_pixtype_name(pixtype),
745  initialvalue, checkvalfloat
746  );
747 #endif
748  result = 1;
749  }
750  break;
751  }
752  case PT_64BF: {
753  if (FLT_NEQ(checkvaldouble, initialvalue)) {
754 #if POSTGIS_RASTER_WARN_ON_TRUNCATION > 0
755  rtwarn("Value set for %s band got converted from %f to %f",
756  rt_pixtype_name(pixtype),
757  initialvalue, checkvaldouble
758  );
759 #endif
760  result = 1;
761  }
762  break;
763  }
764  case PT_END:
765  break;
766  }
767 
768  return result;
769 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:262
#define FLT_NEQ(x, y)
Definition: librtcore.h:2386
@ PT_32BUI
Definition: librtcore.h:196
@ PT_2BUI
Definition: librtcore.h:189
@ PT_32BSI
Definition: librtcore.h:195
@ PT_END
Definition: librtcore.h:199
@ PT_4BUI
Definition: librtcore.h:190
@ PT_32BF
Definition: librtcore.h:197
@ PT_1BB
Definition: librtcore.h:188
@ PT_16BUI
Definition: librtcore.h:194
@ PT_8BSI
Definition: librtcore.h:191
@ PT_16BSI
Definition: librtcore.h:193
@ PT_64BF
Definition: librtcore.h:198
@ PT_8BUI
Definition: librtcore.h:192
void rtwarn(const char *fmt,...)
Definition: rt_context.c:244
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110

References FLT_NEQ, PT_16BSI, PT_16BUI, PT_1BB, PT_2BUI, PT_32BF, PT_32BSI, PT_32BUI, PT_4BUI, PT_64BF, PT_8BSI, PT_8BUI, PT_END, result, rt_pixtype_name(), and rtwarn().

Referenced by rt_band_reclass(), rt_band_set_nodata(), rt_band_set_pixel(), and rt_raster_generate_new_band().

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