PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_band_pixtype_16BSI()

static void test_band_pixtype_16BSI ( )
static

Definition at line 751 of file cu_band_basics.c.

751 {
752 rt_pixtype pixtype = PT_16BSI;
753 uint8_t *data = NULL;
754 rt_band band = NULL;
755 int width = 5;
756 int height = 5;
757 int err = 0;
758 int clamped = 0;
759 double val = 0;
760 int x;
761 int y;
762
763 /* inline band */
764 data = rtalloc(rt_pixtype_size(pixtype) * width * height);
765 CU_ASSERT(data != NULL);
766 memset(data, 0, rt_pixtype_size(pixtype) * width * height);
767
769 width, height,
770 pixtype,
771 0, 0,
772 data
773 );
774 CU_ASSERT(band != NULL);
776 CU_ASSERT(rt_band_get_ownsdata_flag(band));
777
778 err = rt_band_set_nodata(band, 1, &clamped);
779 CU_ASSERT_EQUAL(err, ES_NONE);
780 CU_ASSERT(!clamped);
781 rt_band_get_nodata(band, &val);
782 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
783
784 err = rt_band_set_nodata(band, 0, &clamped);
785 CU_ASSERT_EQUAL(err, ES_NONE);
786 CU_ASSERT(!clamped);
787 rt_band_get_nodata(band, &val);
788 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
789
790 err = rt_band_set_nodata(band, 31, &clamped);
791 CU_ASSERT_EQUAL(err, ES_NONE);
792 CU_ASSERT(!clamped);
793 rt_band_get_nodata(band, &val);
794 CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
795
796 err = rt_band_set_nodata(band, 255, &clamped);
797 CU_ASSERT_EQUAL(err, ES_NONE);
798 CU_ASSERT(!clamped);
799 rt_band_get_nodata(band, &val);
800 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
801
802 err = rt_band_set_nodata(band, -32767, &clamped);
803 CU_ASSERT_EQUAL(err, ES_NONE);
804 CU_ASSERT(!clamped);
805 rt_band_get_nodata(band, &val);
806 CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
807
808 err = rt_band_set_nodata(band, 32767, &clamped);
809 CU_ASSERT_EQUAL(err, ES_NONE);
810 CU_ASSERT(!clamped);
811 rt_band_get_nodata(band, &val);
812 CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
813
814 /* out of range (-32767..32767) */
815 err = rt_band_set_nodata(band, -32769, &clamped);
816 CU_ASSERT_EQUAL(err, ES_NONE);
817 CU_ASSERT(clamped);
818
819 /* out of range (-32767..32767) */
820 err = rt_band_set_nodata(band, 32769, &clamped);
821 CU_ASSERT_EQUAL(err, ES_NONE);
822 CU_ASSERT(clamped);
823
824 /* out of range (-32767..32767) */
825 err = rt_band_set_pixel(band, 0, 0, -32769, &clamped);
826 CU_ASSERT_EQUAL(err, ES_NONE);
827 CU_ASSERT(clamped);
828
829 /* out of range (-32767..32767) */
830 err = rt_band_set_pixel(band, 0, 0, 32769, &clamped);
831 CU_ASSERT_EQUAL(err, ES_NONE);
832 CU_ASSERT(clamped);
833
834 /* out of dimensions range */
835 err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, NULL);
836 CU_ASSERT((err != ES_NONE));
837
838 for (x=0; x<rt_band_get_width(band); ++x) {
839 for (y=0; y<rt_band_get_height(band); ++y) {
840 err = rt_band_set_pixel(band, x, y, 255, NULL);
841 CU_ASSERT_EQUAL(err, ES_NONE);
842 err = rt_band_get_pixel(band, x, y, &val, NULL);
843 CU_ASSERT_EQUAL(err, ES_NONE);
844 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
845
846 err = rt_band_set_pixel(band, x, y, -32767, NULL);
847 CU_ASSERT_EQUAL(err, ES_NONE);
848 err = rt_band_get_pixel(band, x, y, &val, NULL);
849 CU_ASSERT_EQUAL(err, ES_NONE);
850 CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
851
852 err = rt_band_set_pixel(band, x, y, 32767, NULL);
853 CU_ASSERT_EQUAL(err, ES_NONE);
854 err = rt_band_get_pixel(band, x, y, &val, NULL);
855 CU_ASSERT_EQUAL(err, ES_NONE);
856 CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
857 }
858 }
859
860 rt_band_destroy(band);
861}
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:64
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition rt_band.c:826
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:191
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition rt_band.c:799
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition rt_band.c:1551
rt_pixtype
Definition librtcore.h:188
@ PT_16BSI
Definition librtcore.h:194
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition rt_band.c:892
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition rt_band.c:1140
@ ES_NONE
Definition librtcore.h:182
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition rt_band.c:499
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition rt_band.c:2067
int rt_band_get_ownsdata_flag(rt_band band)
Return 0 (FALSE) or non-zero (TRUE) indicating if rt_band is responsible for managing the memory for ...
Definition rt_band.c:818
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition rt_band.c:808
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition rt_pixel.c:40

References ES_NONE, PT_16BSI, rt_band_destroy(), rt_band_get_height(), rt_band_get_nodata(), rt_band_get_ownsdata_flag(), rt_band_get_pixel(), rt_band_get_width(), rt_band_new_inline(), rt_band_set_nodata(), rt_band_set_ownsdata_flag(), rt_band_set_pixel(), rt_pixtype_size(), and rtalloc().

Referenced by band_basics_suite_setup().

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