diff --git a/libavfilter/vf_hqx.c b/libavfilter/vf_hqx.c index e7ed9cfb99..4783381565 100644 --- a/libavfilter/vf_hqx.c +++ b/libavfilter/vf_hqx.c @@ -510,14 +510,21 @@ static av_cold int init(AVFilterContext *ctx) static const hqxfunc_t hqxfuncs[] = {hq2x, hq3x, hq4x}; uint32_t c; - for (c = 0; c < FF_ARRAY_ELEMS(hqx->rgbtoyuv); c++) { - const int r = c >> 16 & 0xff; - const int g = c >> 8 & 0xff; - const int b = c & 0xff; - const uint32_t y = (uint32_t)(( 299*r + 587*g + 114*b)/1000); - const uint32_t u = (uint32_t)((-169*r - 331*g + 500*b)/1000) + 128; - const uint32_t v = (uint32_t)(( 500*r - 419*g - 81*b)/1000) + 128; - hqx->rgbtoyuv[c] = (y << 16) + (u << 8) + v; + int bg, rg, g; + + for (bg=-255; bg<256; bg++) { + for (rg=-255; rg<256; rg++) { + const uint32_t u = (uint32_t)((-169*rg + 500*bg)/1000) + 128; + const uint32_t v = (uint32_t)(( 500*rg - 81*bg)/1000) + 128; + int startg = FFMAX3(-bg, -rg, 0); + int endg = FFMIN3(255-bg, 255-rg, 255); + uint32_t y = (uint32_t)(( 299*rg + 1000*startg + 114*bg)/1000); + c = bg + (rg<<16) + 0x010101 * startg; + for (g = startg; g <= endg; g++) { + hqx->rgbtoyuv[c] = ((y++) << 16) + (u << 8) + v; + c+= 0x010101; + } + } } hqx->func = hqxfuncs[hqx->n - 2];