| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (C) 2001-2011 Michael Niedermayer <michaelni@gmx.at> | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with FFmpeg; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | #ifndef SWSCALE_SWSCALE_INTERNAL_H | ||
| 22 | #define SWSCALE_SWSCALE_INTERNAL_H | ||
| 23 | |||
| 24 | #include <stdatomic.h> | ||
| 25 | #include <assert.h> | ||
| 26 | |||
| 27 | #include "config.h" | ||
| 28 | #include "swscale.h" | ||
| 29 | #include "graph.h" | ||
| 30 | |||
| 31 | #include "libavfilter/framepool.h" | ||
| 32 | #include "libavutil/avassert.h" | ||
| 33 | #include "libavutil/common.h" | ||
| 34 | #include "libavutil/frame.h" | ||
| 35 | #include "libavutil/intreadwrite.h" | ||
| 36 | #include "libavutil/log.h" | ||
| 37 | #include "libavutil/mem_internal.h" | ||
| 38 | #include "libavutil/pixfmt.h" | ||
| 39 | #include "libavutil/pixdesc.h" | ||
| 40 | #include "libavutil/slicethread.h" | ||
| 41 | #include "libavutil/half2float.h" | ||
| 42 | |||
| 43 | #if HAVE_ALTIVEC | ||
| 44 | #define SWSINTERNAL_ADDITIONAL_ASM_SIZE (7*16 + 2*8 + /* alignment */ 16) | ||
| 45 | #endif | ||
| 46 | #ifndef SWSINTERNAL_ADDITIONAL_ASM_SIZE | ||
| 47 | #define SWSINTERNAL_ADDITIONAL_ASM_SIZE 0 | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long | ||
| 51 | |||
| 52 | #define YUVRGB_TABLE_HEADROOM 512 | ||
| 53 | #define YUVRGB_TABLE_LUMA_HEADROOM 512 | ||
| 54 | |||
| 55 | #define MAX_FILTER_SIZE SWS_MAX_FILTER_SIZE | ||
| 56 | |||
| 57 | #define SWS_MAX_THREADS 8192 /* sanity clamp */ | ||
| 58 | |||
| 59 | #if HAVE_BIGENDIAN | ||
| 60 | #define ALT32_CORR (-1) | ||
| 61 | #else | ||
| 62 | #define ALT32_CORR 1 | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #if ARCH_X86_64 | ||
| 66 | # define APCK_PTR2 8 | ||
| 67 | # define APCK_COEF 16 | ||
| 68 | # define APCK_SIZE 24 | ||
| 69 | #else | ||
| 70 | # define APCK_PTR2 4 | ||
| 71 | # define APCK_COEF 8 | ||
| 72 | # define APCK_SIZE 16 | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #define RETCODE_USE_CASCADE -12345 | ||
| 76 | |||
| 77 | typedef struct SwsInternal SwsInternal; | ||
| 78 | |||
| 79 | 2561632 | static inline SwsInternal *sws_internal(const SwsContext *sws) | |
| 80 | { | ||
| 81 | 2561632 | return (SwsInternal *) sws; | |
| 82 | } | ||
| 83 | |||
| 84 | typedef struct Range { | ||
| 85 | unsigned int start; | ||
| 86 | unsigned int len; | ||
| 87 | } Range; | ||
| 88 | |||
| 89 | typedef struct RangeList { | ||
| 90 | Range *ranges; | ||
| 91 | unsigned int nb_ranges; | ||
| 92 | int ranges_allocated; | ||
| 93 | } RangeList; | ||
| 94 | |||
| 95 | int ff_range_add(RangeList *r, unsigned int start, unsigned int len); | ||
| 96 | |||
| 97 | typedef int (*SwsFunc)(SwsInternal *c, const uint8_t *const src[], | ||
| 98 | const int srcStride[], int srcSliceY, int srcSliceH, | ||
| 99 | uint8_t *const dst[], const int dstStride[]); | ||
| 100 | |||
| 101 | typedef void (*SwsColorFunc)(const SwsInternal *c, uint8_t *dst, int dst_stride, | ||
| 102 | const uint8_t *src, int src_stride, int w, int h); | ||
| 103 | |||
| 104 | typedef struct SwsLuts { | ||
| 105 | uint16_t *in; | ||
| 106 | uint16_t *out; | ||
| 107 | } SwsLuts; | ||
| 108 | |||
| 109 | typedef struct SwsColorXform { | ||
| 110 | SwsLuts gamma; | ||
| 111 | int16_t mat[3][3]; | ||
| 112 | } SwsColorXform; | ||
| 113 | |||
| 114 | /** | ||
| 115 | * Write one line of horizontally scaled data to planar output | ||
| 116 | * without any additional vertical scaling (or point-scaling). | ||
| 117 | * | ||
| 118 | * @param src scaled source data, 15 bits for 8-10-bit output, | ||
| 119 | * 19 bits for 16-bit output (in int32_t) | ||
| 120 | * @param dest pointer to the output plane. For >8-bit | ||
| 121 | * output, this is in uint16_t | ||
| 122 | * @param dstW width of destination in pixels | ||
| 123 | * @param dither ordered dither array of type int16_t and size 8 | ||
| 124 | * @param offset Dither offset | ||
| 125 | */ | ||
| 126 | typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, | ||
| 127 | const uint8_t *dither, int offset); | ||
| 128 | |||
| 129 | /** | ||
| 130 | * Write one line of horizontally scaled data to planar output | ||
| 131 | * with multi-point vertical scaling between input pixels. | ||
| 132 | * | ||
| 133 | * @param filter vertical luma/alpha scaling coefficients, 12 bits [0,4096] | ||
| 134 | * @param src scaled luma (Y) or alpha (A) source data, 15 bits for | ||
| 135 | * 8-10-bit output, 19 bits for 16-bit output (in int32_t) | ||
| 136 | * @param filterSize number of vertical input lines to scale | ||
| 137 | * @param dest pointer to output plane. For >8-bit | ||
| 138 | * output, this is in uint16_t | ||
| 139 | * @param dstW width of destination pixels | ||
| 140 | * @param offset Dither offset | ||
| 141 | */ | ||
| 142 | typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize, | ||
| 143 | const int16_t **src, uint8_t *dest, int dstW, | ||
| 144 | const uint8_t *dither, int offset); | ||
| 145 | |||
| 146 | /** | ||
| 147 | * Write one line of horizontally scaled chroma to interleaved output | ||
| 148 | * with multi-point vertical scaling between input pixels. | ||
| 149 | * | ||
| 150 | * @param dstFormat destination pixel format | ||
| 151 | * @param chrDither ordered dither array of type uint8_t and size 8 | ||
| 152 | * @param chrFilter vertical chroma scaling coefficients, 12 bits [0,4096] | ||
| 153 | * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit | ||
| 154 | * output, 19 bits for 16-bit output (in int32_t) | ||
| 155 | * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit | ||
| 156 | * output, 19 bits for 16-bit output (in int32_t) | ||
| 157 | * @param chrFilterSize number of vertical chroma input lines to scale | ||
| 158 | * @param dest pointer to the output plane. For >8-bit | ||
| 159 | * output, this is in uint16_t | ||
| 160 | * @param dstW width of chroma planes | ||
| 161 | */ | ||
| 162 | typedef void (*yuv2interleavedX_fn)(enum AVPixelFormat dstFormat, | ||
| 163 | const uint8_t *chrDither, | ||
| 164 | const int16_t *chrFilter, | ||
| 165 | int chrFilterSize, | ||
| 166 | const int16_t **chrUSrc, | ||
| 167 | const int16_t **chrVSrc, | ||
| 168 | uint8_t *dest, int dstW); | ||
| 169 | |||
| 170 | /** | ||
| 171 | * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB | ||
| 172 | * output without any additional vertical scaling (or point-scaling). Note | ||
| 173 | * that this function may do chroma scaling, see the "uvalpha" argument. | ||
| 174 | * | ||
| 175 | * @param c SWS scaling context | ||
| 176 | * @param lumSrc scaled luma (Y) source data, 15 bits for 8-10-bit output, | ||
| 177 | * 19 bits for 16-bit output (in int32_t) | ||
| 178 | * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output, | ||
| 179 | * 19 bits for 16-bit output (in int32_t) | ||
| 180 | * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output, | ||
| 181 | * 19 bits for 16-bit output (in int32_t) | ||
| 182 | * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output, | ||
| 183 | * 19 bits for 16-bit output (in int32_t) | ||
| 184 | * @param dest pointer to the output plane. For 16-bit output, this is | ||
| 185 | * uint16_t | ||
| 186 | * @param dstW width of lumSrc and alpSrc in pixels, number of pixels | ||
| 187 | * to write into dest[] | ||
| 188 | * @param uvalpha chroma scaling coefficient for the second line of chroma | ||
| 189 | * pixels, either 2048 or 0. If 0, one chroma input is used | ||
| 190 | * for 2 output pixels (or if the SWS_FULL_CHR_H_INT flag | ||
| 191 | * is set, it generates 1 output pixel). If 2048, two chroma | ||
| 192 | * input pixels should be averaged for 2 output pixels (this | ||
| 193 | * only happens if SWS_FULL_CHR_H_INT is not set) | ||
| 194 | * @param y vertical line number for this output. This does not need | ||
| 195 | * to be used to calculate the offset in the destination, | ||
| 196 | * but can be used to generate comfort noise using dithering | ||
| 197 | * for some output formats. | ||
| 198 | */ | ||
| 199 | typedef void (*yuv2packed1_fn)(SwsInternal *c, const int16_t *lumSrc, | ||
| 200 | const int16_t *chrUSrc[2], | ||
| 201 | const int16_t *chrVSrc[2], | ||
| 202 | const int16_t *alpSrc, uint8_t *dest, | ||
| 203 | int dstW, int uvalpha, int y); | ||
| 204 | /** | ||
| 205 | * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB | ||
| 206 | * output by doing bilinear scaling between two input lines. | ||
| 207 | * | ||
| 208 | * @param c SWS scaling context | ||
| 209 | * @param lumSrc scaled luma (Y) source data, 15 bits for 8-10-bit output, | ||
| 210 | * 19 bits for 16-bit output (in int32_t) | ||
| 211 | * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output, | ||
| 212 | * 19 bits for 16-bit output (in int32_t) | ||
| 213 | * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output, | ||
| 214 | * 19 bits for 16-bit output (in int32_t) | ||
| 215 | * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output, | ||
| 216 | * 19 bits for 16-bit output (in int32_t) | ||
| 217 | * @param dest pointer to the output plane. For 16-bit output, this is | ||
| 218 | * uint16_t | ||
| 219 | * @param dstW width of lumSrc and alpSrc in pixels, number of pixels | ||
| 220 | * to write into dest[] | ||
| 221 | * @param yalpha luma/alpha scaling coefficients for the second input line. | ||
| 222 | * The first line's coefficients can be calculated by using | ||
| 223 | * 4096 - yalpha | ||
| 224 | * @param uvalpha chroma scaling coefficient for the second input line. The | ||
| 225 | * first line's coefficients can be calculated by using | ||
| 226 | * 4096 - uvalpha | ||
| 227 | * @param y vertical line number for this output. This does not need | ||
| 228 | * to be used to calculate the offset in the destination, | ||
| 229 | * but can be used to generate comfort noise using dithering | ||
| 230 | * for some output formats. | ||
| 231 | */ | ||
| 232 | typedef void (*yuv2packed2_fn)(SwsInternal *c, const int16_t *lumSrc[2], | ||
| 233 | const int16_t *chrUSrc[2], | ||
| 234 | const int16_t *chrVSrc[2], | ||
| 235 | const int16_t *alpSrc[2], | ||
| 236 | uint8_t *dest, | ||
| 237 | int dstW, int yalpha, int uvalpha, int y); | ||
| 238 | /** | ||
| 239 | * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB | ||
| 240 | * output by doing multi-point vertical scaling between input pixels. | ||
| 241 | * | ||
| 242 | * @param c SWS scaling context | ||
| 243 | * @param lumFilter vertical luma/alpha scaling coefficients, 12 bits [0,4096] | ||
| 244 | * @param lumSrc scaled luma (Y) source data, 15 bits for 8-10-bit output, | ||
| 245 | * 19 bits for 16-bit output (in int32_t) | ||
| 246 | * @param lumFilterSize number of vertical luma/alpha input lines to scale | ||
| 247 | * @param chrFilter vertical chroma scaling coefficients, 12 bits [0,4096] | ||
| 248 | * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output, | ||
| 249 | * 19 bits for 16-bit output (in int32_t) | ||
| 250 | * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output, | ||
| 251 | * 19 bits for 16-bit output (in int32_t) | ||
| 252 | * @param chrFilterSize number of vertical chroma input lines to scale | ||
| 253 | * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output, | ||
| 254 | * 19 bits for 16-bit output (in int32_t) | ||
| 255 | * @param dest pointer to the output plane. For 16-bit output, this is | ||
| 256 | * uint16_t | ||
| 257 | * @param dstW width of lumSrc and alpSrc in pixels, number of pixels | ||
| 258 | * to write into dest[] | ||
| 259 | * @param y vertical line number for this output. This does not need | ||
| 260 | * to be used to calculate the offset in the destination, | ||
| 261 | * but can be used to generate comfort noise using dithering | ||
| 262 | * or some output formats. | ||
| 263 | */ | ||
| 264 | typedef void (*yuv2packedX_fn)(SwsInternal *c, const int16_t *lumFilter, | ||
| 265 | const int16_t **lumSrc, int lumFilterSize, | ||
| 266 | const int16_t *chrFilter, | ||
| 267 | const int16_t **chrUSrc, | ||
| 268 | const int16_t **chrVSrc, int chrFilterSize, | ||
| 269 | const int16_t **alpSrc, uint8_t *dest, | ||
| 270 | int dstW, int y); | ||
| 271 | |||
| 272 | /** | ||
| 273 | * Write one line of horizontally scaled Y/U/V/A to YUV/RGB | ||
| 274 | * output by doing multi-point vertical scaling between input pixels. | ||
| 275 | * | ||
| 276 | * @param c SWS scaling context | ||
| 277 | * @param lumFilter vertical luma/alpha scaling coefficients, 12 bits [0,4096] | ||
| 278 | * @param lumSrc scaled luma (Y) source data, 15 bits for 8-10-bit output, | ||
| 279 | * 19 bits for 16-bit output (in int32_t) | ||
| 280 | * @param lumFilterSize number of vertical luma/alpha input lines to scale | ||
| 281 | * @param chrFilter vertical chroma scaling coefficients, 12 bits [0,4096] | ||
| 282 | * @param chrUSrc scaled chroma (U) source data, 15 bits for 8-10-bit output, | ||
| 283 | * 19 bits for 16-bit output (in int32_t) | ||
| 284 | * @param chrVSrc scaled chroma (V) source data, 15 bits for 8-10-bit output, | ||
| 285 | * 19 bits for 16-bit output (in int32_t) | ||
| 286 | * @param chrFilterSize number of vertical chroma input lines to scale | ||
| 287 | * @param alpSrc scaled alpha (A) source data, 15 bits for 8-10-bit output, | ||
| 288 | * 19 bits for 16-bit output (in int32_t) | ||
| 289 | * @param dest pointer to the output planes. For 16-bit output, this is | ||
| 290 | * uint16_t | ||
| 291 | * @param dstW width of lumSrc and alpSrc in pixels, number of pixels | ||
| 292 | * to write into dest[] | ||
| 293 | * @param y vertical line number for this output. This does not need | ||
| 294 | * to be used to calculate the offset in the destination, | ||
| 295 | * but can be used to generate comfort noise using dithering | ||
| 296 | * or some output formats. | ||
| 297 | */ | ||
| 298 | typedef void (*yuv2anyX_fn)(SwsInternal *c, const int16_t *lumFilter, | ||
| 299 | const int16_t **lumSrc, int lumFilterSize, | ||
| 300 | const int16_t *chrFilter, | ||
| 301 | const int16_t **chrUSrc, | ||
| 302 | const int16_t **chrVSrc, int chrFilterSize, | ||
| 303 | const int16_t **alpSrc, uint8_t **dest, | ||
| 304 | int dstW, int y); | ||
| 305 | |||
| 306 | /** | ||
| 307 | * Unscaled conversion of luma/alpha plane to YV12 for horizontal scaler. | ||
| 308 | */ | ||
| 309 | typedef void (*planar1_YV12_fn)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, | ||
| 310 | const uint8_t *src3, int width, uint32_t *pal, | ||
| 311 | void *opaque); | ||
| 312 | |||
| 313 | /** | ||
| 314 | * Unscaled conversion of chroma plane to YV12 for horizontal scaler. | ||
| 315 | */ | ||
| 316 | typedef void (*planar2_YV12_fn)(uint8_t *dst, uint8_t *dst2, const uint8_t *src, | ||
| 317 | const uint8_t *src2, const uint8_t *src3, | ||
| 318 | int width, uint32_t *pal, void *opaque); | ||
| 319 | |||
| 320 | /** | ||
| 321 | * Unscaled conversion of arbitrary planar data (e.g. RGBA) to YV12, through | ||
| 322 | * conversion using the given color matrix. | ||
| 323 | */ | ||
| 324 | typedef void (*planarX_YV12_fn)(uint8_t *dst, const uint8_t *src[4], int width, | ||
| 325 | int32_t *rgb2yuv, void *opaque); | ||
| 326 | |||
| 327 | typedef void (*planarX2_YV12_fn)(uint8_t *dst, uint8_t *dst2, | ||
| 328 | const uint8_t *src[4], int width, | ||
| 329 | int32_t *rgb2yuv, void *opaque); | ||
| 330 | |||
| 331 | struct SwsSlice; | ||
| 332 | struct SwsFilterDescriptor; | ||
| 333 | |||
| 334 | /* This struct should be aligned on at least a 32-byte boundary. */ | ||
| 335 | struct SwsInternal { | ||
| 336 | /* Currently active user-facing options. Also contains AVClass */ | ||
| 337 | SwsContext opts; | ||
| 338 | |||
| 339 | /* Parent context (for slice contexts) */ | ||
| 340 | SwsContext *parent; | ||
| 341 | |||
| 342 | AVSliceThread *slicethread; | ||
| 343 | SwsContext **slice_ctx; | ||
| 344 | int *slice_err; | ||
| 345 | int nb_slice_ctx; | ||
| 346 | |||
| 347 | /* Scaling graph, reinitialized dynamically as needed. */ | ||
| 348 | SwsGraph *graph[2]; /* top, bottom fields */ | ||
| 349 | |||
| 350 | // values passed to current sws_receive_slice() call | ||
| 351 | int dst_slice_start; | ||
| 352 | int dst_slice_height; | ||
| 353 | |||
| 354 | /** | ||
| 355 | * Note that src, dst, srcStride, dstStride will be copied in the | ||
| 356 | * sws_scale() wrapper so they can be freely modified here. | ||
| 357 | */ | ||
| 358 | SwsFunc convert_unscaled; | ||
| 359 | int chrSrcW; ///< Width of source chroma planes. | ||
| 360 | int chrSrcH; ///< Height of source chroma planes. | ||
| 361 | int chrDstW; ///< Width of destination chroma planes. | ||
| 362 | int chrDstH; ///< Height of destination chroma planes. | ||
| 363 | int lumXInc, chrXInc; | ||
| 364 | int lumYInc, chrYInc; | ||
| 365 | int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format. | ||
| 366 | int srcFormatBpp; ///< Number of bits per pixel of the source pixel format. | ||
| 367 | int dstBpc, srcBpc; | ||
| 368 | int chrSrcHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source image. | ||
| 369 | int chrSrcVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image. | ||
| 370 | int chrDstHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image. | ||
| 371 | int chrDstVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in destination image. | ||
| 372 | int vChrDrop; ///< Binary logarithm of extra vertical subsampling factor in source image chroma planes specified by user. | ||
| 373 | int sliceDir; ///< Direction that slices are fed to the scaler (1 = top-to-bottom, -1 = bottom-to-top). | ||
| 374 | |||
| 375 | AVFrame *frame_src; | ||
| 376 | AVFrame *frame_dst; | ||
| 377 | |||
| 378 | RangeList src_ranges; | ||
| 379 | |||
| 380 | /* The cascaded_* fields allow splitting a scaler task into multiple | ||
| 381 | * sequential steps, this is for example used to limit the maximum | ||
| 382 | * downscaling factor that needs to be supported in one scaler. | ||
| 383 | */ | ||
| 384 | SwsContext *cascaded_context[3]; | ||
| 385 | int cascaded_tmpStride[2][4]; | ||
| 386 | uint8_t *cascaded_tmp[2][4]; | ||
| 387 | int cascaded_mainindex; | ||
| 388 | |||
| 389 | double gamma_value; | ||
| 390 | int is_internal_gamma; | ||
| 391 | uint16_t *gamma; | ||
| 392 | uint16_t *inv_gamma; | ||
| 393 | |||
| 394 | int numDesc; | ||
| 395 | int descIndex[2]; | ||
| 396 | int numSlice; | ||
| 397 | struct SwsSlice *slice; | ||
| 398 | struct SwsFilterDescriptor *desc; | ||
| 399 | |||
| 400 | uint32_t pal_yuv[256]; | ||
| 401 | uint32_t pal_rgb[256]; | ||
| 402 | |||
| 403 | float uint2float_lut[256]; | ||
| 404 | |||
| 405 | /** | ||
| 406 | * @name Scaled horizontal lines ring buffer. | ||
| 407 | * The horizontal scaler keeps just enough scaled lines in a ring buffer | ||
| 408 | * so they may be passed to the vertical scaler. The pointers to the | ||
| 409 | * allocated buffers for each line are duplicated in sequence in the ring | ||
| 410 | * buffer to simplify indexing and avoid wrapping around between lines | ||
| 411 | * inside the vertical scaler code. The wrapping is done before the | ||
| 412 | * vertical scaler is called. | ||
| 413 | */ | ||
| 414 | //@{ | ||
| 415 | int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer. | ||
| 416 | int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer. | ||
| 417 | //@} | ||
| 418 | |||
| 419 | uint8_t *formatConvBuffer; | ||
| 420 | int needAlpha; | ||
| 421 | |||
| 422 | /** | ||
| 423 | * @name Horizontal and vertical filters. | ||
| 424 | * To better understand the following fields, here is a pseudo-code of | ||
| 425 | * their usage in filtering a horizontal line: | ||
| 426 | * @code | ||
| 427 | * for (i = 0; i < width; i++) { | ||
| 428 | * dst[i] = 0; | ||
| 429 | * for (j = 0; j < filterSize; j++) | ||
| 430 | * dst[i] += src[ filterPos[i] + j ] * filter[ filterSize * i + j ]; | ||
| 431 | * dst[i] >>= FRAC_BITS; // The actual implementation is fixed-point. | ||
| 432 | * } | ||
| 433 | * @endcode | ||
| 434 | */ | ||
| 435 | //@{ | ||
| 436 | int16_t *hLumFilter; ///< Array of horizontal filter coefficients for luma/alpha planes. | ||
| 437 | int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes. | ||
| 438 | int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes. | ||
| 439 | int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes. | ||
| 440 | int32_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes. | ||
| 441 | int32_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes. | ||
| 442 | int32_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes. | ||
| 443 | int32_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes. | ||
| 444 | int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels. | ||
| 445 | int hChrFilterSize; ///< Horizontal filter size for chroma pixels. | ||
| 446 | int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels. | ||
| 447 | int vChrFilterSize; ///< Vertical filter size for chroma pixels. | ||
| 448 | //@} | ||
| 449 | |||
| 450 | int lumMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for luma/alpha planes. | ||
| 451 | int chrMmxextFilterCodeSize; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code size for chroma planes. | ||
| 452 | uint8_t *lumMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for luma/alpha planes. | ||
| 453 | uint8_t *chrMmxextFilterCode; ///< Runtime-generated MMXEXT horizontal fast bilinear scaler code for chroma planes. | ||
| 454 | |||
| 455 | int canMMXEXTBeUsed; | ||
| 456 | int warned_unuseable_bilinear; | ||
| 457 | |||
| 458 | int dstY; ///< Last destination vertical line output from last slice. | ||
| 459 | void *yuvTable; // pointer to the yuv->rgb table start so it can be freed() | ||
| 460 | // alignment ensures the offset can be added in a single | ||
| 461 | // instruction on e.g. ARM | ||
| 462 | DECLARE_ALIGNED(16, int, table_gV)[256 + 2*YUVRGB_TABLE_HEADROOM]; | ||
| 463 | uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM]; | ||
| 464 | uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM]; | ||
| 465 | uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM]; | ||
| 466 | DECLARE_ALIGNED(16, int32_t, input_rgb2yuv_table)[16+40*4]; // This table can contain both C and SIMD formatted values, the C vales are always at the XY_IDX points | ||
| 467 | #define RY_IDX 0 | ||
| 468 | #define GY_IDX 1 | ||
| 469 | #define BY_IDX 2 | ||
| 470 | #define RU_IDX 3 | ||
| 471 | #define GU_IDX 4 | ||
| 472 | #define BU_IDX 5 | ||
| 473 | #define RV_IDX 6 | ||
| 474 | #define GV_IDX 7 | ||
| 475 | #define BV_IDX 8 | ||
| 476 | #define RGB2YUV_SHIFT 15 | ||
| 477 | |||
| 478 | int *dither_error[4]; | ||
| 479 | |||
| 480 | //Colorspace stuff | ||
| 481 | int contrast, brightness, saturation; // for sws_getColorspaceDetails | ||
| 482 | int srcColorspaceTable[4]; | ||
| 483 | int dstColorspaceTable[4]; | ||
| 484 | int src0Alpha; | ||
| 485 | int dst0Alpha; | ||
| 486 | int srcXYZ; | ||
| 487 | int dstXYZ; | ||
| 488 | int yuv2rgb_y_offset; | ||
| 489 | int yuv2rgb_y_coeff; | ||
| 490 | int yuv2rgb_v2r_coeff; | ||
| 491 | int yuv2rgb_v2g_coeff; | ||
| 492 | int yuv2rgb_u2g_coeff; | ||
| 493 | int yuv2rgb_u2b_coeff; | ||
| 494 | |||
| 495 | #define RED_DITHER "0*8" | ||
| 496 | #define GREEN_DITHER "1*8" | ||
| 497 | #define BLUE_DITHER "2*8" | ||
| 498 | #define Y_COEFF "3*8" | ||
| 499 | #define VR_COEFF "4*8" | ||
| 500 | #define UB_COEFF "5*8" | ||
| 501 | #define VG_COEFF "6*8" | ||
| 502 | #define UG_COEFF "7*8" | ||
| 503 | #define Y_OFFSET "8*8" | ||
| 504 | #define U_OFFSET "9*8" | ||
| 505 | #define V_OFFSET "10*8" | ||
| 506 | #define LUM_MMX_FILTER_OFFSET "11*8" | ||
| 507 | #define CHR_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE) | ||
| 508 | #define DSTW_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2" | ||
| 509 | #define ESP_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+8" | ||
| 510 | #define VROUNDER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+16" | ||
| 511 | #define U_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+24" | ||
| 512 | #define V_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+32" | ||
| 513 | #define Y_TEMP "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+40" | ||
| 514 | #define ALP_MMX_FILTER_OFFSET "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*2+48" | ||
| 515 | #define UV_OFF_PX "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+48" | ||
| 516 | #define UV_OFF_BYTE "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+56" | ||
| 517 | #define DITHER16 "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+64" | ||
| 518 | #define DITHER32 "11*8+4*4*"AV_STRINGIFY(MAX_FILTER_SIZE)"*3+80" | ||
| 519 | #define DITHER32_INT (11*8+4*4*MAX_FILTER_SIZE*3+80) // value equal to above, used for checking that the struct hasn't been changed by mistake | ||
| 520 | |||
| 521 | DECLARE_ALIGNED(8, uint64_t, redDither); | ||
| 522 | DECLARE_ALIGNED(8, uint64_t, greenDither); | ||
| 523 | DECLARE_ALIGNED(8, uint64_t, blueDither); | ||
| 524 | |||
| 525 | DECLARE_ALIGNED(8, uint64_t, yCoeff); | ||
| 526 | DECLARE_ALIGNED(8, uint64_t, vrCoeff); | ||
| 527 | DECLARE_ALIGNED(8, uint64_t, ubCoeff); | ||
| 528 | DECLARE_ALIGNED(8, uint64_t, vgCoeff); | ||
| 529 | DECLARE_ALIGNED(8, uint64_t, ugCoeff); | ||
| 530 | DECLARE_ALIGNED(8, uint64_t, yOffset); | ||
| 531 | DECLARE_ALIGNED(8, uint64_t, uOffset); | ||
| 532 | DECLARE_ALIGNED(8, uint64_t, vOffset); | ||
| 533 | int32_t lumMmxFilter[4 * MAX_FILTER_SIZE]; | ||
| 534 | int32_t chrMmxFilter[4 * MAX_FILTER_SIZE]; | ||
| 535 | int dstW_mmx; | ||
| 536 | DECLARE_ALIGNED(8, uint64_t, esp); | ||
| 537 | DECLARE_ALIGNED(8, uint64_t, vRounder); | ||
| 538 | DECLARE_ALIGNED(8, uint64_t, u_temp); | ||
| 539 | DECLARE_ALIGNED(8, uint64_t, v_temp); | ||
| 540 | DECLARE_ALIGNED(8, uint64_t, y_temp); | ||
| 541 | int32_t alpMmxFilter[4 * MAX_FILTER_SIZE]; | ||
| 542 | // alignment of these values is not necessary, but merely here | ||
| 543 | // to maintain the same offset across x8632 and x86-64. Once we | ||
| 544 | // use proper offset macros in the asm, they can be removed. | ||
| 545 | DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes | ||
| 546 | DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes | ||
| 547 | DECLARE_ALIGNED(8, uint16_t, dither16)[8]; | ||
| 548 | DECLARE_ALIGNED(8, uint32_t, dither32)[8]; | ||
| 549 | |||
| 550 | const uint8_t *chrDither8, *lumDither8; | ||
| 551 | |||
| 552 | int use_mmx_vfilter; | ||
| 553 | |||
| 554 | /* pre defined color-spaces gamma */ | ||
| 555 | #define XYZ_GAMMA (2.6) | ||
| 556 | #define RGB_GAMMA (2.2) | ||
| 557 | SwsColorFunc xyz12Torgb48; | ||
| 558 | SwsColorFunc rgb48Toxyz12; | ||
| 559 | SwsColorXform xyz2rgb; | ||
| 560 | SwsColorXform rgb2xyz; | ||
| 561 | |||
| 562 | /* function pointers for swscale() */ | ||
| 563 | yuv2planar1_fn yuv2plane1; | ||
| 564 | yuv2planarX_fn yuv2planeX; | ||
| 565 | yuv2interleavedX_fn yuv2nv12cX; | ||
| 566 | yuv2packed1_fn yuv2packed1; | ||
| 567 | yuv2packed2_fn yuv2packed2; | ||
| 568 | yuv2packedX_fn yuv2packedX; | ||
| 569 | yuv2anyX_fn yuv2anyX; | ||
| 570 | |||
| 571 | /// Opaque data pointer passed to all input functions. | ||
| 572 | void *input_opaque; | ||
| 573 | |||
| 574 | planar1_YV12_fn lumToYV12; | ||
| 575 | planar1_YV12_fn alpToYV12; | ||
| 576 | planar2_YV12_fn chrToYV12; | ||
| 577 | |||
| 578 | /** | ||
| 579 | * Functions to read planar input, such as planar RGB, and convert | ||
| 580 | * internally to Y/UV/A. | ||
| 581 | */ | ||
| 582 | /** @{ */ | ||
| 583 | planarX_YV12_fn readLumPlanar; | ||
| 584 | planarX_YV12_fn readAlpPlanar; | ||
| 585 | planarX2_YV12_fn readChrPlanar; | ||
| 586 | /** @} */ | ||
| 587 | |||
| 588 | /** | ||
| 589 | * Scale one horizontal line of input data using a bilinear filter | ||
| 590 | * to produce one line of output data. Compared to SwsInternal->hScale(), | ||
| 591 | * please take note of the following caveats when using these: | ||
| 592 | * - Scaling is done using only 7 bits instead of 14-bit coefficients. | ||
| 593 | * - You can use no more than 5 input pixels to produce 4 output | ||
| 594 | * pixels. Therefore, this filter should not be used for downscaling | ||
| 595 | * by more than ~20% in width (because that equals more than 5/4th | ||
| 596 | * downscaling and thus more than 5 pixels input per 4 pixels output). | ||
| 597 | * - In general, bilinear filters create artifacts during downscaling | ||
| 598 | * (even when <20%), because one output pixel will span more than one | ||
| 599 | * input pixel, and thus some pixels will need edges of both neighbor | ||
| 600 | * pixels to interpolate the output pixel. Since you can use at most | ||
| 601 | * two input pixels per output pixel in bilinear scaling, this is | ||
| 602 | * impossible and thus downscaling by any size will create artifacts. | ||
| 603 | * To enable this type of scaling, set SWS_FAST_BILINEAR | ||
| 604 | * in SwsInternal->flags. | ||
| 605 | */ | ||
| 606 | /** @{ */ | ||
| 607 | void (*hyscale_fast)(SwsInternal *c, | ||
| 608 | int16_t *dst, int dstWidth, | ||
| 609 | const uint8_t *src, int srcW, int xInc); | ||
| 610 | void (*hcscale_fast)(SwsInternal *c, | ||
| 611 | int16_t *dst1, int16_t *dst2, int dstWidth, | ||
| 612 | const uint8_t *src1, const uint8_t *src2, | ||
| 613 | int srcW, int xInc); | ||
| 614 | /** @} */ | ||
| 615 | |||
| 616 | /** | ||
| 617 | * Scale one horizontal line of input data using a filter over the input | ||
| 618 | * lines, to produce one (differently sized) line of output data. | ||
| 619 | * | ||
| 620 | * @param dst pointer to destination buffer for horizontally scaled | ||
| 621 | * data. If the number of bits per component of one | ||
| 622 | * destination pixel (SwsInternal->dstBpc) is <= 10, data | ||
| 623 | * will be 15 bpc in 16 bits (int16_t) width. Else (i.e. | ||
| 624 | * SwsInternal->dstBpc == 16), data will be 19bpc in | ||
| 625 | * 32 bits (int32_t) width. | ||
| 626 | * @param dstW width of destination image | ||
| 627 | * @param src pointer to source data to be scaled. If the number of | ||
| 628 | * bits per component of a source pixel (SwsInternal->srcBpc) | ||
| 629 | * is 8, this is 8bpc in 8 bits (uint8_t) width. Else | ||
| 630 | * (i.e. SwsInternal->dstBpc > 8), this is native depth | ||
| 631 | * in 16 bits (uint16_t) width. In other words, for 9-bit | ||
| 632 | * YUV input, this is 9bpc, for 10-bit YUV input, this is | ||
| 633 | * 10bpc, and for 16-bit RGB or YUV, this is 16bpc. | ||
| 634 | * @param filter filter coefficients to be used per output pixel for | ||
| 635 | * scaling. This contains 14bpp filtering coefficients. | ||
| 636 | * Guaranteed to contain dstW * filterSize entries. | ||
| 637 | * @param filterPos position of the first input pixel to be used for | ||
| 638 | * each output pixel during scaling. Guaranteed to | ||
| 639 | * contain dstW entries. | ||
| 640 | * @param filterSize the number of input coefficients to be used (and | ||
| 641 | * thus the number of input pixels to be used) for | ||
| 642 | * creating a single output pixel. Is aligned to 4 | ||
| 643 | * (and input coefficients thus padded with zeroes) | ||
| 644 | * to simplify creating SIMD code. | ||
| 645 | */ | ||
| 646 | /** @{ */ | ||
| 647 | void (*hyScale)(SwsInternal *c, int16_t *dst, int dstW, | ||
| 648 | const uint8_t *src, const int16_t *filter, | ||
| 649 | const int32_t *filterPos, int filterSize); | ||
| 650 | void (*hcScale)(SwsInternal *c, int16_t *dst, int dstW, | ||
| 651 | const uint8_t *src, const int16_t *filter, | ||
| 652 | const int32_t *filterPos, int filterSize); | ||
| 653 | /** @} */ | ||
| 654 | |||
| 655 | /** | ||
| 656 | * Color range conversion functions if needed. | ||
| 657 | * If SwsInternal->dstBpc is > 14: | ||
| 658 | * - int16_t *dst (data is 15 bpc) | ||
| 659 | * - uint16_t coeff | ||
| 660 | * - int32_t offset | ||
| 661 | * Otherwise (SwsInternal->dstBpc is <= 14): | ||
| 662 | * - int32_t *dst (data is 19 bpc) | ||
| 663 | * - uint32_t coeff | ||
| 664 | * - int64_t offset | ||
| 665 | */ | ||
| 666 | /** @{ */ | ||
| 667 | void (*lumConvertRange)(int16_t *dst, int width, | ||
| 668 | uint32_t coeff, int64_t offset); | ||
| 669 | void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width, | ||
| 670 | uint32_t coeff, int64_t offset); | ||
| 671 | /** @} */ | ||
| 672 | |||
| 673 | uint32_t lumConvertRange_coeff; | ||
| 674 | uint32_t chrConvertRange_coeff; | ||
| 675 | int64_t lumConvertRange_offset; | ||
| 676 | int64_t chrConvertRange_offset; | ||
| 677 | |||
| 678 | int needs_hcscale; ///< Set if there are chroma planes to be converted. | ||
| 679 | |||
| 680 | // scratch buffer for converting packed rgb0 sources | ||
| 681 | // filled with a copy of the input frame + fully opaque alpha, | ||
| 682 | // then passed as input to further conversion | ||
| 683 | uint8_t *rgb0_scratch; | ||
| 684 | unsigned int rgb0_scratch_allocated; | ||
| 685 | |||
| 686 | // scratch buffer for converting XYZ sources | ||
| 687 | // filled with the input converted to rgb48 | ||
| 688 | // then passed as input to further conversion | ||
| 689 | uint8_t *xyz_scratch; | ||
| 690 | unsigned int xyz_scratch_allocated; | ||
| 691 | |||
| 692 | unsigned int dst_slice_align; | ||
| 693 | atomic_int stride_unaligned_warned; | ||
| 694 | atomic_int data_unaligned_warned; | ||
| 695 | int color_conversion_warned; | ||
| 696 | |||
| 697 | Half2FloatTables *h2f_tables; | ||
| 698 | |||
| 699 | // Hardware specific private data | ||
| 700 | void *hw_priv; /* refstruct */ | ||
| 701 | |||
| 702 | int is_legacy_init; | ||
| 703 | |||
| 704 | FFFramePool frame_pool; /* for sws_scale_frame() data allocations */ | ||
| 705 | }; | ||
| 706 | //FIXME check init (where 0) | ||
| 707 | |||
| 708 | static_assert(offsetof(SwsInternal, redDither) + DITHER32_INT == offsetof(SwsInternal, dither32), | ||
| 709 | "dither32 must be at the same offset as redDither + DITHER32_INT"); | ||
| 710 | |||
| 711 | #if ARCH_X86_64 | ||
| 712 | /* x86 yuv2gbrp uses the SwsInternal for yuv coefficients | ||
| 713 | if struct offsets change the asm needs to be updated too */ | ||
| 714 | static_assert(offsetof(SwsInternal, yuv2rgb_y_offset) == 40348, | ||
| 715 | "yuv2rgb_y_offset must be updated in x86 asm"); | ||
| 716 | #endif | ||
| 717 | |||
| 718 | SwsFunc ff_yuv2rgb_get_func_ptr(SwsInternal *c); | ||
| 719 | int ff_yuv2rgb_c_init_tables(SwsInternal *c, const int inv_table[4], | ||
| 720 | int fullRange, int brightness, | ||
| 721 | int contrast, int saturation); | ||
| 722 | void ff_yuv2rgb_init_tables_ppc(SwsInternal *c, const int inv_table[4], | ||
| 723 | int brightness, int contrast, int saturation); | ||
| 724 | |||
| 725 | void ff_updateMMXDitherTables(SwsInternal *c, int dstY); | ||
| 726 | |||
| 727 | void ff_update_palette(SwsInternal *c, const uint32_t *pal); | ||
| 728 | |||
| 729 | av_cold void ff_sws_init_range_convert(SwsInternal *c); | ||
| 730 | av_cold void ff_sws_init_range_convert_aarch64(SwsInternal *c); | ||
| 731 | av_cold void ff_sws_init_range_convert_loongarch(SwsInternal *c); | ||
| 732 | av_cold void ff_sws_init_range_convert_riscv(SwsInternal *c); | ||
| 733 | av_cold void ff_sws_init_range_convert_x86(SwsInternal *c); | ||
| 734 | |||
| 735 | av_cold void ff_sws_init_xyzdsp(SwsInternal *c); | ||
| 736 | av_cold void ff_sws_init_xyzdsp_aarch64(SwsInternal *c); | ||
| 737 | |||
| 738 | av_cold int ff_sws_fill_xyztables(SwsInternal *c); | ||
| 739 | |||
| 740 | SwsFunc ff_yuv2rgb_init_x86(SwsInternal *c); | ||
| 741 | SwsFunc ff_yuv2rgb_init_ppc(SwsInternal *c); | ||
| 742 | SwsFunc ff_yuv2rgb_init_loongarch(SwsInternal *c); | ||
| 743 | SwsFunc ff_yuv2rgb_init_aarch64(SwsInternal *c); | ||
| 744 | |||
| 745 | 676940 | static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt) | |
| 746 | { | ||
| 747 | 676940 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 748 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 676940 times.
|
676940 | av_assert0(desc); |
| 749 | 676940 | return desc->comp[0].depth == 16; | |
| 750 | } | ||
| 751 | |||
| 752 | 15547 | static av_always_inline int is32BPS(enum AVPixelFormat pix_fmt) | |
| 753 | { | ||
| 754 | 15547 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 755 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 15547 times.
|
15547 | av_assert0(desc); |
| 756 | 15547 | return desc->comp[0].depth == 32; | |
| 757 | } | ||
| 758 | |||
| 759 | 970166 | static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt) | |
| 760 | { | ||
| 761 | 970166 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 762 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 970166 times.
|
970166 | av_assert0(desc); |
| 763 |
4/4✓ Branch 0 taken 522280 times.
✓ Branch 1 taken 447886 times.
✓ Branch 2 taken 390034 times.
✓ Branch 3 taken 132246 times.
|
970166 | return desc->comp[0].depth >= 9 && desc->comp[0].depth <= 14; |
| 764 | } | ||
| 765 | |||
| 766 | 6725332 | static av_always_inline int isBE(enum AVPixelFormat pix_fmt) | |
| 767 | { | ||
| 768 | 6725332 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 769 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6725332 times.
|
6725332 | av_assert0(desc); |
| 770 | 6725332 | return desc->flags & AV_PIX_FMT_FLAG_BE; | |
| 771 | } | ||
| 772 | |||
| 773 | 4403242 | static av_always_inline int isYUV(enum AVPixelFormat pix_fmt) | |
| 774 | { | ||
| 775 | 4403242 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 776 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4403242 times.
|
4403242 | av_assert0(desc); |
| 777 |
4/4✓ Branch 0 taken 4053394 times.
✓ Branch 1 taken 349848 times.
✓ Branch 2 taken 4034227 times.
✓ Branch 3 taken 19167 times.
|
4403242 | return !(desc->flags & AV_PIX_FMT_FLAG_RGB) && desc->nb_components >= 2; |
| 778 | } | ||
| 779 | |||
| 780 | 3607648 | static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt) | |
| 781 | { | ||
| 782 | 3607648 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 783 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3607648 times.
|
3607648 | av_assert0(desc); |
| 784 |
4/4✓ Branch 0 taken 3159197 times.
✓ Branch 1 taken 448451 times.
✓ Branch 3 taken 2928012 times.
✓ Branch 4 taken 231185 times.
|
3607648 | return ((desc->flags & AV_PIX_FMT_FLAG_PLANAR) && isYUV(pix_fmt)); |
| 785 | } | ||
| 786 | |||
| 787 | /* | ||
| 788 | * Identity semi-planar YUV formats. Specifically, those are YUV formats | ||
| 789 | * where the second and third components (U & V) are on the same plane. | ||
| 790 | */ | ||
| 791 | 1661050 | static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt) | |
| 792 | { | ||
| 793 | 1661050 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 794 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1661050 times.
|
1661050 | av_assert0(desc); |
| 795 |
4/4✓ Branch 1 taken 1399124 times.
✓ Branch 2 taken 261926 times.
✓ Branch 3 taken 940811 times.
✓ Branch 4 taken 458313 times.
|
1661050 | return (isPlanarYUV(pix_fmt) && desc->comp[1].plane == desc->comp[2].plane); |
| 796 | } | ||
| 797 | |||
| 798 | 267 | static av_always_inline int isRGB(enum AVPixelFormat pix_fmt) | |
| 799 | { | ||
| 800 | 267 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 801 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 267 times.
|
267 | av_assert0(desc); |
| 802 | 267 | return (desc->flags & AV_PIX_FMT_FLAG_RGB); | |
| 803 | } | ||
| 804 | |||
| 805 | 1363062 | static av_always_inline int isGray(enum AVPixelFormat pix_fmt) | |
| 806 | { | ||
| 807 | 1363062 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 808 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1363062 times.
|
1363062 | av_assert0(desc); |
| 809 | 2724208 | return !(desc->flags & AV_PIX_FMT_FLAG_PAL) && | |
| 810 |
2/2✓ Branch 0 taken 1361130 times.
✓ Branch 1 taken 16 times.
|
1361146 | !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) && |
| 811 |
4/4✓ Branch 0 taken 105983 times.
✓ Branch 1 taken 1255147 times.
✓ Branch 2 taken 99694 times.
✓ Branch 3 taken 6289 times.
|
1361130 | desc->nb_components <= 2 && |
| 812 |
4/4✓ Branch 0 taken 1361146 times.
✓ Branch 1 taken 1916 times.
✓ Branch 2 taken 91969 times.
✓ Branch 3 taken 7725 times.
|
2724208 | pix_fmt != AV_PIX_FMT_MONOBLACK && |
| 813 | pix_fmt != AV_PIX_FMT_MONOWHITE; | ||
| 814 | } | ||
| 815 | |||
| 816 | 42896 | static av_always_inline int isRGBinInt(enum AVPixelFormat pix_fmt) | |
| 817 | { | ||
| 818 |
2/2✓ Branch 0 taken 42132 times.
✓ Branch 1 taken 622 times.
|
42754 | return pix_fmt == AV_PIX_FMT_RGB48BE || |
| 819 |
2/2✓ Branch 0 taken 37274 times.
✓ Branch 1 taken 4858 times.
|
42132 | pix_fmt == AV_PIX_FMT_RGB48LE || |
| 820 |
2/2✓ Branch 0 taken 37261 times.
✓ Branch 1 taken 13 times.
|
37274 | pix_fmt == AV_PIX_FMT_RGB32 || |
| 821 |
2/2✓ Branch 0 taken 18234 times.
✓ Branch 1 taken 19027 times.
|
37261 | pix_fmt == AV_PIX_FMT_RGB32_1 || |
| 822 |
2/2✓ Branch 0 taken 18229 times.
✓ Branch 1 taken 5 times.
|
18234 | pix_fmt == AV_PIX_FMT_RGB24 || |
| 823 |
2/2✓ Branch 0 taken 16150 times.
✓ Branch 1 taken 2079 times.
|
18229 | pix_fmt == AV_PIX_FMT_RGB565BE || |
| 824 |
2/2✓ Branch 0 taken 16145 times.
✓ Branch 1 taken 5 times.
|
16150 | pix_fmt == AV_PIX_FMT_RGB565LE || |
| 825 |
2/2✓ Branch 0 taken 7147 times.
✓ Branch 1 taken 8998 times.
|
16145 | pix_fmt == AV_PIX_FMT_RGB555BE || |
| 826 |
2/2✓ Branch 0 taken 7142 times.
✓ Branch 1 taken 5 times.
|
7147 | pix_fmt == AV_PIX_FMT_RGB555LE || |
| 827 |
2/2✓ Branch 0 taken 7137 times.
✓ Branch 1 taken 5 times.
|
7142 | pix_fmt == AV_PIX_FMT_RGB444BE || |
| 828 |
2/2✓ Branch 0 taken 7130 times.
✓ Branch 1 taken 7 times.
|
7137 | pix_fmt == AV_PIX_FMT_RGB444LE || |
| 829 |
2/2✓ Branch 0 taken 7129 times.
✓ Branch 1 taken 1 times.
|
7130 | pix_fmt == AV_PIX_FMT_RGB8 || |
| 830 |
2/2✓ Branch 0 taken 7123 times.
✓ Branch 1 taken 6 times.
|
7129 | pix_fmt == AV_PIX_FMT_RGB4 || |
| 831 |
2/2✓ Branch 0 taken 7110 times.
✓ Branch 1 taken 13 times.
|
7123 | pix_fmt == AV_PIX_FMT_RGB4_BYTE || |
| 832 |
2/2✓ Branch 0 taken 7107 times.
✓ Branch 1 taken 3 times.
|
7110 | pix_fmt == AV_PIX_FMT_RGBA64BE || |
| 833 |
2/2✓ Branch 0 taken 7002 times.
✓ Branch 1 taken 105 times.
|
7107 | pix_fmt == AV_PIX_FMT_RGBA64LE || |
| 834 |
4/4✓ Branch 0 taken 42754 times.
✓ Branch 1 taken 142 times.
✓ Branch 2 taken 105 times.
✓ Branch 3 taken 6897 times.
|
85650 | pix_fmt == AV_PIX_FMT_MONOBLACK || |
| 835 | pix_fmt == AV_PIX_FMT_MONOWHITE; | ||
| 836 | } | ||
| 837 | |||
| 838 | 29335 | static av_always_inline int isBGRinInt(enum AVPixelFormat pix_fmt) | |
| 839 | { | ||
| 840 |
2/2✓ Branch 0 taken 29331 times.
✓ Branch 1 taken 3 times.
|
29334 | return pix_fmt == AV_PIX_FMT_BGR48BE || |
| 841 |
2/2✓ Branch 0 taken 28996 times.
✓ Branch 1 taken 335 times.
|
29331 | pix_fmt == AV_PIX_FMT_BGR48LE || |
| 842 |
2/2✓ Branch 0 taken 28922 times.
✓ Branch 1 taken 74 times.
|
28996 | pix_fmt == AV_PIX_FMT_BGR32 || |
| 843 |
2/2✓ Branch 0 taken 27377 times.
✓ Branch 1 taken 1545 times.
|
28922 | pix_fmt == AV_PIX_FMT_BGR32_1 || |
| 844 |
2/2✓ Branch 0 taken 27370 times.
✓ Branch 1 taken 7 times.
|
27377 | pix_fmt == AV_PIX_FMT_BGR24 || |
| 845 |
2/2✓ Branch 0 taken 27363 times.
✓ Branch 1 taken 7 times.
|
27370 | pix_fmt == AV_PIX_FMT_BGR565BE || |
| 846 |
2/2✓ Branch 0 taken 27356 times.
✓ Branch 1 taken 7 times.
|
27363 | pix_fmt == AV_PIX_FMT_BGR565LE || |
| 847 |
2/2✓ Branch 0 taken 24159 times.
✓ Branch 1 taken 3197 times.
|
27356 | pix_fmt == AV_PIX_FMT_BGR555BE || |
| 848 |
2/2✓ Branch 0 taken 24152 times.
✓ Branch 1 taken 7 times.
|
24159 | pix_fmt == AV_PIX_FMT_BGR555LE || |
| 849 |
2/2✓ Branch 0 taken 24145 times.
✓ Branch 1 taken 7 times.
|
24152 | pix_fmt == AV_PIX_FMT_BGR444BE || |
| 850 |
2/2✓ Branch 0 taken 24136 times.
✓ Branch 1 taken 9 times.
|
24145 | pix_fmt == AV_PIX_FMT_BGR444LE || |
| 851 |
2/2✓ Branch 0 taken 24135 times.
✓ Branch 1 taken 1 times.
|
24136 | pix_fmt == AV_PIX_FMT_BGR8 || |
| 852 |
2/2✓ Branch 0 taken 24127 times.
✓ Branch 1 taken 8 times.
|
24135 | pix_fmt == AV_PIX_FMT_BGR4 || |
| 853 |
2/2✓ Branch 0 taken 24126 times.
✓ Branch 1 taken 1 times.
|
24127 | pix_fmt == AV_PIX_FMT_BGR4_BYTE || |
| 854 |
2/2✓ Branch 0 taken 24123 times.
✓ Branch 1 taken 3 times.
|
24126 | pix_fmt == AV_PIX_FMT_BGRA64BE || |
| 855 |
2/2✓ Branch 0 taken 24040 times.
✓ Branch 1 taken 83 times.
|
24123 | pix_fmt == AV_PIX_FMT_BGRA64LE || |
| 856 |
4/4✓ Branch 0 taken 29334 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 83 times.
✓ Branch 3 taken 23957 times.
|
58669 | pix_fmt == AV_PIX_FMT_MONOBLACK || |
| 857 | pix_fmt == AV_PIX_FMT_MONOWHITE; | ||
| 858 | } | ||
| 859 | |||
| 860 | 105138 | static av_always_inline int isBayer(enum AVPixelFormat pix_fmt) | |
| 861 | { | ||
| 862 | 105138 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 863 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 105138 times.
|
105138 | av_assert0(desc); |
| 864 | 105138 | return !!(desc->flags & AV_PIX_FMT_FLAG_BAYER); | |
| 865 | } | ||
| 866 | |||
| 867 | ✗ | static av_always_inline int isBayer16BPS(enum AVPixelFormat pix_fmt) | |
| 868 | { | ||
| 869 | ✗ | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 870 | ✗ | av_assert0(desc); | |
| 871 | ✗ | return desc->comp[1].depth == 8; | |
| 872 | } | ||
| 873 | |||
| 874 | 38554268 | static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt) | |
| 875 | { | ||
| 876 | 38554268 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 877 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38554268 times.
|
38554268 | av_assert0(desc); |
| 878 |
2/2✓ Branch 0 taken 22367216 times.
✓ Branch 1 taken 94285 times.
|
22461501 | return (desc->flags & AV_PIX_FMT_FLAG_RGB) || |
| 879 |
4/4✓ Branch 0 taken 22461501 times.
✓ Branch 1 taken 16092767 times.
✓ Branch 2 taken 105667 times.
✓ Branch 3 taken 22261549 times.
|
61015769 | pix_fmt == AV_PIX_FMT_MONOBLACK || pix_fmt == AV_PIX_FMT_MONOWHITE; |
| 880 | } | ||
| 881 | |||
| 882 | 118886 | static av_always_inline int isFloat(enum AVPixelFormat pix_fmt) | |
| 883 | { | ||
| 884 | 118886 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 885 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 118886 times.
|
118886 | av_assert0(desc); |
| 886 | 118886 | return desc->flags & AV_PIX_FMT_FLAG_FLOAT; | |
| 887 | } | ||
| 888 | |||
| 889 | 134577 | static av_always_inline int isFloat16(enum AVPixelFormat pix_fmt) | |
| 890 | { | ||
| 891 | 134577 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 892 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 134577 times.
|
134577 | av_assert0(desc); |
| 893 |
4/4✓ Branch 0 taken 2117 times.
✓ Branch 1 taken 132460 times.
✓ Branch 2 taken 822 times.
✓ Branch 3 taken 1295 times.
|
134577 | return (desc->flags & AV_PIX_FMT_FLAG_FLOAT) && desc->comp[0].depth == 16; |
| 894 | } | ||
| 895 | |||
| 896 | 696589 | static av_always_inline int isALPHA(enum AVPixelFormat pix_fmt) | |
| 897 | { | ||
| 898 | 696589 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 899 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 696589 times.
|
696589 | av_assert0(desc); |
| 900 |
2/2✓ Branch 0 taken 1079 times.
✓ Branch 1 taken 695510 times.
|
696589 | if (pix_fmt == AV_PIX_FMT_PAL8) |
| 901 | 1079 | return 1; | |
| 902 | 695510 | return desc->flags & AV_PIX_FMT_FLAG_ALPHA; | |
| 903 | } | ||
| 904 | |||
| 905 | 573417 | static av_always_inline int isPacked(enum AVPixelFormat pix_fmt) | |
| 906 | { | ||
| 907 | 573417 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 908 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 573417 times.
|
573417 | av_assert0(desc); |
| 909 |
4/4✓ Branch 0 taken 427740 times.
✓ Branch 1 taken 117593 times.
✓ Branch 2 taken 454882 times.
✓ Branch 3 taken 942 times.
|
573417 | return (desc->nb_components >= 2 && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) || |
| 910 |
2/2✓ Branch 0 taken 452164 times.
✓ Branch 1 taken 2718 times.
|
454882 | pix_fmt == AV_PIX_FMT_PAL8 || |
| 911 |
4/4✓ Branch 0 taken 545333 times.
✓ Branch 1 taken 28084 times.
✓ Branch 2 taken 2918 times.
✓ Branch 3 taken 449246 times.
|
1146834 | pix_fmt == AV_PIX_FMT_MONOBLACK || pix_fmt == AV_PIX_FMT_MONOWHITE; |
| 912 | } | ||
| 913 | |||
| 914 | 571704 | static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt) | |
| 915 | { | ||
| 916 | 571704 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 917 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 571704 times.
|
571704 | av_assert0(desc); |
| 918 |
4/4✓ Branch 0 taken 542613 times.
✓ Branch 1 taken 29091 times.
✓ Branch 2 taken 426160 times.
✓ Branch 3 taken 116453 times.
|
571704 | return (desc->nb_components >= 2 && (desc->flags & AV_PIX_FMT_FLAG_PLANAR)); |
| 919 | } | ||
| 920 | |||
| 921 | 35355 | static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt) | |
| 922 | { | ||
| 923 | 35355 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 924 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35355 times.
|
35355 | av_assert0(desc); |
| 925 | 35355 | return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) == AV_PIX_FMT_FLAG_RGB); | |
| 926 | } | ||
| 927 | |||
| 928 | 107075 | static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt) | |
| 929 | { | ||
| 930 | 107075 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 931 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 107075 times.
|
107075 | av_assert0(desc); |
| 932 | 107075 | return ((desc->flags & (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)) == | |
| 933 | (AV_PIX_FMT_FLAG_PLANAR | AV_PIX_FMT_FLAG_RGB)); | ||
| 934 | } | ||
| 935 | |||
| 936 | 856581 | static av_always_inline int usePal(enum AVPixelFormat pix_fmt) | |
| 937 | { | ||
| 938 |
2/2✓ Branch 0 taken 75673 times.
✓ Branch 1 taken 780908 times.
|
856581 | switch (pix_fmt) { |
| 939 | 75673 | case AV_PIX_FMT_PAL8: | |
| 940 | case AV_PIX_FMT_BGR4_BYTE: | ||
| 941 | case AV_PIX_FMT_BGR8: | ||
| 942 | case AV_PIX_FMT_GRAY8: | ||
| 943 | case AV_PIX_FMT_RGB4_BYTE: | ||
| 944 | case AV_PIX_FMT_RGB8: | ||
| 945 | 75673 | return 1; | |
| 946 | 780908 | default: | |
| 947 | 780908 | return 0; | |
| 948 | } | ||
| 949 | } | ||
| 950 | |||
| 951 | /* | ||
| 952 | * Identity formats where the data is in the high bits, and the low bits are shifted away. | ||
| 953 | */ | ||
| 954 | 255246 | static av_always_inline int isDataInHighBits(enum AVPixelFormat pix_fmt) | |
| 955 | { | ||
| 956 | int i; | ||
| 957 | 255246 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 958 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 255246 times.
|
255246 | av_assert0(desc); |
| 959 |
2/2✓ Branch 0 taken 2716 times.
✓ Branch 1 taken 252530 times.
|
255246 | if (desc->flags & (AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_HWACCEL)) |
| 960 | 2716 | return 0; | |
| 961 |
2/2✓ Branch 0 taken 308353 times.
✓ Branch 1 taken 26871 times.
|
335224 | for (i = 0; i < desc->nb_components; i++) { |
| 962 |
2/2✓ Branch 0 taken 218063 times.
✓ Branch 1 taken 90290 times.
|
308353 | if (!desc->comp[i].shift) |
| 963 | 218063 | return 0; | |
| 964 |
2/2✓ Branch 0 taken 7596 times.
✓ Branch 1 taken 82694 times.
|
90290 | if ((desc->comp[i].shift + desc->comp[i].depth) & 0x7) |
| 965 | 7596 | return 0; | |
| 966 | } | ||
| 967 | 26871 | return 1; | |
| 968 | } | ||
| 969 | |||
| 970 | /* | ||
| 971 | * Identity formats where the chroma planes are swapped (CrCb order). | ||
| 972 | */ | ||
| 973 | 868379 | static av_always_inline int isSwappedChroma(enum AVPixelFormat pix_fmt) | |
| 974 | { | ||
| 975 | 868379 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); | |
| 976 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 868379 times.
|
868379 | av_assert0(desc); |
| 977 |
2/2✓ Branch 1 taken 134 times.
✓ Branch 2 taken 868245 times.
|
868379 | if (!isYUV(pix_fmt)) |
| 978 | 134 | return 0; | |
| 979 |
4/4✓ Branch 0 taken 4203 times.
✓ Branch 1 taken 864042 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 4196 times.
|
868245 | if ((desc->flags & AV_PIX_FMT_FLAG_ALPHA) && desc->nb_components < 4) |
| 980 | 7 | return 0; | |
| 981 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 868238 times.
|
868238 | if (desc->nb_components < 3) |
| 982 | ✗ | return 0; | |
| 983 |
4/4✓ Branch 1 taken 868211 times.
✓ Branch 2 taken 27 times.
✓ Branch 4 taken 859691 times.
✓ Branch 5 taken 8520 times.
|
868238 | if (!isPlanarYUV(pix_fmt) || isSemiPlanarYUV(pix_fmt)) |
| 984 | 859718 | return desc->comp[1].offset > desc->comp[2].offset; | |
| 985 | else | ||
| 986 | 8520 | return desc->comp[1].plane > desc->comp[2].plane; | |
| 987 | } | ||
| 988 | |||
| 989 | extern const uint64_t ff_dither4[2]; | ||
| 990 | extern const uint64_t ff_dither8[2]; | ||
| 991 | |||
| 992 | extern const uint8_t ff_dither_2x2_4[3][8]; | ||
| 993 | extern const uint8_t ff_dither_2x2_8[3][8]; | ||
| 994 | extern const uint8_t ff_dither_4x4_16[5][8]; | ||
| 995 | extern const uint8_t ff_dither_8x8_32[9][8]; | ||
| 996 | extern const uint8_t ff_dither_8x8_73[9][8]; | ||
| 997 | extern const uint8_t ff_dither_8x8_128[9][8]; | ||
| 998 | extern const uint8_t ff_dither_8x8_220[9][8]; | ||
| 999 | |||
| 1000 | extern const int32_t ff_yuv2rgb_coeffs[11][4]; | ||
| 1001 | |||
| 1002 | extern const AVClass ff_sws_context_class; | ||
| 1003 | |||
| 1004 | int ff_sws_init_single_context(SwsContext *sws, SwsFilter *srcFilter, | ||
| 1005 | SwsFilter *dstFilter); | ||
| 1006 | |||
| 1007 | /** | ||
| 1008 | * Set c->convert_unscaled to an unscaled converter if one exists for the | ||
| 1009 | * specific source and destination formats, bit depths, flags, etc. | ||
| 1010 | */ | ||
| 1011 | void ff_get_unscaled_swscale(SwsInternal *c); | ||
| 1012 | void ff_get_unscaled_swscale_ppc(SwsInternal *c); | ||
| 1013 | void ff_get_unscaled_swscale_arm(SwsInternal *c); | ||
| 1014 | void ff_get_unscaled_swscale_aarch64(SwsInternal *c); | ||
| 1015 | |||
| 1016 | void ff_sws_init_scale(SwsInternal *c); | ||
| 1017 | |||
| 1018 | void ff_sws_init_input_funcs(SwsInternal *c, | ||
| 1019 | planar1_YV12_fn *lumToYV12, | ||
| 1020 | planar1_YV12_fn *alpToYV12, | ||
| 1021 | planar2_YV12_fn *chrToYV12, | ||
| 1022 | planarX_YV12_fn *readLumPlanar, | ||
| 1023 | planarX_YV12_fn *readAlpPlanar, | ||
| 1024 | planarX2_YV12_fn *readChrPlanar); | ||
| 1025 | void ff_sws_init_output_funcs(SwsInternal *c, | ||
| 1026 | yuv2planar1_fn *yuv2plane1, | ||
| 1027 | yuv2planarX_fn *yuv2planeX, | ||
| 1028 | yuv2interleavedX_fn *yuv2nv12cX, | ||
| 1029 | yuv2packed1_fn *yuv2packed1, | ||
| 1030 | yuv2packed2_fn *yuv2packed2, | ||
| 1031 | yuv2packedX_fn *yuv2packedX, | ||
| 1032 | yuv2anyX_fn *yuv2anyX); | ||
| 1033 | void ff_sws_init_swscale_ppc(SwsInternal *c); | ||
| 1034 | void ff_sws_init_swscale_vsx(SwsInternal *c); | ||
| 1035 | void ff_sws_init_swscale_x86(SwsInternal *c); | ||
| 1036 | void ff_sws_init_swscale_aarch64(SwsInternal *c); | ||
| 1037 | void ff_sws_init_swscale_arm(SwsInternal *c); | ||
| 1038 | void ff_sws_init_swscale_loongarch(SwsInternal *c); | ||
| 1039 | void ff_sws_init_swscale_riscv(SwsInternal *c); | ||
| 1040 | |||
| 1041 | int ff_sws_init_altivec_bufs(SwsInternal *c); | ||
| 1042 | void ff_sws_free_altivec_bufs(SwsInternal *c); | ||
| 1043 | |||
| 1044 | void ff_hyscale_fast_c(SwsInternal *c, int16_t *dst, int dstWidth, | ||
| 1045 | const uint8_t *src, int srcW, int xInc); | ||
| 1046 | void ff_hcscale_fast_c(SwsInternal *c, int16_t *dst1, int16_t *dst2, | ||
| 1047 | int dstWidth, const uint8_t *src1, | ||
| 1048 | const uint8_t *src2, int srcW, int xInc); | ||
| 1049 | int ff_init_hscaler_mmxext(int dstW, int xInc, uint8_t *filterCode, | ||
| 1050 | int16_t *filter, int32_t *filterPos, | ||
| 1051 | int numSplits); | ||
| 1052 | void ff_hyscale_fast_mmxext(SwsInternal *c, int16_t *dst, | ||
| 1053 | int dstWidth, const uint8_t *src, | ||
| 1054 | int srcW, int xInc); | ||
| 1055 | void ff_hcscale_fast_mmxext(SwsInternal *c, int16_t *dst1, int16_t *dst2, | ||
| 1056 | int dstWidth, const uint8_t *src1, | ||
| 1057 | const uint8_t *src2, int srcW, int xInc); | ||
| 1058 | |||
| 1059 | int ff_sws_alphablendaway(SwsInternal *c, const uint8_t *const src[], | ||
| 1060 | const int srcStride[], int srcSliceY, int srcSliceH, | ||
| 1061 | uint8_t *const dst[], const int dstStride[]); | ||
| 1062 | |||
| 1063 | void ff_copyPlane(const uint8_t *src, int srcStride, | ||
| 1064 | int srcSliceY, int srcSliceH, int width, | ||
| 1065 | uint8_t *dst, int dstStride); | ||
| 1066 | |||
| 1067 | 1515 | static inline void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, | |
| 1068 | int alpha, int bits, const int big_endian) | ||
| 1069 | { | ||
| 1070 | 1515 | uint8_t *ptr = plane + stride * y; | |
| 1071 |
1/2✓ Branch 0 taken 1515 times.
✗ Branch 1 not taken.
|
1515 | int v = alpha ? 0xFFFF>>(16-bits) : (1<<(bits-1)); |
| 1072 |
2/2✓ Branch 0 taken 586 times.
✓ Branch 1 taken 929 times.
|
1515 | if (big_endian != HAVE_BIGENDIAN) |
| 1073 | 586 | v = av_bswap16(v); | |
| 1074 |
2/2✓ Branch 0 taken 374468 times.
✓ Branch 1 taken 1515 times.
|
375983 | for (int i = 0; i < height; i++) { |
| 1075 |
2/2✓ Branch 0 taken 127413704 times.
✓ Branch 1 taken 374468 times.
|
127788172 | for (int j = 0; j < width; j++) |
| 1076 | 127413704 | AV_WN16(ptr + 2 * j, v); | |
| 1077 | 374468 | ptr += stride; | |
| 1078 | } | ||
| 1079 | 1515 | } | |
| 1080 | |||
| 1081 | 140 | static inline void fillPlane32(uint8_t *plane, int stride, int width, int height, int y, | |
| 1082 | int alpha, int bits, const int big_endian, int is_float) | ||
| 1083 | { | ||
| 1084 | 140 | uint8_t *ptr = plane + stride * y; | |
| 1085 | uint32_t v; | ||
| 1086 | 140 | uint32_t onef32 = 0x3f800000; | |
| 1087 |
1/2✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
|
140 | if (is_float) |
| 1088 |
1/2✓ Branch 0 taken 140 times.
✗ Branch 1 not taken.
|
140 | v = alpha ? onef32 : 0; |
| 1089 | else | ||
| 1090 | ✗ | v = alpha ? 0xFFFFFFFF>>(32-bits) : (1<<(bits-1)); | |
| 1091 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 98 times.
|
140 | if (big_endian != HAVE_BIGENDIAN) |
| 1092 | 42 | v = av_bswap32(v); | |
| 1093 | |||
| 1094 |
2/2✓ Branch 0 taken 36480 times.
✓ Branch 1 taken 140 times.
|
36620 | for (int i = 0; i < height; i++) { |
| 1095 |
2/2✓ Branch 0 taken 12349440 times.
✓ Branch 1 taken 36480 times.
|
12385920 | for (int j = 0; j < width; j++) |
| 1096 | 12349440 | AV_WN32(ptr + 4 * j, v); | |
| 1097 | 36480 | ptr += stride; | |
| 1098 | } | ||
| 1099 | 140 | } | |
| 1100 | |||
| 1101 | |||
| 1102 | #define MAX_SLICE_PLANES 4 | ||
| 1103 | |||
| 1104 | /// Slice plane | ||
| 1105 | typedef struct SwsPlane | ||
| 1106 | { | ||
| 1107 | int available_lines; ///< max number of lines that can be hold by this plane | ||
| 1108 | int sliceY; ///< index of first line | ||
| 1109 | int sliceH; ///< number of lines | ||
| 1110 | uint8_t **line; ///< line buffer | ||
| 1111 | uint8_t **tmp; ///< Tmp line buffer used by mmx code | ||
| 1112 | } SwsPlane; | ||
| 1113 | |||
| 1114 | /** | ||
| 1115 | * Struct which defines a slice of an image to be scaled or an output for | ||
| 1116 | * a scaled slice. | ||
| 1117 | * A slice can also be used as intermediate ring buffer for scaling steps. | ||
| 1118 | */ | ||
| 1119 | typedef struct SwsSlice | ||
| 1120 | { | ||
| 1121 | int width; ///< Slice line width | ||
| 1122 | int h_chr_sub_sample; ///< horizontal chroma subsampling factor | ||
| 1123 | int v_chr_sub_sample; ///< vertical chroma subsampling factor | ||
| 1124 | int is_ring; ///< flag to identify if this slice is a ring buffer | ||
| 1125 | int should_free_lines; ///< flag to identify if there are dynamic allocated lines | ||
| 1126 | enum AVPixelFormat fmt; ///< planes pixel format | ||
| 1127 | SwsPlane plane[MAX_SLICE_PLANES]; ///< color planes | ||
| 1128 | } SwsSlice; | ||
| 1129 | |||
| 1130 | /** | ||
| 1131 | * Struct which holds all necessary data for processing a slice. | ||
| 1132 | * A processing step can be a color conversion or horizontal/vertical scaling. | ||
| 1133 | */ | ||
| 1134 | typedef struct SwsFilterDescriptor | ||
| 1135 | { | ||
| 1136 | SwsSlice *src; ///< Source slice | ||
| 1137 | SwsSlice *dst; ///< Output slice | ||
| 1138 | |||
| 1139 | int alpha; ///< Flag for processing alpha channel | ||
| 1140 | void *instance; ///< Filter instance data | ||
| 1141 | |||
| 1142 | /// Function for processing input slice sliceH lines starting from line sliceY | ||
| 1143 | int (*process)(SwsInternal *c, struct SwsFilterDescriptor *desc, int sliceY, int sliceH); | ||
| 1144 | } SwsFilterDescriptor; | ||
| 1145 | |||
| 1146 | // warp input lines in the form (src + width*i + j) to slice format (line[i][j]) | ||
| 1147 | // relative=true means first line src[x][0] otherwise first line is src[x][lum/crh Y] | ||
| 1148 | int ff_init_slice_from_src(SwsSlice * s, uint8_t *const src[4], const int stride[4], | ||
| 1149 | int srcW, int lumY, int lumH, int chrY, int chrH, int relative); | ||
| 1150 | |||
| 1151 | // Initialize scaler filter descriptor chain | ||
| 1152 | int ff_init_filters(SwsInternal *c); | ||
| 1153 | |||
| 1154 | // Free all filter data | ||
| 1155 | int ff_free_filters(SwsInternal *c); | ||
| 1156 | |||
| 1157 | /* | ||
| 1158 | function for applying ring buffer logic into slice s | ||
| 1159 | It checks if the slice can hold more @lum lines, if yes | ||
| 1160 | do nothing otherwise remove @lum least used lines. | ||
| 1161 | It applies the same procedure for @chr lines. | ||
| 1162 | */ | ||
| 1163 | int ff_rotate_slice(SwsSlice *s, int lum, int chr); | ||
| 1164 | |||
| 1165 | /// initializes gamma conversion descriptor | ||
| 1166 | int ff_init_gamma_convert(SwsFilterDescriptor *desc, SwsSlice * src, uint16_t *table); | ||
| 1167 | |||
| 1168 | /// initializes lum pixel format conversion descriptor | ||
| 1169 | int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal); | ||
| 1170 | |||
| 1171 | /// initializes lum horizontal scaling descriptor | ||
| 1172 | int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc); | ||
| 1173 | |||
| 1174 | /// initializes chr pixel format conversion descriptor | ||
| 1175 | int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal); | ||
| 1176 | |||
| 1177 | /// initializes chr horizontal scaling descriptor | ||
| 1178 | int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc); | ||
| 1179 | |||
| 1180 | int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst); | ||
| 1181 | |||
| 1182 | /// initializes vertical scaling descriptors | ||
| 1183 | int ff_init_vscale(SwsInternal *c, SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst); | ||
| 1184 | |||
| 1185 | /// setup vertical scaler functions | ||
| 1186 | void ff_init_vscale_pfn(SwsInternal *c, yuv2planar1_fn yuv2plane1, yuv2planarX_fn yuv2planeX, | ||
| 1187 | yuv2interleavedX_fn yuv2nv12cX, yuv2packed1_fn yuv2packed1, yuv2packed2_fn yuv2packed2, | ||
| 1188 | yuv2packedX_fn yuv2packedX, yuv2anyX_fn yuv2anyX, int use_mmx); | ||
| 1189 | |||
| 1190 | void ff_sws_slice_worker(void *priv, int jobnr, int threadnr, | ||
| 1191 | int nb_jobs, int nb_threads); | ||
| 1192 | |||
| 1193 | int ff_swscale(SwsInternal *c, const uint8_t *const src[], const int srcStride[], | ||
| 1194 | int srcSliceY, int srcSliceH, uint8_t *const dst[], | ||
| 1195 | const int dstStride[], int dstSliceY, int dstSliceH); | ||
| 1196 | |||
| 1197 | |||
| 1198 | //number of extra lines to process | ||
| 1199 | #define MAX_LINES_AHEAD 4 | ||
| 1200 | |||
| 1201 | //shuffle filter and filterPos for hyScale and hcScale filters in avx2 | ||
| 1202 | int ff_shuffle_filter_coefficients(SwsInternal *c, int* filterPos, int filterSize, int16_t *filter, int dstW); | ||
| 1203 | #endif /* SWSCALE_SWSCALE_INTERNAL_H */ | ||
| 1204 |