summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'openjpeg/src/lib/openjp2/bench_dwt.c')
-rw-r--r--openjpeg/src/lib/openjp2/bench_dwt.c140
1 files changed, 110 insertions, 30 deletions
diff --git a/openjpeg/src/lib/openjp2/bench_dwt.c b/openjpeg/src/lib/openjp2/bench_dwt.c
index 8cb64d06..1124cd61 100644
--- a/openjpeg/src/lib/openjp2/bench_dwt.c
+++ b/openjpeg/src/lib/openjp2/bench_dwt.c
@@ -49,7 +49,8 @@ void init_tilec(opj_tcd_tilecomp_t * l_tilec,
OPJ_INT32 y0,
OPJ_INT32 x1,
OPJ_INT32 y1,
- OPJ_UINT32 numresolutions)
+ OPJ_UINT32 numresolutions,
+ OPJ_BOOL irreversible)
{
opj_tcd_resolution_t* l_res;
OPJ_UINT32 resno, l_level_no;
@@ -64,9 +65,16 @@ void init_tilec(opj_tcd_tilecomp_t * l_tilec,
(size_t)(l_tilec->y1 - l_tilec->y0);
l_tilec->data = (OPJ_INT32*) opj_malloc(sizeof(OPJ_INT32) * nValues);
for (i = 0; i < nValues; i++) {
- l_tilec->data[i] = getValue((OPJ_UINT32)i);
+ OPJ_INT32 val = getValue((OPJ_UINT32)i);
+ if (irreversible) {
+ OPJ_FLOAT32 fVal = (OPJ_FLOAT32)val;
+ memcpy(&l_tilec->data[i], &fVal, sizeof(OPJ_FLOAT32));
+ } else {
+ l_tilec->data[i] = val;
+ }
}
l_tilec->numresolutions = numresolutions;
+ l_tilec->minimum_num_resolutions = numresolutions;
l_tilec->resolutions = (opj_tcd_resolution_t*) opj_calloc(
l_tilec->numresolutions,
sizeof(opj_tcd_resolution_t));
@@ -98,9 +106,9 @@ void free_tilec(opj_tcd_tilecomp_t * l_tilec)
void usage(void)
{
printf(
- "bench_dwt [-size value] [-check] [-display] [-num_resolutions val]\n");
+ "bench_dwt [-decode|encode] [-I] [-size value] [-check] [-display]\n");
printf(
- " [-offset x y] [-num_threads val]\n");
+ " [-num_resolutions val] [-offset x y] [-num_threads val]\n");
exit(1);
}
@@ -131,6 +139,17 @@ OPJ_FLOAT64 opj_clock(void)
#endif
}
+static OPJ_FLOAT64 opj_wallclock(void)
+{
+#ifdef _WIN32
+ return opj_clock();
+#else
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return (OPJ_FLOAT64)tv.tv_sec + 1e-6 * (OPJ_FLOAT64)tv.tv_usec;
+#endif
+}
+
int main(int argc, char** argv)
{
int num_threads = 0;
@@ -146,16 +165,24 @@ int main(int argc, char** argv)
OPJ_BOOL check = OPJ_FALSE;
OPJ_INT32 size = 16384 - 1;
OPJ_FLOAT64 start, stop;
+ OPJ_FLOAT64 start_wc, stop_wc;
OPJ_UINT32 offset_x = ((OPJ_UINT32)size + 1) / 2 - 1;
OPJ_UINT32 offset_y = ((OPJ_UINT32)size + 1) / 2 - 1;
OPJ_UINT32 num_resolutions = 6;
+ OPJ_BOOL bench_decode = OPJ_TRUE;
+ OPJ_BOOL irreversible = OPJ_FALSE;
for (i = 1; i < argc; i++) {
- if (strcmp(argv[i], "-display") == 0) {
+ if (strcmp(argv[i], "-encode") == 0) {
+ bench_decode = OPJ_FALSE;
+ } else if (strcmp(argv[i], "-decode") == 0) {
+ bench_decode = OPJ_TRUE;
+ } else if (strcmp(argv[i], "-display") == 0) {
display = OPJ_TRUE;
- check = OPJ_TRUE;
} else if (strcmp(argv[i], "-check") == 0) {
check = OPJ_TRUE;
+ } else if (strcmp(argv[i], "-I") == 0) {
+ irreversible = OPJ_TRUE;
} else if (strcmp(argv[i], "-size") == 0 && i + 1 < argc) {
size = atoi(argv[i + 1]);
i ++;
@@ -179,18 +206,29 @@ int main(int argc, char** argv)
}
}
+ if (irreversible && check) {
+ /* Due to irreversible inverse DWT not being symetric of forward */
+ /* See BUG_WEIRD_TWO_INVK in dwt.c */
+ printf("-I and -check aren't compatible\n");
+ exit(1);
+ }
+
tp = opj_thread_pool_create(num_threads);
init_tilec(&tilec, (OPJ_INT32)offset_x, (OPJ_INT32)offset_y,
(OPJ_INT32)offset_x + size, (OPJ_INT32)offset_y + size,
- num_resolutions);
+ num_resolutions, irreversible);
if (display) {
printf("Before\n");
k = 0;
for (j = 0; j < tilec.y1 - tilec.y0; j++) {
for (i = 0; i < tilec.x1 - tilec.x0; i++) {
- printf("%d ", tilec.data[k]);
+ if (irreversible) {
+ printf("%f ", ((OPJ_FLOAT32*)tilec.data)[k]);
+ } else {
+ printf("%d ", tilec.data[k]);
+ }
k ++;
}
printf("\n");
@@ -223,45 +261,87 @@ int main(int argc, char** argv)
image_comp.dy = 1;
start = opj_clock();
- opj_dwt_decode(&tcd, &tilec, tilec.numresolutions);
+ start_wc = opj_wallclock();
+ if (bench_decode) {
+ if (irreversible) {
+ opj_dwt_decode_real(&tcd, &tilec, tilec.numresolutions);
+ } else {
+ opj_dwt_decode(&tcd, &tilec, tilec.numresolutions);
+ }
+ } else {
+ if (irreversible) {
+ opj_dwt_encode_real(&tcd, &tilec);
+ } else {
+ opj_dwt_encode(&tcd, &tilec);
+ }
+ }
stop = opj_clock();
- printf("time for dwt_decode: %.03f s\n", stop - start);
+ stop_wc = opj_wallclock();
+ printf("time for %s: total = %.03f s, wallclock = %.03f s\n",
+ bench_decode ? "dwt_decode" : "dwt_encode",
+ stop - start,
+ stop_wc - start_wc);
- if (display || check) {
- if (display) {
+ if (display) {
+ if (bench_decode) {
printf("After IDWT\n");
- k = 0;
- for (j = 0; j < tilec.y1 - tilec.y0; j++) {
- for (i = 0; i < tilec.x1 - tilec.x0; i++) {
+ } else {
+ printf("After FDWT\n");
+ }
+ k = 0;
+ for (j = 0; j < tilec.y1 - tilec.y0; j++) {
+ for (i = 0; i < tilec.x1 - tilec.x0; i++) {
+ if (irreversible) {
+ printf("%f ", ((OPJ_FLOAT32*)tilec.data)[k]);
+ } else {
printf("%d ", tilec.data[k]);
- k ++;
}
- printf("\n");
+ k ++;
}
+ printf("\n");
}
+ }
- opj_dwt_encode(&tilec);
- if (display) {
- printf("After FDWT\n");
+ if ((display || check) && !irreversible) {
+
+ if (bench_decode) {
+ opj_dwt_encode(&tcd, &tilec);
+ } else {
+ opj_dwt_decode(&tcd, &tilec, tilec.numresolutions);
+ }
+
+
+ if (display && !irreversible) {
+ if (bench_decode) {
+ printf("After FDWT\n");
+ } else {
+ printf("After IDWT\n");
+ }
k = 0;
for (j = 0; j < tilec.y1 - tilec.y0; j++) {
for (i = 0; i < tilec.x1 - tilec.x0; i++) {
- printf("%d ", tilec.data[k]);
+ if (irreversible) {
+ printf("%f ", ((OPJ_FLOAT32*)tilec.data)[k]);
+ } else {
+ printf("%d ", tilec.data[k]);
+ }
k ++;
}
printf("\n");
}
}
- if (check) {
- size_t idx;
- size_t nValues = (size_t)(tilec.x1 - tilec.x0) *
- (size_t)(tilec.y1 - tilec.y0);
- for (idx = 0; idx < nValues; idx++) {
- if (tilec.data[idx] != getValue((OPJ_UINT32)idx)) {
- printf("Difference found at idx = %u\n", (OPJ_UINT32)idx);
- exit(1);
- }
+ }
+
+ if (check) {
+
+ size_t idx;
+ size_t nValues = (size_t)(tilec.x1 - tilec.x0) *
+ (size_t)(tilec.y1 - tilec.y0);
+ for (idx = 0; idx < nValues; idx++) {
+ if (tilec.data[idx] != getValue((OPJ_UINT32)idx)) {
+ printf("Difference found at idx = %u\n", (OPJ_UINT32)idx);
+ exit(1);
}
}
}