[FFmpeg-devel] [PATCH 4/7] Adds gray floating-point pixel formats.

James Almer jamrial at gmail.com
Thu Aug 2 22:32:28 EEST 2018


On 8/2/2018 4:22 PM, Martin Vignali wrote:
>>
>> +static int uint_y_to_float_y_wrapper(SwsContext *c, const uint8_t *src[],
>> +                                     int srcStride[], int srcSliceY,
>> +                                     int srcSliceH, uint8_t *dst[], int
>> dstStride[])
>> +{
>> +    int y, x;
>> +    int dstStrideFloat = dstStride[0] >> 2;;
>> +    const uint8_t *srcPtr = src[0];
>> +    float *dstPtr = (float *)(dst[0] + dstStride[0] * srcSliceY);
>> +
>> +    for (y = 0; y < srcSliceH; ++y){
>> +        for (x = 0; x < c->srcW; ++x){
>> +            dstPtr[x] = (float)srcPtr[x] / 255.0f;
>> +        }
>> +        srcPtr += srcStride[0];
>> +        dstPtr += dstStrideFloat;
>> +    }
>> +
>> +    return srcSliceH;
>> +}
>> +
>> +static int float_y_to_uint_y_wrapper(SwsContext *c, const uint8_t* src[],
>> +                                     int srcStride[], int srcSliceY,
>> +                                     int srcSliceH, uint8_t* dst[], int
>> dstStride[])
>> +{
>> +    int y, x;
>> +    int srcStrideFloat = srcStride[0] >> 2;
>> +    const float *srcPtr = (const float *)src[0];
>> +    uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY;
>> +
>> +    for (y = 0; y < srcSliceH; ++y){
>> +        for (x = 0; x < c->srcW; ++x){
>> +            dstPtr[x] = (uint8_t)(255.0f * FFMIN(FFMAX(srcPtr[x], 0.0f),
>> 1.0f));
>> +        }
>> +        srcPtr += srcStrideFloat;
>> +        dstPtr += dstStride[0];
>> +    }
>> +
>> +    return srcSliceH;
>> +}
>>
> 
> 
> Maybe you can avoid to use float for these conversions
> like in libavcodec/exr.c, where there is a float to uint16 conversion
> 
> Martin

Unless i'm missing something, I think the point is that he was asked to
not do format conversion within the filter itself.


More information about the ffmpeg-devel mailing list