+ int shift;
+ OPJ_SIZE_T i, len;
+
+ if (component->prec == precision) {
+ return;
+ }
+ if (component->prec < precision) {
+ scale_component_up(component, precision);
+ return;
+ }
+ shift = (int)(component->prec - precision);
+ len = (OPJ_SIZE_T)component->w * (OPJ_SIZE_T)component->h;
+ if (component->sgnd) {
+ OPJ_INT32* l_data = component->data;
+ for (i = 0; i < len; ++i) {
+ l_data[i] >>= shift;
+ }
+ } else {
+ OPJ_UINT32* l_data = (OPJ_UINT32*)component->data;
+ for (i = 0; i < len; ++i) {
+ l_data[i] >>= shift;
+ }
+ }
+ component->bpp = precision;
+ component->prec = precision;
+}
+
+
+/* planar / interleaved conversions */
+/* used by PNG/TIFF */
+static void convert_32s_C1P1(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst,
+ OPJ_SIZE_T length)
+{
+ memcpy(pDst[0], pSrc, length * sizeof(OPJ_INT32));
+}
+static void convert_32s_C2P2(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst,
+ OPJ_SIZE_T length)
+{
+ OPJ_SIZE_T i;
+ OPJ_INT32* pDst0 = pDst[0];
+ OPJ_INT32* pDst1 = pDst[1];
+
+ for (i = 0; i < length; i++) {
+ pDst0[i] = pSrc[2 * i + 0];
+ pDst1[i] = pSrc[2 * i + 1];
+ }
+}
+static void convert_32s_C3P3(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst,
+ OPJ_SIZE_T length)
+{
+ OPJ_SIZE_T i;
+ OPJ_INT32* pDst0 = pDst[0];
+ OPJ_INT32* pDst1 = pDst[1];
+ OPJ_INT32* pDst2 = pDst[2];
+
+ for (i = 0; i < length; i++) {
+ pDst0[i] = pSrc[3 * i + 0];
+ pDst1[i] = pSrc[3 * i + 1];
+ pDst2[i] = pSrc[3 * i + 2];
+ }
+}
+static void convert_32s_C4P4(const OPJ_INT32* pSrc, OPJ_INT32* const* pDst,
+ OPJ_SIZE_T length)
+{
+ OPJ_SIZE_T i;
+ OPJ_INT32* pDst0 = pDst[0];
+ OPJ_INT32* pDst1 = pDst[1];
+ OPJ_INT32* pDst2 = pDst[2];
+ OPJ_INT32* pDst3 = pDst[3];
+
+ for (i = 0; i < length; i++) {
+ pDst0[i] = pSrc[4 * i + 0];
+ pDst1[i] = pSrc[4 * i + 1];
+ pDst2[i] = pSrc[4 * i + 2];
+ pDst3[i] = pSrc[4 * i + 3];
+ }
+}
+const convert_32s_CXPX convert_32s_CXPX_LUT[5] = {
+ NULL,
+ convert_32s_C1P1,
+ convert_32s_C2P2,
+ convert_32s_C3P3,
+ convert_32s_C4P4
+};
+
+static void convert_32s_P1C1(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst,
+ OPJ_SIZE_T length, OPJ_INT32 adjust)
+{
+ OPJ_SIZE_T i;
+ const OPJ_INT32* pSrc0 = pSrc[0];
+
+ for (i = 0; i < length; i++) {
+ pDst[i] = pSrc0[i] + adjust;
+ }
+}
+static void convert_32s_P2C2(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst,
+ OPJ_SIZE_T length, OPJ_INT32 adjust)
+{
+ OPJ_SIZE_T i;
+ const OPJ_INT32* pSrc0 = pSrc[0];
+ const OPJ_INT32* pSrc1 = pSrc[1];
+
+ for (i = 0; i < length; i++) {
+ pDst[2 * i + 0] = pSrc0[i] + adjust;
+ pDst[2 * i + 1] = pSrc1[i] + adjust;
+ }
+}
+static void convert_32s_P3C3(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst,
+ OPJ_SIZE_T length, OPJ_INT32 adjust)
+{
+ OPJ_SIZE_T i;
+ const OPJ_INT32* pSrc0 = pSrc[0];
+ const OPJ_INT32* pSrc1 = pSrc[1];
+ const OPJ_INT32* pSrc2 = pSrc[2];
+
+ for (i = 0; i < length; i++) {
+ pDst[3 * i + 0] = pSrc0[i] + adjust;
+ pDst[3 * i + 1] = pSrc1[i] + adjust;
+ pDst[3 * i + 2] = pSrc2[i] + adjust;
+ }
+}
+static void convert_32s_P4C4(OPJ_INT32 const* const* pSrc, OPJ_INT32* pDst,
+ OPJ_SIZE_T length, OPJ_INT32 adjust)
+{
+ OPJ_SIZE_T i;
+ const OPJ_INT32* pSrc0 = pSrc[0];
+ const OPJ_INT32* pSrc1 = pSrc[1];
+ const OPJ_INT32* pSrc2 = pSrc[2];
+ const OPJ_INT32* pSrc3 = pSrc[3];
+
+ for (i = 0; i < length; i++) {
+ pDst[4 * i + 0] = pSrc0[i] + adjust;
+ pDst[4 * i + 1] = pSrc1[i] + adjust;
+ pDst[4 * i + 2] = pSrc2[i] + adjust;
+ pDst[4 * i + 3] = pSrc3[i] + adjust;
+ }
+}
+const convert_32s_PXCX convert_32s_PXCX_LUT[5] = {
+ NULL,
+ convert_32s_P1C1,
+ convert_32s_P2C2,
+ convert_32s_P3C3,
+ convert_32s_P4C4
+};
+
+/* bit depth conversions */
+/* used by PNG/TIFF up to 8bpp */
+static void convert_1u32s_C1R(const OPJ_BYTE* pSrc, OPJ_INT32* pDst,
+ OPJ_SIZE_T length)
+{
+ OPJ_SIZE_T i;
+ for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i += 8U) {
+ OPJ_UINT32 val = *pSrc++;
+ pDst[i + 0] = (OPJ_INT32)(val >> 7);
+ pDst[i + 1] = (OPJ_INT32)((val >> 6) & 0x1U);
+ pDst[i + 2] = (OPJ_INT32)((val >> 5) & 0x1U);
+ pDst[i + 3] = (OPJ_INT32)((val >> 4) & 0x1U);
+ pDst[i + 4] = (OPJ_INT32)((val >> 3) & 0x1U);
+ pDst[i + 5] = (OPJ_INT32)((val >> 2) & 0x1U);
+ pDst[i + 6] = (OPJ_INT32)((val >> 1) & 0x1U);
+ pDst[i + 7] = (OPJ_INT32)(val & 0x1U);
+ }
+ if (length & 7U) {
+ OPJ_UINT32 val = *pSrc++;
+ length = length & 7U;
+ pDst[i + 0] = (OPJ_INT32)(val >> 7);
+
+ if (length > 1U) {
+ pDst[i + 1] = (OPJ_INT32)((val >> 6) & 0x1U);
+ if (length > 2U) {
+ pDst[i + 2] = (OPJ_INT32)((val >> 5) & 0x1U);
+ if (length > 3U) {
+ pDst[i + 3] = (OPJ_INT32)((val >> 4) & 0x1U);
+ if (length > 4U) {
+ pDst[i + 4] = (OPJ_INT32)((val >> 3) & 0x1U);
+ if (length > 5U) {
+ pDst[i + 5] = (OPJ_INT32)((val >> 2) & 0x1U);
+ if (length > 6U) {
+ pDst[i + 6] = (OPJ_INT32)((val >> 1) & 0x1U);
+ }
+ }
+ }
+ }
+ }
+ }
+ }