Intel® Integrated Performance Primitives (Intel® IPP) Developer Guide and Reference

ID 790148
Date 10/31/2024
Public
Document Table of Contents

ScaleC

Scales pixel values of an image and converts them to another bit depth.

Syntax

Case 1: Not-in-place operation

IppStatus ippiScaleC_<mod>_C1R(const Ipp<srcDatatype>* pSrc, int srcStep, Ipp64f mVal, Ipp64f aVal, Ipp<dstDatatype>* pDst, int dstStep, IppiSize roiSize, IppHintAlgorithm hint);

Supported values for mod:

8u 8u8s 8u16u 8u16s 8u32s 8u32f 8u64f
8s8u 8s 8s16u 8s16s 8s32s 8s32f 8s64f
16u8u 16u8s 16u 16u16s 16u32s 16u32f 16u64f
16s8u 16s8s 16s16u 16s 16s32s 16s32f 16s64f
32s8u 32s8s 32s16u 32s16s 32s 32s32f 32s64f
32f8u 32f8s 32f16u 32f16s 32f32s 32f 32f64f
64f8u 64f8s 64f16u 64f16s 64f32s 64f32f 64f

where the first value is srcDatatype and the second value is dstDatatype.

Case 2: In-place operation

IppStatus ippiScaleC_<mod>_C1IR(const Ipp<datatype>* pSrcDst, int srcDstStep, Ipp64f mVal, Ipp64f aVal, IppiSize roiSize, IppHintAlgorithm hint);

Supported values for mod:

8u 8s 16u 16s 32s 32f 64f

Include Files

ippi.h

Domain Dependencies

Headers: ippcore.h, ippvm.h, ipps.h

Libraries: ippcore.lib, ippvm.lib, ipps.lib

Parameters

pSrc

Pointer to the source image ROI.

pSrcDst

Pointer to the source and destination buffer or an array of pointers to separate source and destination color planes for in-place operation.

srcDstStep

Distance, in bytes, between the starting points of consecutive lines in the source and destination image for in-place operation.

srcStep

Distance, in bytes, between the starting points of consecutive lines in the source image.

mVal

Value of the multiplier used for scaling.

aVal

Offset value for scaling.

pDst

Pointer to the destination image ROI.

dstStep

Distance, in bytes, between the starting bytes of consecutive lines in the destination image.

roiSize

Size of the source and destination ROI, in pixels.

hint

Option to select the algorithmic implementation of the function. Supported values are ippAlgHintFast (default) and ippAlgHintAccurate.

Description

This function operates with ROI (see Regions of Interest in Intel IPP).

This function scales pixel values of the source image ROI and converts them to the destination data type according to the following formula:

dst = saturate_to_dstType(src * mVal + aVal)

Return Values

ippStsNoErr

Indicates no error. Any other value indicates an error or a warning.

ippStsNullPtrErr

Indicates an error when any of the specified pointers is NULL.

ippStsSizeErr

Indicates an error when roiSize has a field with a zero or negative value.

ippStsStepErr

Indicates an error when the step value is less than, or equal to zero.

Example

/*******************************************************************************
* Copyright 2015 Intel Corporation.
*
*
* This software and the related documents are Intel copyrighted materials, and your use of them is governed by
* the express license under which they were provided to you ('License'). Unless the License provides otherwise,
* you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related
* documents without Intel's prior written permission.
* This software and the related documents are provided as is, with no express or implied warranties, other than
* those that are expressly stated in the License.
*******************************************************************************/

//    The code example below illustrates how to use the ippiScaleC function.

#include <stdio.h>
#include "ipp.h"


/* Next two defines are created to simplify code reading and understanding */
#define EXIT_MAIN exitLine:                                  /* Label for Exit */
#define check_sts(st) if((st) != ippStsNoErr) goto exitLine; /* Go to Exit if Intel(R) Integrated Performance Primitives (Intel(R) IPP) function returned status different from ippStsNoErr */

/* Results of ippMalloc() are not validated because Intel(R) IPP functions perform bad arguments check and will return an appropriate status  */


int main(void)
{
    IppStatus status = ippStsNoErr;

    Ipp32u seed=0;
    IppiSize roiSize = {8, 8}; /* Image sizes */
    Ipp8u pSrc[8*8]={0};       /* Pointers to source images */
    Ipp16s pDst[8*8];          /* Pointers to destination images */
    Ipp64f mVal, aVal;
    Ipp64f minSrc=IPP_MIN_8U, maxSrc=IPP_MAX_8U;
    Ipp64f minDst=IPP_MIN_16S, maxDst=IPP_MAX_16S;

    /* set random image  */
    check_sts( status = ippiAddRandUniform_8u_C1IR( pSrc, roiSize.width*sizeof(*pSrc), roiSize, IPP_MIN_8U, IPP_MAX_8U, &seed) )

    /* calculate coefficient for scaling */
    mVal = (maxDst-minDst) / (maxSrc-minSrc);
    aVal = minDst - minSrc*mVal;

    /* do scaling */
    check_sts( status = ippiScaleC_8u16s_C1R(pSrc, roiSize.width*sizeof(*pSrc), mVal, aVal, pDst, roiSize.width*sizeof(*pDst), roiSize, ippAlgHintFast) )

EXIT_MAIN
    printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
    return (int)status;
}