Skip to content

Commit 83cb4af

Browse files
committed
WIP
1 parent 4c704f0 commit 83cb4af

File tree

9 files changed

+1090
-1192
lines changed

9 files changed

+1090
-1192
lines changed

build.py

Lines changed: 0 additions & 168 deletions
This file was deleted.

lib/interface/encode.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ extern int EncodeArray(
137137

138138
// Check array is C-style, contiguous and aligned
139139
if (PyArray_ISCARRAY_RO(arr) != 1) {
140-
py_error("The input array must be C-style, contiguous and aligned");
140+
py_error("The input array must be C-style, contiguous, aligned and in machine byte-order");
141141
return 7;
142142
};
143143

@@ -383,7 +383,12 @@ extern int EncodeArray(
383383
{
384384
ptr = PyArray_GETPTR3(arr, r, c, p);
385385
// `data[...]` is OPJ_INT32, so *may* support range i (1, 32), u (1, 31)
386-
image->comps[p].data[c + columns * r] = is_signed ? *(npy_int32 *) ptr : *(npy_uint32 *) ptr;
386+
if (is_signed) {
387+
image->comps[p].data[c + columns * r] = *(npy_int32 *) ptr;
388+
} else {
389+
image->comps[p].data[c + columns * r] = *(npy_uint32 *) ptr;
390+
391+
}
387392
}
388393
}
389394
}
@@ -780,37 +785,55 @@ extern int EncodeBuffer(
780785
{
781786
for (p = 0; p < samples_per_pixel; p++)
782787
{
783-
image->comps[p].data[ii] = is_signed ? *data : (unsigned char) *data;
788+
// comps[...].data[...] is OPJ_INT32 -> int32_t
789+
image->comps[p].data[ii] = is_signed ? (signed char) *data : (unsigned char) *data;
784790
data++;
785791
}
786792
}
787793
} else if (bytes_per_pixel == 2) {
788794
union {
789-
short val;
795+
signed short val;
790796
unsigned char vals[2];
791797
} u16;
792798

793799
for (OPJ_UINT64 ii = 0; ii < nr_pixels; ii++)
794800
{
795801
for (p = 0; p < samples_per_pixel; p++)
796802
{
803+
#ifdef ON_BE_SYSTEM
804+
u16.vals[1] = (unsigned char) *data;
805+
data++;
806+
u16.vals[0] = (unsigned char) *data;
807+
data++;
808+
#else
797809
u16.vals[0] = (unsigned char) *data;
798810
data++;
799811
u16.vals[1] = (unsigned char) *data;
800812
data++;
813+
#endif
801814
image->comps[p].data[ii] = is_signed ? u16.val : (unsigned short) u16.val;
802815
}
803816
}
804817
} else if (bytes_per_pixel == 4) {
805818
union {
806-
long val;
819+
signed long val;
807820
unsigned char vals[4];
808821
} u32;
809822

810823
for (OPJ_UINT64 ii = 0; ii < nr_pixels; ii++)
811824
{
812825
for (p = 0; p < samples_per_pixel; p++)
813826
{
827+
#ifdef ON_BE_SYSTEM
828+
u32.vals[3] = (unsigned char) *data;
829+
data++;
830+
u32.vals[2] = (unsigned char) *data;
831+
data++;
832+
u32.vals[1] = (unsigned char) *data;
833+
data++;
834+
u32.vals[0] = (unsigned char) *data;
835+
data++;
836+
#else
814837
u32.vals[0] = (unsigned char) *data;
815838
data++;
816839
u32.vals[1] = (unsigned char) *data;
@@ -819,7 +842,12 @@ extern int EncodeBuffer(
819842
data++;
820843
u32.vals[3] = (unsigned char) *data;
821844
data++;
822-
image->comps[p].data[ii] = is_signed ? u32.val : (unsigned long) u32.val;
845+
#endif
846+
if (is_signed) {
847+
image->comps[p].data[ii] = u32.val;
848+
} else {
849+
image->comps[p].data[ii] = (unsigned long) u32.val;
850+
}
823851
}
824852
}
825853
}

0 commit comments

Comments
 (0)