// This function computes the distance from each component to the next one in bytes. static void ComputeIncrementsForChunky(cmsUInt32Number Format, cmsUInt32Number ComponentStartingOrder[], cmsUInt32Number ComponentPointerIncrements[]) { cmsUInt32Number channels[cmsMAXCHANNELS]; int extra = T_EXTRA(Format); int nchannels = T_CHANNELS(Format); int total_chans = nchannels + extra; int i; int channelSize = trueBytesSize(Format); int pixelSize = channelSize * total_chans; // Sanity check if (total_chans <= 0 || total_chans >= cmsMAXCHANNELS) return; memset(channels, 0, sizeof(channels)); // Separation is independent of starting point and only depends on channel size for (i = 0; i < extra; i++) ComponentPointerIncrements[i] = pixelSize; // Handle do swap for (i = 0; i < total_chans; i++) { if (T_DOSWAP(Format)) { channels[i] = total_chans - i - 1; } else { channels[i] = i; } } // Handle swap first (ROL of positions), example CMYK -> KCMY | 0123 -> 3012 if (T_SWAPFIRST(Format) && total_chans > 1) { cmsUInt32Number tmp = channels[0]; for (i = 0; i < total_chans-1; i++) channels[i] = channels[i + 1]; channels[total_chans - 1] = tmp; } // Handle size if (channelSize > 1) for (i = 0; i < total_chans; i++) { channels[i] *= channelSize; } for (i = 0; i < extra; i++) ComponentStartingOrder[i] = channels[i + nchannels]; }
// On planar configurations, the distance is the stride added to any non-negative static void ComputeIncrementsForPlanar(cmsUInt32Number Format, cmsUInt32Number BytesPerPlane, cmsUInt32Number ComponentStartingOrder[], cmsUInt32Number ComponentPointerIncrements[]) { cmsUInt32Number channels[cmsMAXCHANNELS]; int extra = T_EXTRA(Format); int nchannels = T_CHANNELS(Format); int total_chans = nchannels + extra; int i; int channelSize = trueBytesSize(Format); // Separation is independent of starting point and only depends on channel size for (i = 0; i < extra; i++) ComponentPointerIncrements[i] = channelSize; // Handle do swap for (i = 0; i < total_chans; i++) { if (T_DOSWAP(Format)) { channels[i] = total_chans - i - 1; } else { channels[i] = i; } } // Handle swap first (ROL of positions), example CMYK -> KCMY | 0123 -> 3012 if (T_SWAPFIRST(Format)) { cmsUInt32Number tmp = channels[0]; for (i = 0; i < total_chans - 1; i++) channels[i] = channels[i + 1]; channels[total_chans - 1] = tmp; } // Handle size for (i = 0; i < total_chans; i++) { channels[i] *= BytesPerPlane; } for (i = 0; i < extra; i++) ComponentStartingOrder[i] = channels[i + nchannels]; }