diff options
| author | Matthieu Darbois <mayeut@users.noreply.github.com> | 2014-11-19 20:05:39 +0000 |
|---|---|---|
| committer | Matthieu Darbois <mayeut@users.noreply.github.com> | 2014-11-19 20:05:39 +0000 |
| commit | 3bc360fc9d58b25493af4084394955e790fce26b (patch) | |
| tree | 84cd8df9b63e7976875429cc22b4b3abb29c600b /src/bin/jp2/convert.c | |
| parent | ae1da37558796508abcaff73632fb2ab06decb9f (diff) | |
[trunk] added option to force output bit depth in opj_decompress (fixes issue 283)
Diffstat (limited to 'src/bin/jp2/convert.c')
| -rw-r--r-- | src/bin/jp2/convert.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 6af7b7ab..7ada9a41 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -67,6 +67,84 @@ static int int_floorlog2(int a) { return l; } +/* Component precision scaling */ +void clip_component(opj_image_comp_t* component, OPJ_UINT32 precision) +{ + OPJ_SIZE_T i; + OPJ_SIZE_T len; + OPJ_UINT32 umax = (OPJ_UINT32)((OPJ_INT32)-1); + + len = (OPJ_SIZE_T)component->w * (OPJ_SIZE_T)component->h; + if (precision < 32) { + umax = (1U << precision) - 1U; + } + + if (component->sgnd) { + OPJ_INT32* l_data = component->data; + OPJ_INT32 max = (OPJ_INT32)(umax / 2U); + OPJ_INT32 min = -max - 1; + for (i = 0; i < len; ++i) { + if (l_data[i] > max) { + l_data[i] = max; + } else if (l_data[i] < min) { + l_data[i] = min; + } + } + } else { + OPJ_UINT32* l_data = (OPJ_UINT32*)component->data; + for (i = 0; i < len; ++i) { + if (l_data[i] > umax) { + l_data[i] = umax; + } + } + } + component->prec = precision; +} + +/* Component precision scaling */ +void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision) +{ + int shift; + OPJ_SIZE_T i; + OPJ_SIZE_T len; + + if (component->prec == precision) { + return; + } + if (component->prec < precision) { + shift = precision - component->prec; + } else { + shift = component->prec - precision; + } + len = (OPJ_SIZE_T)component->w * (OPJ_SIZE_T)component->h; + + if (component->sgnd) { + OPJ_INT32* l_data = component->data; + if (component->prec < precision) { + for (i = 0; i < len; ++i) { + l_data[i] <<= shift; + } + } else { + for (i = 0; i < len; ++i) { + l_data[i] >>= shift; + } + } + } else { + OPJ_UINT32* l_data = (OPJ_UINT32*)component->data; + if (component->prec < precision) { + for (i = 0; i < len; ++i) { + l_data[i] <<= shift; + } + } else { + for (i = 0; i < len; ++i) { + l_data[i] >>= shift; + } + } + } + component->prec = precision; +} + + /* -->> -->> -->> -->> TGA IMAGE FORMAT |
