-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_strides2.c
120 lines (113 loc) · 3.23 KB
/
test_strides2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "libics.h"
int main(int argc, const char* argv[]) {
ICS* ip;
Ics_DataType dt;
int ndims;
size_t dims[ICS_MAXDIM];
size_t bufsize;
ptrdiff_t strides[3];
void* buf1;
void* buf2;
void* buf3;
Ics_Error retval;
if (argc != 3) {
fprintf(stderr, "Two file names required: in out\n");
exit(-1);
}
/* Read image */
retval = IcsOpen(&ip, argv[1], "r");
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not open input file: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
IcsGetLayout(ip, &dt, &ndims, dims);
strides[0] = (ptrdiff_t)(dims[1]*2);
strides[1] = 2;
strides[2] = (ptrdiff_t)(dims[0]*dims[1]*2);
bufsize = IcsGetDataSize(ip);
buf1 = malloc(bufsize);
if (buf1 == NULL) {
fprintf(stderr, "Could not allocate memory.\n");
exit(-1);
}
retval = IcsGetData(ip, buf1, bufsize);
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not read input image data: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
buf3 = malloc(2*bufsize);
if (buf3 == NULL) {
fprintf(stderr, "Could not allocate memory.\n");
exit(-1);
}
retval = IcsGetDataWithStrides(ip, buf3, 2*bufsize, strides, 3);
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not read input image data using strides: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
retval = IcsClose(ip);
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not close input file: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
/* Write image */
retval = IcsOpen(&ip, argv[2], "w2");
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not open output file: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
IcsSetLayout(ip, dt, ndims, dims);
IcsSetDataWithStrides(ip, buf3, 2*bufsize, strides, 3);
#ifdef ICS_ZLIB
IcsSetCompression(ip, IcsCompr_gzip, 6);
#endif
retval = IcsClose(ip);
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not write output file: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
/* Read image */
retval = IcsOpen(&ip, argv[2], "r");
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not open output file for reading: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
if (bufsize != IcsGetDataSize(ip)) {
fprintf(stderr, "Data in output file not same size as written.\n");
exit(-1);
}
buf2 = malloc(bufsize);
if (buf2 == NULL) {
fprintf(stderr, "Could not allocate memory.\n");
exit(-1);
}
retval = IcsGetData(ip, buf2, bufsize);
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not read output image data: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
retval = IcsClose(ip);
if (retval != IcsErr_Ok) {
fprintf(stderr, "Could not close output file: %s\n",
IcsGetErrorText(retval));
exit(-1);
}
if (memcmp(buf1, buf2, bufsize) != 0) {
fprintf(stderr, "Data in output file does not match data in input.\n");
exit(-1);
}
free(buf1);
free(buf2);
exit(0);
}