Skip to content

Commit

Permalink
Allowing negative strides.
Browse files Browse the repository at this point in the history
  • Loading branch information
crisluengo authored and Peter J. Verveer committed Jul 26, 2017
1 parent bb828bc commit 6a2bbed
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 111 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ check_PROGRAMS = test_ics1 \
test_gzip \
test_strides \
test_strides2 \
test_strides3 \
test_metadata \
test_history

Expand All @@ -57,6 +58,7 @@ test_compress_SOURCES = test_compress.c
test_gzip_SOURCES = test_gzip.c
test_strides_SOURCES = test_strides.c
test_strides2_SOURCES = test_strides2.c
test_strides3_SOURCES = test_strides3.c
test_metadata_SOURCES = test_metadata.c
test_history_SOURCES = test_history.c

Expand All @@ -67,6 +69,7 @@ test_compress_LDADD = libics.la
test_gzip_LDADD = libics.la
test_strides_LDADD = libics.la
test_strides2_LDADD = libics.la
test_strides3_LDADD = libics.la
test_metadata_LDADD = libics.la
test_history_LDADD = libics.la

Expand All @@ -77,6 +80,7 @@ TESTS = test_ics1.sh \
test_gzip.sh \
test_strides.sh \
test_strides2.sh \
test_strides3.sh \
test_metadata.sh \
test_history.sh

Expand Down
56 changes: 37 additions & 19 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ build_triplet = @build@
host_triplet = @host@
check_PROGRAMS = test_ics1$(EXEEXT) test_ics2a$(EXEEXT) \
test_ics2b$(EXEEXT) test_compress$(EXEEXT) test_gzip$(EXEEXT) \
test_strides$(EXEEXT) test_strides2$(EXEEXT) \
test_strides$(EXEEXT) test_strides2$(EXEEXT) test_strides3$(EXEEXT) \
test_metadata$(EXEEXT) test_history$(EXEEXT)
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
Expand Down Expand Up @@ -159,7 +159,7 @@ libics_la_OBJECTS = $(am_libics_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
am__v_lt_1 =
libics_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(libics_la_LDFLAGS) $(LDFLAGS) -o $@
Expand Down Expand Up @@ -190,18 +190,21 @@ test_strides_DEPENDENCIES = libics.la
am_test_strides2_OBJECTS = test_strides2.$(OBJEXT)
test_strides2_OBJECTS = $(am_test_strides2_OBJECTS)
test_strides2_DEPENDENCIES = libics.la
am_test_strides3_OBJECTS = test_strides3.$(OBJEXT)
test_strides3_OBJECTS = $(am_test_strides3_OBJECTS)
test_strides3_DEPENDENCIES = libics.la
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
am__v_at_1 =
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
Expand All @@ -215,25 +218,25 @@ LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
am__v_CC_1 =
am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
am__v_CCLD_1 =
SOURCES = $(libics_la_SOURCES) $(test_compress_SOURCES) \
$(test_gzip_SOURCES) $(test_history_SOURCES) \
$(test_ics1_SOURCES) $(test_ics2a_SOURCES) \
$(test_ics2b_SOURCES) $(test_metadata_SOURCES) \
$(test_strides_SOURCES) $(test_strides2_SOURCES)
$(test_strides_SOURCES) $(test_strides2_SOURCES) $(test_strides3_SOURCES)
DIST_SOURCES = $(libics_la_SOURCES) $(test_compress_SOURCES) \
$(test_gzip_SOURCES) $(test_history_SOURCES) \
$(test_ics1_SOURCES) $(test_ics2a_SOURCES) \
$(test_ics2b_SOURCES) $(test_metadata_SOURCES) \
$(test_strides_SOURCES) $(test_strides2_SOURCES)
$(test_strides_SOURCES) $(test_strides2_SOURCES) $(test_strides3_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
Expand Down Expand Up @@ -613,6 +616,7 @@ test_compress_SOURCES = test_compress.c
test_gzip_SOURCES = test_gzip.c
test_strides_SOURCES = test_strides.c
test_strides2_SOURCES = test_strides2.c
test_strides3_SOURCES = test_strides3.c
test_metadata_SOURCES = test_metadata.c
test_history_SOURCES = test_history.c
test_ics1_LDADD = libics.la
Expand All @@ -622,6 +626,7 @@ test_compress_LDADD = libics.la
test_gzip_LDADD = libics.la
test_strides_LDADD = libics.la
test_strides2_LDADD = libics.la
test_strides3_LDADD = libics.la
test_metadata_LDADD = libics.la
test_history_LDADD = libics.la
TESTS = test_ics1.sh \
Expand All @@ -631,6 +636,7 @@ TESTS = test_ics1.sh \
test_gzip.sh \
test_strides.sh \
test_strides2.sh \
test_strides3.sh \
test_metadata.sh \
test_history.sh

Expand Down Expand Up @@ -721,7 +727,7 @@ config.h: stamp-h1
stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
@rm -f stamp-h1
cd $(top_builddir) && $(SHELL) ./config.status config.h
$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
$(srcdir)/config.h.in: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
($(am__cd) $(top_srcdir) && $(AUTOHEADER))
rm -f stamp-h1
touch $@
Expand Down Expand Up @@ -772,7 +778,7 @@ clean-libLTLIBRARIES:
rm -f $${locs}; \
}

libics.la: $(libics_la_OBJECTS) $(libics_la_DEPENDENCIES) $(EXTRA_libics_la_DEPENDENCIES)
libics.la: $(libics_la_OBJECTS) $(libics_la_DEPENDENCIES) $(EXTRA_libics_la_DEPENDENCIES)
$(AM_V_CCLD)$(libics_la_LINK) -rpath $(libdir) $(libics_la_OBJECTS) $(libics_la_LIBADD) $(LIBS)

clean-checkPROGRAMS:
Expand All @@ -784,42 +790,46 @@ clean-checkPROGRAMS:
echo " rm -f" $$list; \
rm -f $$list

test_compress$(EXEEXT): $(test_compress_OBJECTS) $(test_compress_DEPENDENCIES) $(EXTRA_test_compress_DEPENDENCIES)
test_compress$(EXEEXT): $(test_compress_OBJECTS) $(test_compress_DEPENDENCIES) $(EXTRA_test_compress_DEPENDENCIES)
@rm -f test_compress$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_compress_OBJECTS) $(test_compress_LDADD) $(LIBS)

test_gzip$(EXEEXT): $(test_gzip_OBJECTS) $(test_gzip_DEPENDENCIES) $(EXTRA_test_gzip_DEPENDENCIES)
test_gzip$(EXEEXT): $(test_gzip_OBJECTS) $(test_gzip_DEPENDENCIES) $(EXTRA_test_gzip_DEPENDENCIES)
@rm -f test_gzip$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_gzip_OBJECTS) $(test_gzip_LDADD) $(LIBS)

test_history$(EXEEXT): $(test_history_OBJECTS) $(test_history_DEPENDENCIES) $(EXTRA_test_history_DEPENDENCIES)
test_history$(EXEEXT): $(test_history_OBJECTS) $(test_history_DEPENDENCIES) $(EXTRA_test_history_DEPENDENCIES)
@rm -f test_history$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_history_OBJECTS) $(test_history_LDADD) $(LIBS)

test_ics1$(EXEEXT): $(test_ics1_OBJECTS) $(test_ics1_DEPENDENCIES) $(EXTRA_test_ics1_DEPENDENCIES)
test_ics1$(EXEEXT): $(test_ics1_OBJECTS) $(test_ics1_DEPENDENCIES) $(EXTRA_test_ics1_DEPENDENCIES)
@rm -f test_ics1$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_ics1_OBJECTS) $(test_ics1_LDADD) $(LIBS)

test_ics2a$(EXEEXT): $(test_ics2a_OBJECTS) $(test_ics2a_DEPENDENCIES) $(EXTRA_test_ics2a_DEPENDENCIES)
test_ics2a$(EXEEXT): $(test_ics2a_OBJECTS) $(test_ics2a_DEPENDENCIES) $(EXTRA_test_ics2a_DEPENDENCIES)
@rm -f test_ics2a$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_ics2a_OBJECTS) $(test_ics2a_LDADD) $(LIBS)

test_ics2b$(EXEEXT): $(test_ics2b_OBJECTS) $(test_ics2b_DEPENDENCIES) $(EXTRA_test_ics2b_DEPENDENCIES)
test_ics2b$(EXEEXT): $(test_ics2b_OBJECTS) $(test_ics2b_DEPENDENCIES) $(EXTRA_test_ics2b_DEPENDENCIES)
@rm -f test_ics2b$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_ics2b_OBJECTS) $(test_ics2b_LDADD) $(LIBS)

test_metadata$(EXEEXT): $(test_metadata_OBJECTS) $(test_metadata_DEPENDENCIES) $(EXTRA_test_metadata_DEPENDENCIES)
test_metadata$(EXEEXT): $(test_metadata_OBJECTS) $(test_metadata_DEPENDENCIES) $(EXTRA_test_metadata_DEPENDENCIES)
@rm -f test_metadata$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_metadata_OBJECTS) $(test_metadata_LDADD) $(LIBS)

test_strides$(EXEEXT): $(test_strides_OBJECTS) $(test_strides_DEPENDENCIES) $(EXTRA_test_strides_DEPENDENCIES)
test_strides$(EXEEXT): $(test_strides_OBJECTS) $(test_strides_DEPENDENCIES) $(EXTRA_test_strides_DEPENDENCIES)
@rm -f test_strides$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_strides_OBJECTS) $(test_strides_LDADD) $(LIBS)

test_strides2$(EXEEXT): $(test_strides2_OBJECTS) $(test_strides2_DEPENDENCIES) $(EXTRA_test_strides2_DEPENDENCIES)
test_strides2$(EXEEXT): $(test_strides2_OBJECTS) $(test_strides2_DEPENDENCIES) $(EXTRA_test_strides2_DEPENDENCIES)
@rm -f test_strides2$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_strides2_OBJECTS) $(test_strides2_LDADD) $(LIBS)

test_strides3$(EXEEXT): $(test_strides3_OBJECTS) $(test_strides3_DEPENDENCIES) $(EXTRA_test_strides3_DEPENDENCIES)
@rm -f test_strides3$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_strides3_OBJECTS) $(test_strides3_LDADD) $(LIBS)

mostlyclean-compile:
-rm -f *.$(OBJEXT)

Expand Down Expand Up @@ -847,6 +857,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_metadata.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_strides.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_strides2.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_strides3.Po@am__quote@

.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
Expand Down Expand Up @@ -1148,6 +1159,13 @@ test_strides2.sh.log: test_strides2.sh
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_strides3.sh.log: test_strides3.sh
@p='test_strides3.sh'; \
b='test_strides3.sh'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_metadata.sh.log: test_metadata.sh
@p='test_metadata.sh'; \
b='test_metadata.sh'; \
Expand Down
2 changes: 1 addition & 1 deletion docs/Ics_Header.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ <h3 class="ident">DataStrides</h3>
neighbors. Not used when reading.</p>

<p class="info"><span class="headtxt">type</span>:
<tt class="keyword">size_t const*</tt></p>
<tt class="keyword">ptrdiff_t const*</tt></p>

<p class="info"><span class="headtxt">access</span>:
<tt class="funcident"><a href="TopLevelFunctions.html#IcsSetDataWithStrides">IcsSetDataWithStrides</a></tt>.</p>
Expand Down
8 changes: 6 additions & 2 deletions docs/TopLevelFunctions.html
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ <h3 class="ident"><a name="IcsGetDataWithStrides"></a>IcsGetDataWithStrides</h3>
(<span class="typeident"><a href="Ics_Header.html">ICS</a></span>*&nbsp;<span class="varident">ics</span>,
<span class="keyword">void&nbsp;const</span>*&nbsp;<span class="varident">src</span>,
<span class="keyword">size_t</span>&nbsp;<span class="varident">n</span>,
<span class="keyword">size_t&nbsp;const</span>*&nbsp;<span class="varident">strides</span>,
<span class="keyword">ptrdiff_t&nbsp;const</span>*&nbsp;<span class="varident">strides</span>,
<span class="keyword">int</span>&nbsp;<span class="varident">ndims</span>);
</p>

Expand All @@ -352,6 +352,8 @@ <h3 class="ident"><a name="IcsGetDataWithStrides"></a>IcsGetDataWithStrides</h3>
<p>This function does currently not work when the data is compressed with
<tt class="constant"><a href="Enums.html#Ics_Compression">IcsCompr_compress</a></tt>.</p>

<p>The parameter <tt class="varident">n</tt> is ignored.</p>

<p class="info"><span class="headtxt">errors</span>:
<tt class="constant">IcsErr_Alloc</tt>,
<tt class="constant">IcsErr_BitsVsSizeConfl</tt>,
Expand Down Expand Up @@ -582,7 +584,7 @@ <h3 class="ident"><a name="IcsSetDataWithStrides"></a>IcsSetDataWithStrides</h3>
(<span class="typeident"><a href="Ics_Header.html">ICS</a></span>*&nbsp;<span class="varident">ics</span>,
<span class="keyword">void&nbsp;const</span>*&nbsp;<span class="varident">src</span>,
<span class="keyword">size_t</span>&nbsp;<span class="varident">n</span>,
<span class="keyword">size_t&nbsp;const</span>*&nbsp;<span class="varident">strides</span>,
<span class="keyword">ptrdiff_t&nbsp;const</span>*&nbsp;<span class="varident">strides</span>,
<span class="keyword">int</span>&nbsp;<span class="varident">ndims</span>);
</p>

Expand All @@ -595,6 +597,8 @@ <h3 class="ident"><a name="IcsSetDataWithStrides"></a>IcsSetDataWithStrides</h3>
equal to the dimensionality of the data as specified earlier through
<tt class="funcident"><a href="#IcsSetLayout">IcsSetLayout</a></tt></p>

<p>The parameter <tt class="varident">n</tt> is ignored.</p>

<p class="info"><span class="headtxt">errors</span>:
<tt class="constant">IcsErr_DuplicateData</tt>,
<tt class="constant">IcsErr_FSizeConflict</tt>,
Expand Down
22 changes: 11 additions & 11 deletions libics.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ typedef struct _ICS {
/* Size of the data buffer: */
size_t dataLength;
/* Pixel strides (writing only): */
const size_t *dataStrides;
const ptrdiff_t *dataStrides;
/* '.ics' path/filename: */
char filename[ICS_MAXPATHLEN];
/* Number of elements in each dim: */
Expand Down Expand Up @@ -527,11 +527,11 @@ ICSEXPORT Ics_Error IcsGetROIData(ICS *ics,
/* Read the image from an ICS file into a sub-block of a memory block. To use
the defaults in one of the parameters, set the pointer to NULL. Only valid if
reading. */
ICSEXPORT Ics_Error IcsGetDataWithStrides(ICS *ics,
void *dest,
size_t n,
const size_t *stride,
int nDims);
ICSEXPORT Ics_Error IcsGetDataWithStrides(ICS *ics,
void *dest,
size_t n, // ignored
const ptrdiff_t *stride,
int nDims);


/* Read a portion of the image data from an ICS file. Only valid if reading. */
Expand Down Expand Up @@ -562,11 +562,11 @@ ICSEXPORT Ics_Error IcsSetData(ICS *ics,

/* Set the image data for an ICS image. The pointer to this data must be
accessible until IcsClose has been called. Only valid if writing. */
ICSEXPORT Ics_Error IcsSetDataWithStrides(ICS *ics,
const void *src,
size_t n,
const size_t *strides,
int nDims);
ICSEXPORT Ics_Error IcsSetDataWithStrides(ICS *ics,
const void *src,
size_t n,
const ptrdiff_t *strides,
int nDims);

/* Set the image source parameter for an ICS version 2.0 file. Only valid if
writing. */
Expand Down
14 changes: 7 additions & 7 deletions libics_binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@


/* Write uncompressed data, with strides. */
Ics_Error IcsWritePlainWithStrides(const void *src,
const size_t *dim,
const size_t *stride,
int nDims,
int nBytes,
FILE *file)
Ics_Error IcsWritePlainWithStrides(const void *src,
const size_t *dim,
const ptrdiff_t *stride,
int nDims,
int nBytes,
FILE *file)
{
ICSINIT;
size_t curpos[ICS_MAXDIM];
Expand All @@ -84,7 +84,7 @@ Ics_Error IcsWritePlainWithStrides(const void *src,
while (1) {
data = (char const*)src;
for (i = 1; i < nDims; i++) {
data += curpos[i] * stride[i] * nBytes;
data += (ptrdiff_t)curpos[i] * stride[i] * nBytes;
}
if (stride[0] == 1) {
if (fwrite(data, nBytes, dim[0], file) != dim[0]) {
Expand Down
16 changes: 8 additions & 8 deletions libics_gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ Ics_Error IcsWriteZip(const void *inBuf,


/* Write ZIP compressed data, with strides. */
Ics_Error IcsWriteZipWithStrides(const void *src,
const size_t *dim,
const size_t *stride,
int nDims,
int nBytes,
FILE *file,
int level)
Ics_Error IcsWriteZipWithStrides(const void *src,
const size_t *dim,
const ptrdiff_t *stride,
int nDims,
int nBytes,
FILE *file,
int level)
{
#ifdef ICS_ZLIB
ICSINIT;
Expand Down Expand Up @@ -277,7 +277,7 @@ Ics_Error IcsWriteZipWithStrides(const void *src,
while (1) {
data = (char const*)src;
for (i = 1; i < nDims; i++) { /* curPos[0]==0 here */
data += curPos[i] * stride[i] * nBytes;
data += (ptrdiff_t)curPos[i] * stride[i] * nBytes;
}
/* Get data line */
if (contiguousLine) {
Expand Down
Loading

0 comments on commit 6a2bbed

Please sign in to comment.