12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108
#include "dc_spl.h"
#include "dc_spl_scl_easf_filters.h"
#include "dc_spl_isharp_filters.h"
#include "spl_debug.h"
#define spl_div64_s64 div64_s64
#define spl_swap swap
#include "custom_float.h"
#define spl_custom_float_format custom_float_format
#define spl_convert_to_custom_float_format convert_to_custom_float_format
#define IDENTITY_RATIO(ratio) (spl_fixpt_u3d19(ratio) == (1 << 19))
#define MIN_VIEWPORT_SIZE 12
static bool spl_is_yuv420(enum spl_pixel_format format)
{
if ((format >= SPL_PIXEL_FORMAT_420BPP8) &&
(format <= SPL_PIXEL_FORMAT_420BPP10))
return true;
return false;
}
static bool spl_is_yuv422(enum spl_pixel_format format)
{
if ((format >= SPL_PIXEL_FORMAT_422BPP8) &&
(format <= SPL_PIXEL_FORMAT_422BPP12))
return true;
return false;
}
static bool spl_is_rgb8(enum spl_pixel_format format)
{
if (format == SPL_PIXEL_FORMAT_ARGB8888)
return true;
return false;
}
static bool spl_is_video_format(enum spl_pixel_format format)
{
if (format >= SPL_PIXEL_FORMAT_VIDEO_BEGIN
&& format <= SPL_PIXEL_FORMAT_VIDEO_END)
return true;
else
return false;
}
static bool spl_is_subsampled_format(enum spl_pixel_format format)
{
if (format >= SPL_PIXEL_FORMAT_SUBSAMPLED_BEGIN
&& format <= SPL_PIXEL_FORMAT_SUBSAMPLED_END)
return true;
else
return false;
}
static struct spl_rect intersect_rec(const struct spl_rect *r0, const struct spl_rect *r1)
{
struct spl_rect rec;
int r0_x_end = r0->x + r0->width;
int r1_x_end = r1->x + r1->width;
int r0_y_end = r0->y + r0->height;
int r1_y_end = r1->y + r1->height;
rec.x = r0->x > r1->x ? r0->x : r1->x;
rec.width = r0_x_end > r1_x_end ? r1_x_end - rec.x : r0_x_end - rec.x;
rec.y = r0->y > r1->y ? r0->y : r1->y;
rec.height = r0_y_end > r1_y_end ? r1_y_end - rec.y : r0_y_end - rec.y;
if (rec.width < 0 || rec.height < 0)
memset(&rec, 0, sizeof(rec));
return rec;
}
static struct spl_rect shift_rec(const struct spl_rect *rec_in, int x, int y)
{
struct spl_rect rec_out = *rec_in;
rec_out.x += x;
rec_out.y += y;
return rec_out;
}
static void spl_opp_adjust_rect(struct spl_rect *rec, const struct spl_opp_adjust *adjust)
{
if ((rec->x + adjust->x) >= 0)
rec->x += adjust->x;
if ((rec->y + adjust->y) >= 0)
rec->y += adjust->y;
if ((rec->width + adjust->width) >= 1)
rec->width += adjust->width;
if ((rec->height + adjust->height) >= 1)
rec->height += adjust->height;
}
static struct spl_rect calculate_plane_rec_in_timing_active(
struct spl_in *spl_in,
const struct spl_rect *rec_in)
{
const struct spl_rect *stream_src = &spl_in->basic_out.src_rect;
const struct spl_rect *stream_dst = &spl_in->basic_out.dst_rect;
struct spl_rect rec_out = {0};
struct spl_fixed31_32 temp;
temp = spl_fixpt_from_fraction(
rec_in->x * (long long)stream_dst->width,
stream_src->width);
rec_out.x = stream_dst->x + spl_fixpt_round(temp);
temp = spl_fixpt_from_fraction(
(rec_in->x + rec_in->width) * (long long)stream_dst->width,
stream_src->width);
rec_out.width = stream_dst->x + spl_fixpt_round(temp) - rec_out.x;
temp = spl_fixpt_from_fraction(
rec_in->y * (long long)stream_dst->height,
stream_src->height);
rec_out.y = stream_dst->y + spl_fixpt_round(temp);
temp = spl_fixpt_from_fraction(
(rec_in->y + rec_in->height) * (long long)stream_dst->height,
stream_src->height);
rec_out.height = stream_dst->y + spl_fixpt_round(temp) - rec_out.y;
return rec_out;
}
static struct spl_rect calculate_mpc_slice_in_timing_active(
struct spl_in *spl_in,
struct spl_rect *plane_clip_rec)
{
bool use_recout_width_aligned =
spl_in->basic_in.num_h_slices_recout_width_align.use_recout_width_aligned;
int mpc_slice_count =
spl_in->basic_in.num_h_slices_recout_width_align.num_slices_recout_width.mpc_num_h_slices;
int recout_width_align =
spl_in->basic_in.num_h_slices_recout_width_align.num_slices_recout_width.mpc_recout_width_align;
int mpc_slice_idx = spl_in->basic_in.mpc_h_slice_index;
int epimo = mpc_slice_count - plane_clip_rec->width % mpc_slice_count - 1;
struct spl_rect mpc_rec;
if (spl_in->basic_in.custom_width != 0) {
mpc_rec.width = spl_in->basic_in.custom_width;
mpc_rec.x = spl_in->basic_in.custom_x;
mpc_rec.height = plane_clip_rec->height;
mpc_rec.y = plane_clip_rec->y;
} else if (use_recout_width_aligned) {
mpc_rec.width = recout_width_align;
if ((mpc_rec.width * (mpc_slice_idx + 1)) > plane_clip_rec->width) {
mpc_rec.width = plane_clip_rec->width % recout_width_align;
mpc_rec.x = plane_clip_rec->x + recout_width_align * mpc_slice_idx;
} else
mpc_rec.x = plane_clip_rec->x + mpc_rec.width * mpc_slice_idx;
mpc_rec.height = plane_clip_rec->height;
mpc_rec.y = plane_clip_rec->y;
} else {
mpc_rec.width = plane_clip_rec->width / mpc_slice_count;
mpc_rec.x = plane_clip_rec->x + mpc_rec.width * mpc_slice_idx;
mpc_rec.height = plane_clip_rec->height;
mpc_rec.y = plane_clip_rec->y;
}
SPL_ASSERT(mpc_slice_count == 1 ||
spl_in->basic_out.view_format != SPL_VIEW_3D_SIDE_BY_SIDE ||
mpc_rec.width % 2 == 0);
if ((use_recout_width_aligned == false) &&
mpc_slice_idx > epimo && spl_in->basic_in.custom_width == 0) {
mpc_rec.x += mpc_slice_idx - epimo - 1;
mpc_rec.width += 1;
}
if (spl_in->basic_out.view_format == SPL_VIEW_3D_TOP_AND_BOTTOM) {
SPL_ASSERT(mpc_rec.height % 2 == 0);
mpc_rec.height /= 2;
}
return mpc_rec;
}
static struct spl_rect calculate_odm_slice_in_timing_active(struct spl_in *spl_in)
{
int odm_slice_count = spl_in->basic_out.odm_combine_factor;
int odm_slice_idx = spl_in->odm_slice_index;
bool is_last_odm_slice = (odm_slice_idx + 1) == odm_slice_count;
int h_active = spl_in->basic_out.output_size.width;
int v_active = spl_in->basic_out.output_size.height;
int odm_slice_width;
struct spl_rect odm_rec;
if (spl_in->basic_out.odm_combine_factor > 0) {
odm_slice_width = h_active / odm_slice_count;
if (spl_in->basic_out.use_two_pixels_per_container && (odm_slice_width % 2))
odm_slice_width++;
odm_rec.x = odm_slice_width * odm_slice_idx;
odm_rec.width = is_last_odm_slice ?
h_active - odm_slice_width * (odm_slice_count - 1) :
odm_slice_width;
odm_rec.y = 0;
odm_rec.height = v_active;
return odm_rec;
}
return spl_in->basic_out.odm_slice_rect;
}
static void spl_calculate_recout(struct spl_in *spl_in, struct spl_scratch *spl_scratch, struct spl_out *spl_out)
{
struct spl_rect plane_clip;
struct spl_rect mpc_slice_of_plane_clip;
struct spl_rect odm_slice;
struct spl_rect overlapping_area;
plane_clip = calculate_plane_rec_in_timing_active(spl_in,
&spl_in->basic_in.clip_rect);
plane_clip = intersect_rec(&plane_clip,
&spl_in->basic_out.dst_rect);
mpc_slice_of_plane_clip = calculate_mpc_slice_in_timing_active(
spl_in, &plane_clip);
odm_slice = calculate_odm_slice_in_timing_active(spl_in);
overlapping_area = intersect_rec(&mpc_slice_of_plane_clip, &odm_slice);
if (overlapping_area.height > 0 &&
overlapping_area.width > 0) {
spl_scratch->scl_data.recout = shift_rec(
&overlapping_area,
-odm_slice.x, -odm_slice.y);
spl_scratch->scl_data.recout.height -=
spl_in->debug.visual_confirm_base_offset;
spl_scratch->scl_data.recout.height -=
spl_in->debug.visual_confirm_dpp_offset;
} else
memset(&spl_scratch->scl_data.recout, 0,
sizeof(struct spl_rect));
}
static void spl_calculate_scaling_ratios(struct spl_in *spl_in,
struct spl_scratch *spl_scratch,
struct spl_out *spl_out)
{
const int in_w = spl_in->basic_out.src_rect.width;
const int in_h = spl_in->basic_out.src_rect.height;
const int out_w = spl_in->basic_out.dst_rect.width;
const int out_h = spl_in->basic_out.dst_rect.height;
struct spl_rect surf_src = spl_in->basic_in.src_rect;
if (spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_90 ||
spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_270)
spl_swap(surf_src.height, surf_src.width);
spl_scratch->scl_data.ratios.horz = spl_fixpt_from_fraction(
surf_src.width,
spl_in->basic_in.dst_rect.width);
spl_scratch->scl_data.ratios.vert = spl_fixpt_from_fraction(
surf_src.height,
spl_in->basic_in.dst_rect.height);
if (spl_in->basic_out.view_format == SPL_VIEW_3D_SIDE_BY_SIDE)
spl_scratch->scl_data.ratios.horz.value *= 2;
else if (spl_in->basic_out.view_format == SPL_VIEW_3D_TOP_AND_BOTTOM)
spl_scratch->scl_data.ratios.vert.value *= 2;
spl_scratch->scl_data.ratios.vert.value = spl_div64_s64(
spl_scratch->scl_data.ratios.vert.value * in_h, out_h);
spl_scratch->scl_data.ratios.horz.value = spl_div64_s64(
spl_scratch->scl_data.ratios.horz.value * in_w, out_w);
spl_scratch->scl_data.ratios.horz_c = spl_scratch->scl_data.ratios.horz;
spl_scratch->scl_data.ratios.vert_c = spl_scratch->scl_data.ratios.vert;
if (spl_is_yuv420(spl_in->basic_in.format)) {
spl_scratch->scl_data.ratios.horz_c.value /= 2;
spl_scratch->scl_data.ratios.vert_c.value /= 2;
} else if (spl_is_yuv422(spl_in->basic_in.format)) {
if (spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_90 ||
spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_270)
spl_scratch->scl_data.ratios.vert_c.value /= 2;
else
spl_scratch->scl_data.ratios.horz_c.value /= 2;
}
spl_scratch->scl_data.ratios.horz = spl_fixpt_truncate(
spl_scratch->scl_data.ratios.horz, 19);
spl_scratch->scl_data.ratios.vert = spl_fixpt_truncate(
spl_scratch->scl_data.ratios.vert, 19);
spl_scratch->scl_data.ratios.horz_c = spl_fixpt_truncate(
spl_scratch->scl_data.ratios.horz_c, 19);
spl_scratch->scl_data.ratios.vert_c = spl_fixpt_truncate(
spl_scratch->scl_data.ratios.vert_c, 19);
spl_scratch->scl_data.recip_ratios.horz = spl_fixpt_recip(
spl_scratch->scl_data.ratios.horz);
spl_scratch->scl_data.recip_ratios.vert = spl_fixpt_recip(
spl_scratch->scl_data.ratios.vert);
spl_scratch->scl_data.recip_ratios.horz_c = spl_fixpt_recip(
spl_scratch->scl_data.ratios.horz_c);
spl_scratch->scl_data.recip_ratios.vert_c = spl_fixpt_recip(
spl_scratch->scl_data.ratios.vert_c);
}
static void spl_calculate_viewport_size(struct spl_in *spl_in, struct spl_scratch *spl_scratch)
{
spl_scratch->scl_data.viewport.width = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.horz,
spl_scratch->scl_data.recout.width));
spl_scratch->scl_data.viewport.height = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.vert,
spl_scratch->scl_data.recout.height));
spl_scratch->scl_data.viewport_c.width = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.horz_c,
spl_scratch->scl_data.recout.width));
spl_scratch->scl_data.viewport_c.height = spl_fixpt_ceil(spl_fixpt_mul_int(spl_scratch->scl_data.ratios.vert_c,
spl_scratch->scl_data.recout.height));
if (spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_90 ||
spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_270) {
spl_swap(spl_scratch->scl_data.viewport.width, spl_scratch->scl_data.viewport.height);
spl_swap(spl_scratch->scl_data.viewport_c.width, spl_scratch->scl_data.viewport_c.height);
}
}
static void spl_get_vp_scan_direction(enum spl_rotation_angle rotation,
bool horizontal_mirror,
bool *orthogonal_rotation,
bool *flip_vert_scan_dir,
bool *flip_horz_scan_dir)
{
*orthogonal_rotation = false;
*flip_vert_scan_dir = false;
*flip_horz_scan_dir = false;
if (rotation == SPL_ROTATION_ANGLE_180) {
*flip_vert_scan_dir = true;
*flip_horz_scan_dir = true;
} else if (rotation == SPL_ROTATION_ANGLE_90) {
*orthogonal_rotation = true;
*flip_horz_scan_dir = true;
} else if (rotation == SPL_ROTATION_ANGLE_270) {
*orthogonal_rotation = true;
*flip_vert_scan_dir = true;
}
if (horizontal_mirror)
*flip_horz_scan_dir = !*flip_horz_scan_dir;
}
static void spl_calculate_init_and_vp(bool flip_scan_dir,
int recout_offset_within_recout_full,
int recout_size,
int src_size,
int taps,
struct spl_fixed31_32 ratio,
struct spl_fixed31_32 init_adj,
struct spl_fixed31_32 *init,
int *vp_offset,
int *vp_size)
{
struct spl_fixed31_32 temp;
int int_part;
temp = spl_fixpt_mul_int(ratio, recout_offset_within_recout_full);
*vp_offset = spl_fixpt_floor(temp);
temp.value &= 0xffffffff;
*init = spl_fixpt_add(spl_fixpt_div_int(spl_fixpt_add_int(ratio, taps + 1), 2), temp);
*init = spl_fixpt_add(*init, init_adj);
*init = spl_fixpt_truncate(*init, 19);
int_part = spl_fixpt_floor(*init);
if (int_part < taps) {
int_part = taps - int_part;
if (int_part > *vp_offset)
int_part = *vp_offset;
*vp_offset -= int_part;
*init = spl_fixpt_add_int(*init, int_part);
}
temp = spl_fixpt_add(*init, spl_fixpt_mul_int(ratio, recout_size - 1));
*vp_size = spl_fixpt_floor(temp);
if (*vp_size + *vp_offset > src_size)
*vp_size = src_size - *vp_offset;
if (flip_scan_dir)
*vp_offset = src_size - *vp_offset - *vp_size;
}
static void spl_calculate_inits_and_viewports(struct spl_in *spl_in,
struct spl_scratch *spl_scratch)
{
struct spl_rect src = spl_in->basic_in.src_rect;
struct spl_rect recout_dst_in_active_timing;
struct spl_rect recout_clip_in_active_timing;
struct spl_rect recout_clip_in_recout_dst;
struct spl_rect overlap_in_active_timing;
struct spl_rect odm_slice = calculate_odm_slice_in_timing_active(spl_in);
int vp_hc_div = spl_is_subsampled_format(spl_in->basic_in.format) ? 2 : 1;
int vp_vc_div = spl_is_yuv420(spl_in->basic_in.format) ? 2 : 1;
bool orthogonal_rotation, flip_vert_scan_dir, flip_horz_scan_dir;
struct spl_fixed31_32 init_adj_h = spl_fixpt_zero;
struct spl_fixed31_32 init_adj_v = spl_fixpt_zero;
recout_clip_in_active_timing = shift_rec(
&spl_scratch->scl_data.recout, odm_slice.x, odm_slice.y);
recout_dst_in_active_timing = calculate_plane_rec_in_timing_active(
spl_in, &spl_in->basic_in.dst_rect);
overlap_in_active_timing = intersect_rec(&recout_clip_in_active_timing,
&recout_dst_in_active_timing);
if (overlap_in_active_timing.width > 0 &&
overlap_in_active_timing.height > 0)
recout_clip_in_recout_dst = shift_rec(&overlap_in_active_timing,
-recout_dst_in_active_timing.x,
-recout_dst_in_active_timing.y);
else
memset(&recout_clip_in_recout_dst, 0, sizeof(struct spl_rect));
spl_get_vp_scan_direction(
spl_in->basic_in.rotation,
spl_in->basic_in.horizontal_mirror,
&orthogonal_rotation,
&flip_vert_scan_dir,
&flip_horz_scan_dir);
if (spl_is_subsampled_format(spl_in->basic_in.format)) {
int h_sign = flip_horz_scan_dir ? -1 : 1;
int v_sign = flip_vert_scan_dir ? -1 : 1;
switch (spl_in->basic_in.cositing) {
case CHROMA_COSITING_TOPLEFT:
init_adj_h = spl_fixpt_from_fraction(h_sign, 4);
init_adj_v = spl_fixpt_from_fraction(v_sign, 4);
break;
case CHROMA_COSITING_LEFT:
init_adj_h = spl_fixpt_from_fraction(h_sign, 4);
init_adj_v = spl_fixpt_zero;
break;
case CHROMA_COSITING_NONE:
default:
init_adj_h = spl_fixpt_zero;
init_adj_v = spl_fixpt_zero;
break;
}
}
if (orthogonal_rotation) {
spl_swap(src.width, src.height);
spl_swap(flip_vert_scan_dir, flip_horz_scan_dir);
spl_swap(vp_hc_div, vp_vc_div);
spl_swap(init_adj_h, init_adj_v);
}
spl_calculate_init_and_vp(
flip_horz_scan_dir,
recout_clip_in_recout_dst.x,
spl_scratch->scl_data.recout.width,
src.width,
spl_scratch->scl_data.taps.h_taps,
spl_scratch->scl_data.ratios.horz,
spl_fixpt_zero,
&spl_scratch->scl_data.inits.h,
&spl_scratch->scl_data.viewport.x,
&spl_scratch->scl_data.viewport.width);
spl_calculate_init_and_vp(
flip_horz_scan_dir,
recout_clip_in_recout_dst.x,
spl_scratch->scl_data.recout.width,
src.width / vp_hc_div,
spl_scratch->scl_data.taps.h_taps_c,
spl_scratch->scl_data.ratios.horz_c,
init_adj_h,
&spl_scratch->scl_data.inits.h_c,
&spl_scratch->scl_data.viewport_c.x,
&spl_scratch->scl_data.viewport_c.width);
spl_calculate_init_and_vp(
flip_vert_scan_dir,
recout_clip_in_recout_dst.y,
spl_scratch->scl_data.recout.height,
src.height,
spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.ratios.vert,
spl_fixpt_zero,
&spl_scratch->scl_data.inits.v,
&spl_scratch->scl_data.viewport.y,
&spl_scratch->scl_data.viewport.height);
spl_calculate_init_and_vp(
flip_vert_scan_dir,
recout_clip_in_recout_dst.y,
spl_scratch->scl_data.recout.height,
src.height / vp_vc_div,
spl_scratch->scl_data.taps.v_taps_c,
spl_scratch->scl_data.ratios.vert_c,
init_adj_v,
&spl_scratch->scl_data.inits.v_c,
&spl_scratch->scl_data.viewport_c.y,
&spl_scratch->scl_data.viewport_c.height);
if (orthogonal_rotation) {
spl_swap(spl_scratch->scl_data.viewport.x, spl_scratch->scl_data.viewport.y);
spl_swap(spl_scratch->scl_data.viewport.width, spl_scratch->scl_data.viewport.height);
spl_swap(spl_scratch->scl_data.viewport_c.x, spl_scratch->scl_data.viewport_c.y);
spl_swap(spl_scratch->scl_data.viewport_c.width, spl_scratch->scl_data.viewport_c.height);
spl_swap(vp_hc_div, vp_vc_div);
}
spl_scratch->scl_data.viewport.x += src.x;
spl_scratch->scl_data.viewport.y += src.y;
SPL_ASSERT(src.x % vp_hc_div == 0 && src.y % vp_vc_div == 0);
spl_scratch->scl_data.viewport_c.x += src.x / vp_hc_div;
spl_scratch->scl_data.viewport_c.y += src.y / vp_vc_div;
}
static void spl_handle_3d_recout(struct spl_in *spl_in, struct spl_rect *recout)
{
if (spl_in->basic_in.mpc_h_slice_index) {
SPL_ASSERT(spl_in->basic_in.rotation == SPL_ROTATION_ANGLE_0 ||
(spl_in->basic_out.view_format != SPL_VIEW_3D_TOP_AND_BOTTOM &&
spl_in->basic_out.view_format != SPL_VIEW_3D_SIDE_BY_SIDE));
if (spl_in->basic_out.view_format == SPL_VIEW_3D_TOP_AND_BOTTOM)
recout->y += recout->height;
else if (spl_in->basic_out.view_format == SPL_VIEW_3D_SIDE_BY_SIDE)
recout->x += recout->width;
}
}
static void spl_clamp_viewport(struct spl_rect *viewport, int min_viewport_size)
{
if (min_viewport_size == 0)
min_viewport_size = MIN_VIEWPORT_SIZE;
if (viewport->height < min_viewport_size)
viewport->height = min_viewport_size;
if (viewport->width < min_viewport_size)
viewport->width = min_viewport_size;
}
static enum scl_mode spl_get_dscl_mode(const struct spl_in *spl_in,
const struct spl_scaler_data *data,
bool enable_isharp, bool enable_easf)
{
(void)enable_easf;
const long long one = spl_fixpt_one.value;
enum spl_pixel_format pixel_format = spl_in->basic_in.format;
if (data->ratios.horz.value == one
&& data->ratios.vert.value == one
&& data->ratios.horz_c.value == one
&& data->ratios.vert_c.value == one
&& !spl_in->basic_out.always_scale
&& !enable_isharp)
return SCL_MODE_SCALING_444_BYPASS;
if (!spl_is_subsampled_format(pixel_format)) {
if (spl_is_video_format(pixel_format))
return SCL_MODE_SCALING_444_YCBCR_ENABLE;
else
return SCL_MODE_SCALING_444_RGB_ENABLE;
}
if (!enable_isharp) {
if (data->ratios.horz.value == one && data->ratios.vert.value == one && !spl_in->basic_out.always_scale)
return SCL_MODE_SCALING_420_LUMA_BYPASS;
}
return SCL_MODE_SCALING_420_YCBCR_ENABLE;
}
static void spl_choose_lls_policy(enum spl_pixel_format format,
enum linear_light_scaling *lls_pref)
{
if (spl_is_subsampled_format(format))
*lls_pref = LLS_PREF_NO;
else
*lls_pref = LLS_PREF_YES;
}
static bool enable_easf(struct spl_in *spl_in, struct spl_scratch *spl_scratch)
{
int vratio = 0;
int hratio = 0;
bool skip_easf = false;
if (spl_in->disable_easf)
skip_easf = true;
vratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert);
hratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz);
if ((vratio > 2) || (hratio > 2))
skip_easf = true;
if (spl_in->lls_pref == LLS_PREF_DONT_CARE)
spl_choose_lls_policy(spl_in->basic_in.format,
&spl_in->lls_pref);
if (spl_in->lls_pref != LLS_PREF_YES && !spl_in->prefer_easf)
skip_easf = true;
return skip_easf;
}
static bool spl_is_video_fullscreen(struct spl_in *spl_in)
{
if (spl_is_video_format(spl_in->basic_in.format) && spl_in->is_fullscreen)
return true;
return false;
}
static bool spl_get_isharp_en(struct spl_in *spl_in,
struct spl_scratch *spl_scratch)
{
bool enable_isharp = false;
int vratio = 0;
int hratio = 0;
struct spl_taps taps = spl_scratch->scl_data.taps;
bool fullscreen = spl_is_video_fullscreen(spl_in);
if (spl_in->adaptive_sharpness.enable == false)
return enable_isharp;
vratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert);
hratio = spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz);
if (vratio > 1 || hratio > 1)
return enable_isharp;
if (!spl_is_video_format(spl_in->basic_in.format) &&
(spl_in->sharpen_policy == SHARPEN_YUV))
return enable_isharp;
else if ((spl_is_video_format(spl_in->basic_in.format) && !fullscreen) &&
(spl_in->sharpen_policy == SHARPEN_RGB_FULLSCREEN_YUV))
return enable_isharp;
else if (!spl_in->is_fullscreen &&
spl_in->sharpen_policy == SHARPEN_FULLSCREEN_ALL)
return enable_isharp;
if ((taps.h_taps == 4 || taps.h_taps == 6) &&
(taps.v_taps == 3 || taps.v_taps == 4 || taps.v_taps == 6))
enable_isharp = true;
return enable_isharp;
}
static void spl_get_taps_non_adaptive_scaler(
struct spl_scratch *spl_scratch,
const struct spl_taps *in_taps,
bool is_horz_subsampled,
bool is_vert_subsampled)
{
bool check_max_downscale = false;
if (in_taps->h_taps == 0) {
if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz) > 1)
spl_scratch->scl_data.taps.h_taps = spl_min(2 * spl_fixpt_ceil(
spl_scratch->scl_data.ratios.horz), 8);
else
spl_scratch->scl_data.taps.h_taps = 4;
} else
spl_scratch->scl_data.taps.h_taps = in_taps->h_taps;
if (in_taps->v_taps == 0) {
if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert) > 1)
spl_scratch->scl_data.taps.v_taps = spl_min(2 * spl_fixpt_ceil(
spl_scratch->scl_data.ratios.vert), 8);
else
spl_scratch->scl_data.taps.v_taps = 4;
} else
spl_scratch->scl_data.taps.v_taps = in_taps->v_taps;
if (in_taps->v_taps_c == 0) {
if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c) > 1)
spl_scratch->scl_data.taps.v_taps_c = spl_min(2 * spl_fixpt_ceil(
spl_scratch->scl_data.ratios.vert_c), 8);
else
spl_scratch->scl_data.taps.v_taps_c = 4;
} else
spl_scratch->scl_data.taps.v_taps_c = in_taps->v_taps_c;
if (in_taps->h_taps_c == 0) {
if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.horz_c) > 1)
spl_scratch->scl_data.taps.h_taps_c = spl_min(2 * spl_fixpt_ceil(
spl_scratch->scl_data.ratios.horz_c), 8);
else
spl_scratch->scl_data.taps.h_taps_c = 4;
} else if ((in_taps->h_taps_c % 2) != 0 && in_taps->h_taps_c != 1)
spl_scratch->scl_data.taps.h_taps_c = in_taps->h_taps_c - 1;
else
spl_scratch->scl_data.taps.h_taps_c = in_taps->h_taps_c;
check_max_downscale = spl_fixpt_le(spl_scratch->scl_data.ratios.horz,
spl_fixpt_from_fraction(6, 1));
SPL_ASSERT(check_max_downscale);
check_max_downscale = spl_fixpt_le(spl_scratch->scl_data.ratios.vert,
spl_fixpt_from_fraction(6, 1));
SPL_ASSERT(check_max_downscale);
check_max_downscale = spl_fixpt_le(spl_scratch->scl_data.ratios.horz_c,
spl_fixpt_from_fraction(6, 1));
SPL_ASSERT(check_max_downscale);
check_max_downscale = spl_fixpt_le(spl_scratch->scl_data.ratios.vert_c,
spl_fixpt_from_fraction(6, 1));
SPL_ASSERT(check_max_downscale);
if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz))
spl_scratch->scl_data.taps.h_taps = 1;
if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert))
spl_scratch->scl_data.taps.v_taps = 1;
if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz_c) && !is_horz_subsampled)
spl_scratch->scl_data.taps.h_taps_c = 1;
if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert_c) && !is_vert_subsampled)
spl_scratch->scl_data.taps.v_taps_c = 1;
}
static bool spl_get_optimal_number_of_taps(
int max_downscale_src_width, struct spl_in *spl_in, struct spl_scratch *spl_scratch,
const struct spl_taps *in_taps, bool *enable_easf_v, bool *enable_easf_h,
bool *enable_isharp)
{
int num_part_y, num_part_c;
unsigned int max_taps_y, max_taps_c;
unsigned int min_taps_y, min_taps_c;
enum lb_memory_config lb_config;
bool skip_easf = false;
bool is_horz_subsampled = spl_is_subsampled_format(spl_in->basic_in.format);
bool is_vert_subsampled = spl_is_yuv420(spl_in->basic_in.format);
if (spl_scratch->scl_data.viewport.width > spl_scratch->scl_data.h_active &&
max_downscale_src_width != 0 &&
spl_scratch->scl_data.viewport.width > max_downscale_src_width) {
spl_get_taps_non_adaptive_scaler(spl_scratch, in_taps, is_horz_subsampled, is_vert_subsampled);
*enable_easf_v = false;
*enable_easf_h = false;
*enable_isharp = false;
return false;
}
if (spl_in->scaling_quality.integer_scaling) {
spl_get_taps_non_adaptive_scaler(spl_scratch, in_taps, is_horz_subsampled, is_vert_subsampled);
*enable_easf_v = false;
*enable_easf_h = false;
*enable_isharp = false;
return true;
}
skip_easf = enable_easf(spl_in, spl_scratch);
if (skip_easf) {
spl_get_taps_non_adaptive_scaler(spl_scratch, in_taps, is_horz_subsampled, is_vert_subsampled);
}
else {
if (spl_is_subsampled_format(spl_in->basic_in.format)) {
spl_scratch->scl_data.taps.h_taps = 6;
spl_scratch->scl_data.taps.v_taps = 6;
spl_scratch->scl_data.taps.h_taps_c = 4;
spl_scratch->scl_data.taps.v_taps_c = 4;
} else {
spl_scratch->scl_data.taps.h_taps = 6;
spl_scratch->scl_data.taps.v_taps = 6;
spl_scratch->scl_data.taps.h_taps_c = 6;
spl_scratch->scl_data.taps.v_taps_c = 6;
}
if (spl_in->override_easf) {
spl_scratch->scl_data.taps.h_taps = (in_taps->h_taps != 0) ? in_taps->h_taps : spl_scratch->scl_data.taps.h_taps;
spl_scratch->scl_data.taps.v_taps = (in_taps->v_taps != 0) ? in_taps->v_taps : spl_scratch->scl_data.taps.v_taps;
spl_scratch->scl_data.taps.h_taps_c = (in_taps->h_taps_c != 0) ? in_taps->h_taps_c : spl_scratch->scl_data.taps.h_taps_c;
spl_scratch->scl_data.taps.v_taps_c = (in_taps->v_taps_c != 0) ? in_taps->v_taps_c : spl_scratch->scl_data.taps.v_taps_c;
if ((spl_scratch->scl_data.taps.h_taps > 6) || (spl_scratch->scl_data.taps.v_taps > 6))
skip_easf = true;
if ((spl_scratch->scl_data.taps.h_taps > 1) && (spl_scratch->scl_data.taps.h_taps % 2))
spl_scratch->scl_data.taps.h_taps--;
if ((spl_scratch->scl_data.taps.h_taps_c > 1) && (spl_scratch->scl_data.taps.h_taps_c % 2))
spl_scratch->scl_data.taps.h_taps_c--;
}
}
min_taps_y = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert);
min_taps_c = spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c);
if (spl_is_yuv420(spl_in->basic_in.format))
lb_config = LB_MEMORY_CONFIG_3;
else
lb_config = LB_MEMORY_CONFIG_0;
spl_in->callbacks.spl_calc_lb_num_partitions(spl_in->basic_out.alpha_en, &spl_scratch->scl_data,
lb_config, &num_part_y, &num_part_c);
if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert) > 2)
if ((spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert) - 2) > num_part_y)
max_taps_y = 0;
else
max_taps_y = num_part_y - (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert) - 2);
else
max_taps_y = num_part_y;
if (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c) > 2)
if ((spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c) - 2) > num_part_c)
max_taps_c = 0;
else
max_taps_c = num_part_c - (spl_fixpt_ceil(spl_scratch->scl_data.ratios.vert_c) - 2);
else
max_taps_c = num_part_c;
if (max_taps_y < min_taps_y)
return false;
else if (max_taps_c < min_taps_c)
return false;
if (spl_scratch->scl_data.taps.v_taps > max_taps_y)
spl_scratch->scl_data.taps.v_taps = max_taps_y;
if (spl_scratch->scl_data.taps.v_taps_c > max_taps_c)
spl_scratch->scl_data.taps.v_taps_c = max_taps_c;
if (!skip_easf) {
if (spl_scratch->scl_data.taps.v_taps == 5)
spl_scratch->scl_data.taps.v_taps = 4;
if (spl_scratch->scl_data.taps.v_taps_c == 5)
spl_scratch->scl_data.taps.v_taps_c = 4;
if (spl_scratch->scl_data.taps.h_taps == 5)
spl_scratch->scl_data.taps.h_taps = 4;
if (spl_scratch->scl_data.taps.h_taps_c == 5)
spl_scratch->scl_data.taps.h_taps_c = 4;
if (spl_is_video_format(spl_in->basic_in.format)) {
if (spl_scratch->scl_data.taps.h_taps <= 4) {
*enable_easf_v = false;
*enable_easf_h = false;
} else if (spl_scratch->scl_data.taps.v_taps <= 3) {
*enable_easf_v = false;
*enable_easf_h = true;
} else {
*enable_easf_v = true;
*enable_easf_h = true;
}
SPL_ASSERT((spl_scratch->scl_data.taps.v_taps > 1) &&
(spl_scratch->scl_data.taps.v_taps_c > 1));
} else {
if (spl_scratch->scl_data.taps.h_taps <= 3) {
*enable_easf_v = false;
*enable_easf_h = false;
} else if (spl_scratch->scl_data.taps.v_taps < 3) {
*enable_easf_v = false;
*enable_easf_h = true;
} else {
*enable_easf_v = true;
*enable_easf_h = true;
}
SPL_ASSERT(spl_scratch->scl_data.taps.v_taps > 1);
}
} else {
*enable_easf_v = false;
*enable_easf_h = false;
}
*enable_isharp = spl_get_isharp_en(spl_in, spl_scratch);
if (!*enable_isharp && !spl_in->basic_out.always_scale) {
if ((IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz)) &&
(IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert))) {
spl_scratch->scl_data.taps.h_taps = 1;
spl_scratch->scl_data.taps.v_taps = 1;
if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz_c) && !is_horz_subsampled)
spl_scratch->scl_data.taps.h_taps_c = 1;
if (IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert_c) && !is_vert_subsampled)
spl_scratch->scl_data.taps.v_taps_c = 1;
*enable_easf_v = false;
*enable_easf_h = false;
} else {
if ((!*enable_easf_h) &&
(IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz)))
spl_scratch->scl_data.taps.h_taps = 1;
if ((!*enable_easf_v) &&
(IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert)))
spl_scratch->scl_data.taps.v_taps = 1;
if ((!*enable_easf_h) && !is_horz_subsampled &&
(IDENTITY_RATIO(spl_scratch->scl_data.ratios.horz_c)))
spl_scratch->scl_data.taps.h_taps_c = 1;
if ((!*enable_easf_v) && !is_vert_subsampled &&
(IDENTITY_RATIO(spl_scratch->scl_data.ratios.vert_c)))
spl_scratch->scl_data.taps.v_taps_c = 1;
}
}
return true;
}
static void spl_set_black_color_data(enum spl_pixel_format format,
struct scl_black_color *scl_black_color)
{
bool ycbcr = spl_is_video_format(format);
if (ycbcr) {
scl_black_color->offset_rgb_y = BLACK_OFFSET_RGB_Y;
scl_black_color->offset_rgb_cbcr = BLACK_OFFSET_CBCR;
} else {
scl_black_color->offset_rgb_y = 0x0;
scl_black_color->offset_rgb_cbcr = 0x0;
}
}
static void spl_set_manual_ratio_init_data(struct dscl_prog_data *dscl_prog_data,
const struct spl_scaler_data *scl_data)
{
struct spl_fixed31_32 bot;
dscl_prog_data->ratios.h_scale_ratio = spl_fixpt_u3d19(
scl_data->ratios.horz) << 5;
dscl_prog_data->ratios.v_scale_ratio = spl_fixpt_u3d19(
scl_data->ratios.vert) << 5;
dscl_prog_data->ratios.h_scale_ratio_c = spl_fixpt_u3d19(
scl_data->ratios.horz_c) << 5;
dscl_prog_data->ratios.v_scale_ratio_c = spl_fixpt_u3d19(
scl_data->ratios.vert_c) << 5;
dscl_prog_data->init.h_filter_init_frac =
spl_fixpt_u0d19(scl_data->inits.h) << 5;
dscl_prog_data->init.h_filter_init_int =
spl_fixpt_floor(scl_data->inits.h);
dscl_prog_data->init.h_filter_init_frac_c =
spl_fixpt_u0d19(scl_data->inits.h_c) << 5;
dscl_prog_data->init.h_filter_init_int_c =
spl_fixpt_floor(scl_data->inits.h_c);
dscl_prog_data->init.v_filter_init_frac =
spl_fixpt_u0d19(scl_data->inits.v) << 5;
dscl_prog_data->init.v_filter_init_int =
spl_fixpt_floor(scl_data->inits.v);
dscl_prog_data->init.v_filter_init_frac_c =
spl_fixpt_u0d19(scl_data->inits.v_c) << 5;
dscl_prog_data->init.v_filter_init_int_c =
spl_fixpt_floor(scl_data->inits.v_c);
bot = spl_fixpt_add(scl_data->inits.v, scl_data->ratios.vert);
dscl_prog_data->init.v_filter_init_bot_frac = spl_fixpt_u0d19(bot) << 5;
dscl_prog_data->init.v_filter_init_bot_int = spl_fixpt_floor(bot);
bot = spl_fixpt_add(scl_data->inits.v_c, scl_data->ratios.vert_c);
dscl_prog_data->init.v_filter_init_bot_frac_c = spl_fixpt_u0d19(bot) << 5;
dscl_prog_data->init.v_filter_init_bot_int_c = spl_fixpt_floor(bot);
}
static void spl_set_taps_data(struct dscl_prog_data *dscl_prog_data,
const struct spl_scaler_data *scl_data)
{
dscl_prog_data->taps.v_taps = scl_data->taps.v_taps - 1;
dscl_prog_data->taps.h_taps = scl_data->taps.h_taps - 1;
dscl_prog_data->taps.v_taps_c = scl_data->taps.v_taps_c - 1;
dscl_prog_data->taps.h_taps_c = scl_data->taps.h_taps_c - 1;
}
static void spl_set_dscl_prog_data(struct spl_in *spl_in, struct spl_scratch *spl_scratch,
struct spl_out *spl_out, bool enable_easf_v, bool enable_easf_h, bool enable_isharp)
{
struct dscl_prog_data *dscl_prog_data = spl_out->dscl_prog_data;
const struct spl_scaler_data *data = &spl_scratch->scl_data;
struct scl_black_color *scl_black_color = &dscl_prog_data->scl_black_color;
bool enable_easf = enable_easf_v || enable_easf_h;
dscl_prog_data->recout = spl_scratch->scl_data.recout;
dscl_prog_data->mpc_size.width = spl_scratch->scl_data.h_active;
dscl_prog_data->mpc_size.height = spl_scratch->scl_data.v_active;
dscl_prog_data->dscl_mode = spl_get_dscl_mode(spl_in, data, enable_isharp,
enable_easf);
spl_set_black_color_data(spl_in->basic_in.format, scl_black_color);
spl_set_manual_ratio_init_data(dscl_prog_data, data);
spl_set_taps_data(dscl_prog_data, data);
dscl_prog_data->viewport = spl_scratch->scl_data.viewport;
dscl_prog_data->viewport_c = spl_scratch->scl_data.viewport_c;
SPL_NAMESPACE(spl_set_filters_data(dscl_prog_data, data, enable_easf_v, enable_easf_h));
}
static void spl_calculate_c0_c3_hdr(struct dscl_prog_data *dscl_prog_data, uint32_t sdr_white_level_nits)
{
struct spl_fixed31_32 hdr_mult, c0_mult, c1_mult, c2_mult;
struct spl_fixed31_32 c0_calc, c1_calc, c2_calc;
struct spl_custom_float_format fmt;
uint32_t hdr_multx100_int;
if ((sdr_white_level_nits >= 80) && (sdr_white_level_nits <= 480))
hdr_multx100_int = sdr_white_level_nits * 100 / 80;
else
hdr_multx100_int = 100;
hdr_mult = spl_fixpt_from_fraction((long long)hdr_multx100_int, 100LL);
c0_mult = spl_fixpt_from_fraction(2126LL, 10000LL);
c1_mult = spl_fixpt_from_fraction(7152LL, 10000LL);
c2_mult = spl_fixpt_from_fraction(722LL, 10000LL);
c0_calc = spl_fixpt_mul(hdr_mult, spl_fixpt_mul(c0_mult,
spl_fixpt_from_fraction(16384LL, 125LL)));
c1_calc = spl_fixpt_mul(hdr_mult, spl_fixpt_mul(c1_mult,
spl_fixpt_from_fraction(16384LL, 125LL)));
c2_calc = spl_fixpt_mul(hdr_mult, spl_fixpt_mul(c2_mult,
spl_fixpt_from_fraction(16384LL, 125LL)));
fmt.exponenta_bits = 5;
fmt.mantissa_bits = 10;
fmt.sign = true;
spl_convert_to_custom_float_format(c0_calc, &fmt,
&dscl_prog_data->easf_matrix_c0);
spl_convert_to_custom_float_format(c1_calc, &fmt,
&dscl_prog_data->easf_matrix_c1);
spl_convert_to_custom_float_format(c2_calc, &fmt,
&dscl_prog_data->easf_matrix_c2);
dscl_prog_data->easf_matrix_c3 = 0x0;
}
static void spl_set_easf_data(struct spl_scratch *spl_scratch, struct spl_out *spl_out, bool enable_easf_v,
bool enable_easf_h, enum linear_light_scaling lls_pref,
enum spl_pixel_format format, enum system_setup setup,
uint32_t sdr_white_level_nits)
{
struct dscl_prog_data *dscl_prog_data = spl_out->dscl_prog_data;
if (enable_easf_v) {
dscl_prog_data->easf_v_en = true;
dscl_prog_data->easf_v_ring = 0;
dscl_prog_data->easf_v_sharp_factor = 1;
dscl_prog_data->easf_v_bf1_en = 1;
dscl_prog_data->easf_v_bf2_mode = 0xF;
dscl_prog_data->easf_v_bf3_mode = SPL_NAMESPACE(spl_get_v_bf3_mode(
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_3tap_dntilt_uptilt =
SPL_NAMESPACE(spl_get_3tap_dntilt_uptilt_offset(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_3tap_uptilt_max =
SPL_NAMESPACE(spl_get_3tap_uptilt_maxval(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_3tap_dntilt_slope =
SPL_NAMESPACE(spl_get_3tap_dntilt_slope(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_3tap_uptilt1_slope =
SPL_NAMESPACE(spl_get_3tap_uptilt1_slope(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_3tap_uptilt2_slope =
SPL_NAMESPACE(spl_get_3tap_uptilt2_slope(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_3tap_uptilt2_offset =
SPL_NAMESPACE(spl_get_3tap_uptilt2_offset(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_eventap_reduceg1 =
SPL_NAMESPACE(spl_get_reducer_gain4(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_eventap_reduceg2 =
SPL_NAMESPACE(spl_get_reducer_gain6(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_eventap_gain1 =
SPL_NAMESPACE(spl_get_gainRing4(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_ringest_eventap_gain2 =
SPL_NAMESPACE(spl_get_gainRing6(spl_scratch->scl_data.taps.v_taps,
spl_scratch->scl_data.recip_ratios.vert));
dscl_prog_data->easf_v_bf_maxa = 63;
dscl_prog_data->easf_v_bf_maxb = 63;
dscl_prog_data->easf_v_bf_mina = 0;
dscl_prog_data->easf_v_bf_minb = 0;
if (lls_pref == LLS_PREF_YES) {
dscl_prog_data->easf_v_bf2_flat1_gain = 4;
dscl_prog_data->easf_v_bf2_flat2_gain = 8;
dscl_prog_data->easf_v_bf2_roc_gain = 4;
dscl_prog_data->easf_v_bf1_pwl_in_seg0 = 0x600;
dscl_prog_data->easf_v_bf1_pwl_base_seg0 = 0;
dscl_prog_data->easf_v_bf1_pwl_slope_seg0 = 3;
dscl_prog_data->easf_v_bf1_pwl_in_seg1 = 0x7EC;
dscl_prog_data->easf_v_bf1_pwl_base_seg1 = 12;
dscl_prog_data->easf_v_bf1_pwl_slope_seg1 = 326;
dscl_prog_data->easf_v_bf1_pwl_in_seg2 = 0;
dscl_prog_data->easf_v_bf1_pwl_base_seg2 = 63;
dscl_prog_data->easf_v_bf1_pwl_slope_seg2 = 0;
dscl_prog_data->easf_v_bf1_pwl_in_seg3 = 16;
dscl_prog_data->easf_v_bf1_pwl_base_seg3 = 63;
dscl_prog_data->easf_v_bf1_pwl_slope_seg3 = 0x7C8;
dscl_prog_data->easf_v_bf1_pwl_in_seg4 = 32;
dscl_prog_data->easf_v_bf1_pwl_base_seg4 = 56;
dscl_prog_data->easf_v_bf1_pwl_slope_seg4 = 0x7D0;
dscl_prog_data->easf_v_bf1_pwl_in_seg5 = 48;
dscl_prog_data->easf_v_bf1_pwl_base_seg5 = 50;
dscl_prog_data->easf_v_bf1_pwl_slope_seg5 = 0x710;
dscl_prog_data->easf_v_bf1_pwl_in_seg6 = 64;
dscl_prog_data->easf_v_bf1_pwl_base_seg6 = 20;
dscl_prog_data->easf_v_bf1_pwl_slope_seg6 = 0x760;
dscl_prog_data->easf_v_bf1_pwl_in_seg7 = 80;
dscl_prog_data->easf_v_bf1_pwl_base_seg7 = 0;
dscl_prog_data->easf_v_bf3_pwl_in_set0 = 0x000;
dscl_prog_data->easf_v_bf3_pwl_base_set0 = 63;
dscl_prog_data->easf_v_bf3_pwl_slope_set0 = 0x12C5;
dscl_prog_data->easf_v_bf3_pwl_in_set1 =
0x0B37;
dscl_prog_data->easf_v_bf3_pwl_base_set1 = 62;
dscl_prog_data->easf_v_bf3_pwl_slope_set1 =
0x13B8;
dscl_prog_data->easf_v_bf3_pwl_in_set2 =
0x0BB7;
dscl_prog_data->easf_v_bf3_pwl_base_set2 = 20;
dscl_prog_data->easf_v_bf3_pwl_slope_set2 =
0x1356;
dscl_prog_data->easf_v_bf3_pwl_in_set3 =
0x0BF7;
dscl_prog_data->easf_v_bf3_pwl_base_set3 = 0;
dscl_prog_data->easf_v_bf3_pwl_slope_set3 =
0x136B;
dscl_prog_data->easf_v_bf3_pwl_in_set4 =
0x0C37;
dscl_prog_data->easf_v_bf3_pwl_base_set4 = 0x4E;
dscl_prog_data->easf_v_bf3_pwl_slope_set4 =
0x1200;
dscl_prog_data->easf_v_bf3_pwl_in_set5 =
0x0CF7;
dscl_prog_data->easf_v_bf3_pwl_base_set5 = 0x41;
} else {
dscl_prog_data->easf_v_bf2_flat1_gain = 13;
dscl_prog_data->easf_v_bf2_flat2_gain = 15;
dscl_prog_data->easf_v_bf2_roc_gain = 14;
dscl_prog_data->easf_v_bf1_pwl_in_seg0 = 0x440;
dscl_prog_data->easf_v_bf1_pwl_base_seg0 = 0;
dscl_prog_data->easf_v_bf1_pwl_slope_seg0 = 2;
dscl_prog_data->easf_v_bf1_pwl_in_seg1 = 0x7C4;
dscl_prog_data->easf_v_bf1_pwl_base_seg1 = 12;
dscl_prog_data->easf_v_bf1_pwl_slope_seg1 = 109;
dscl_prog_data->easf_v_bf1_pwl_in_seg2 = 0;
dscl_prog_data->easf_v_bf1_pwl_base_seg2 = 63;
dscl_prog_data->easf_v_bf1_pwl_slope_seg2 = 0;
dscl_prog_data->easf_v_bf1_pwl_in_seg3 = 48;
dscl_prog_data->easf_v_bf1_pwl_base_seg3 = 63;
dscl_prog_data->easf_v_bf1_pwl_slope_seg3 = 0x7ED;
dscl_prog_data->easf_v_bf1_pwl_in_seg4 = 96;
dscl_prog_data->easf_v_bf1_pwl_base_seg4 = 56;
dscl_prog_data->easf_v_bf1_pwl_slope_seg4 = 0x7F0;
dscl_prog_data->easf_v_bf1_pwl_in_seg5 = 144;
dscl_prog_data->easf_v_bf1_pwl_base_seg5 = 50;
dscl_prog_data->easf_v_bf1_pwl_slope_seg5 = 0x7B0;
dscl_prog_data->easf_v_bf1_pwl_in_seg6 = 192;
dscl_prog_data->easf_v_bf1_pwl_base_seg6 = 20;
dscl_prog_data->easf_v_bf1_pwl_slope_seg6 = 0x7CB;
dscl_prog_data->easf_v_bf1_pwl_in_seg7 = 240;
dscl_prog_data->easf_v_bf1_pwl_base_seg7 = 0;
dscl_prog_data->easf_v_bf3_pwl_in_set0 = 0x000;
dscl_prog_data->easf_v_bf3_pwl_base_set0 = 63;
dscl_prog_data->easf_v_bf3_pwl_slope_set0 = 0x0000;
dscl_prog_data->easf_v_bf3_pwl_in_set1 =
0x06C0;
dscl_prog_data->easf_v_bf3_pwl_base_set1 = 63;
dscl_prog_data->easf_v_bf3_pwl_slope_set1 = 0x1896;
dscl_prog_data->easf_v_bf3_pwl_in_set2 =
0x0700;
dscl_prog_data->easf_v_bf3_pwl_base_set2 = 20;
dscl_prog_data->easf_v_bf3_pwl_slope_set2 = 0x1810;
dscl_prog_data->easf_v_bf3_pwl_in_set3 =
0x0740;
dscl_prog_data->easf_v_bf3_pwl_base_set3 = 0;
dscl_prog_data->easf_v_bf3_pwl_slope_set3 =
0x1878;
dscl_prog_data->easf_v_bf3_pwl_in_set4 =
0x0761;
dscl_prog_data->easf_v_bf3_pwl_base_set4 = 0x44;
dscl_prog_data->easf_v_bf3_pwl_slope_set4 = 0x1760;
dscl_prog_data->easf_v_bf3_pwl_in_set5 =
0x0780;
dscl_prog_data->easf_v_bf3_pwl_base_set5 = 0x41;
}
} else
dscl_prog_data->easf_v_en = false;
if (enable_easf_h) {
dscl_prog_data->easf_h_en = true;
dscl_prog_data->easf_h_ring = 0;
dscl_prog_data->easf_h_sharp_factor = 1;
dscl_prog_data->easf_h_bf1_en =
1;
dscl_prog_data->easf_h_bf2_mode =
0xF;
dscl_prog_data->easf_h_bf3_mode = SPL_NAMESPACE(spl_get_h_bf3_mode(
spl_scratch->scl_data.recip_ratios.horz));
dscl_prog_data->easf_h_ringest_eventap_reduceg1 =
SPL_NAMESPACE(spl_get_reducer_gain4(spl_scratch->scl_data.taps.h_taps,
spl_scratch->scl_data.recip_ratios.horz));
dscl_prog_data->easf_h_ringest_eventap_reduceg2 =
SPL_NAMESPACE(spl_get_reducer_gain6(spl_scratch->scl_data.taps.h_taps,
spl_scratch->scl_data.recip_ratios.horz));
dscl_prog_data->easf_h_ringest_eventap_gain1 =
SPL_NAMESPACE(spl_get_gainRing4(spl_scratch->scl_data.taps.h_taps,
spl_scratch->scl_data.recip_ratios.horz));
dscl_prog_data->easf_h_ringest_eventap_gain2 =
SPL_NAMESPACE(spl_get_gainRing6(spl_scratch->scl_data.taps.h_taps,
spl_scratch->scl_data.recip_ratios.horz));
dscl_prog_data->easf_h_bf_maxa = 63;
dscl_prog_data->easf_h_bf_maxb = 63;
dscl_prog_data->easf_h_bf_mina = 0;
dscl_prog_data->easf_h_bf_minb = 0;
if (lls_pref == LLS_PREF_YES) {
dscl_prog_data->easf_h_bf2_flat1_gain = 4;
dscl_prog_data->easf_h_bf2_flat2_gain = 8;
dscl_prog_data->easf_h_bf2_roc_gain = 4;
dscl_prog_data->easf_h_bf1_pwl_in_seg0 = 0x600;
dscl_prog_data->easf_h_bf1_pwl_base_seg0 = 0;
dscl_prog_data->easf_h_bf1_pwl_slope_seg0 = 3;
dscl_prog_data->easf_h_bf1_pwl_in_seg1 = 0x7EC;
dscl_prog_data->easf_h_bf1_pwl_base_seg1 = 12;
dscl_prog_data->easf_h_bf1_pwl_slope_seg1 = 326;
dscl_prog_data->easf_h_bf1_pwl_in_seg2 = 0;
dscl_prog_data->easf_h_bf1_pwl_base_seg2 = 63;
dscl_prog_data->easf_h_bf1_pwl_slope_seg2 = 0;
dscl_prog_data->easf_h_bf1_pwl_in_seg3 = 16;
dscl_prog_data->easf_h_bf1_pwl_base_seg3 = 63;
dscl_prog_data->easf_h_bf1_pwl_slope_seg3 = 0x7C8;
dscl_prog_data->easf_h_bf1_pwl_in_seg4 = 32;
dscl_prog_data->easf_h_bf1_pwl_base_seg4 = 56;
dscl_prog_data->easf_h_bf1_pwl_slope_seg4 = 0x7D0;
dscl_prog_data->easf_h_bf1_pwl_in_seg5 = 48;
dscl_prog_data->easf_h_bf1_pwl_base_seg5 = 50;
dscl_prog_data->easf_h_bf1_pwl_slope_seg5 = 0x710;
dscl_prog_data->easf_h_bf1_pwl_in_seg6 = 64;
dscl_prog_data->easf_h_bf1_pwl_base_seg6 = 20;
dscl_prog_data->easf_h_bf1_pwl_slope_seg6 = 0x760;
dscl_prog_data->easf_h_bf1_pwl_in_seg7 = 80;
dscl_prog_data->easf_h_bf1_pwl_base_seg7 = 0;
dscl_prog_data->easf_h_bf3_pwl_in_set0 = 0x000;
dscl_prog_data->easf_h_bf3_pwl_base_set0 = 63;
dscl_prog_data->easf_h_bf3_pwl_slope_set0 = 0x12C5;
dscl_prog_data->easf_h_bf3_pwl_in_set1 =
0x0B37;
dscl_prog_data->easf_h_bf3_pwl_base_set1 = 62;
dscl_prog_data->easf_h_bf3_pwl_slope_set1 = 0x13B8;
dscl_prog_data->easf_h_bf3_pwl_in_set2 =
0x0BB7;
dscl_prog_data->easf_h_bf3_pwl_base_set2 = 20;
dscl_prog_data->easf_h_bf3_pwl_slope_set2 = 0x1356;
dscl_prog_data->easf_h_bf3_pwl_in_set3 =
0x0BF7;
dscl_prog_data->easf_h_bf3_pwl_base_set3 = 0;
dscl_prog_data->easf_h_bf3_pwl_slope_set3 = 0x136B;
dscl_prog_data->easf_h_bf3_pwl_in_set4 =
0x0C37;
dscl_prog_data->easf_h_bf3_pwl_base_set4 = 0x4E;
dscl_prog_data->easf_h_bf3_pwl_slope_set4 = 0x1200;
dscl_prog_data->easf_h_bf3_pwl_in_set5 =
0x0CF7;
dscl_prog_data->easf_h_bf3_pwl_base_set5 = 0x41;
} else {
dscl_prog_data->easf_h_bf2_flat1_gain = 13;
dscl_prog_data->easf_h_bf2_flat2_gain = 15;
dscl_prog_data->easf_h_bf2_roc_gain = 14;
dscl_prog_data->easf_h_bf1_pwl_in_seg0 = 0x440;
dscl_prog_data->easf_h_bf1_pwl_base_seg0 = 0;
dscl_prog_data->easf_h_bf1_pwl_slope_seg0 = 2;
dscl_prog_data->easf_h_bf1_pwl_in_seg1 = 0x7C4;
dscl_prog_data->easf_h_bf1_pwl_base_seg1 = 12;
dscl_prog_data->easf_h_bf1_pwl_slope_seg1 = 109;
dscl_prog_data->easf_h_bf1_pwl_in_seg2 = 0;
dscl_prog_data->easf_h_bf1_pwl_base_seg2 = 63;
dscl_prog_data->easf_h_bf1_pwl_slope_seg2 = 0;
dscl_prog_data->easf_h_bf1_pwl_in_seg3 = 48;
dscl_prog_data->easf_h_bf1_pwl_base_seg3 = 63;
dscl_prog_data->easf_h_bf1_pwl_slope_seg3 = 0x7ED;
dscl_prog_data->easf_h_bf1_pwl_in_seg4 = 96;
dscl_prog_data->easf_h_bf1_pwl_base_seg4 = 56;
dscl_prog_data->easf_h_bf1_pwl_slope_seg4 = 0x7F0;
dscl_prog_data->easf_h_bf1_pwl_in_seg5 = 144;
dscl_prog_data->easf_h_bf1_pwl_base_seg5 = 50;
dscl_prog_data->easf_h_bf1_pwl_slope_seg5 = 0x7B0;
dscl_prog_data->easf_h_bf1_pwl_in_seg6 = 192;
dscl_prog_data->easf_h_bf1_pwl_base_seg6 = 20;
dscl_prog_data->easf_h_bf1_pwl_slope_seg6 = 0x7CB;
dscl_prog_data->easf_h_bf1_pwl_in_seg7 = 240;
dscl_prog_data->easf_h_bf1_pwl_base_seg7 = 0;
dscl_prog_data->easf_h_bf3_pwl_in_set0 = 0x000;
dscl_prog_data->easf_h_bf3_pwl_base_set0 = 63;
dscl_prog_data->easf_h_bf3_pwl_slope_set0 = 0x0000;
dscl_prog_data->easf_h_bf3_pwl_in_set1 =
0x06C0;
dscl_prog_data->easf_h_bf3_pwl_base_set1 = 63;
dscl_prog_data->easf_h_bf3_pwl_slope_set1 = 0x1896;
dscl_prog_data->easf_h_bf3_pwl_in_set2 =
0x0700;
dscl_prog_data->easf_h_bf3_pwl_base_set2 = 20;
dscl_prog_data->easf_h_bf3_pwl_slope_set2 = 0x1810;
dscl_prog_data->easf_h_bf3_pwl_in_set3 =
0x0740;
dscl_prog_data->easf_h_bf3_pwl_base_set3 = 0;
dscl_prog_data->easf_h_bf3_pwl_slope_set3 = 0x1878;
dscl_prog_data->easf_h_bf3_pwl_in_set4 =
0x0761;
dscl_prog_data->easf_h_bf3_pwl_base_set4 = 0x44;
dscl_prog_data->easf_h_bf3_pwl_slope_set4 = 0x1760;
dscl_prog_data->easf_h_bf3_pwl_in_set5 =
0x0780;
dscl_prog_data->easf_h_bf3_pwl_base_set5 = 0x41;
}
} else
dscl_prog_data->easf_h_en = false;
if (lls_pref == LLS_PREF_YES) {
dscl_prog_data->easf_ltonl_en = 1;
if ((setup == HDR_L) && (spl_is_rgb8(format))) {
spl_calculate_c0_c3_hdr(dscl_prog_data, sdr_white_level_nits);
} else {
dscl_prog_data->easf_matrix_c0 =
0x4EF7;
dscl_prog_data->easf_matrix_c1 =
0x55DC;
dscl_prog_data->easf_matrix_c2 =
0x48BB;
dscl_prog_data->easf_matrix_c3 =
0x0;
}
} else {
dscl_prog_data->easf_ltonl_en = 0;
dscl_prog_data->easf_matrix_c0 =
0x3434;
dscl_prog_data->easf_matrix_c1 =
0x396D;
dscl_prog_data->easf_matrix_c2 =
0x2B97;
dscl_prog_data->easf_matrix_c3 =
0x0;
}
if (spl_is_subsampled_format(format)) {
dscl_prog_data->easf_matrix_mode = 1;
dscl_prog_data->easf_v_bf3_mode = 0;
dscl_prog_data->easf_h_bf3_mode = 0;
} else
dscl_prog_data->easf_matrix_mode = 0;
}
static void spl_set_isharp_noise_det_mode(struct dscl_prog_data *dscl_prog_data,
const struct spl_scaler_data *data)
{
if (data->taps.v_taps == 6)
dscl_prog_data->isharp_noise_det.mode = 3;
else if (data->taps.v_taps == 4)
dscl_prog_data->isharp_noise_det.mode = 1;
else if (data->taps.v_taps == 3)
dscl_prog_data->isharp_noise_det.mode = 0;
};
static void spl_set_isharp_data(struct dscl_prog_data *dscl_prog_data,
struct adaptive_sharpness adp_sharpness, bool enable_isharp,
enum linear_light_scaling lls_pref, enum spl_pixel_format format,
const struct spl_scaler_data *data, struct spl_fixed31_32 ratio,
enum system_setup setup, enum scale_to_sharpness_policy scale_to_sharpness_policy)
{
(void)format;
if (!enable_isharp) {
dscl_prog_data->isharp_en = 0;
return;
}
SPL_NAMESPACE(spl_build_isharp_1dlut_from_reference_curve(ratio, setup, adp_sharpness,
scale_to_sharpness_policy));
memcpy(dscl_prog_data->isharp_delta, SPL_NAMESPACE(spl_get_pregen_filter_isharp_1D_lut(setup)),
sizeof(uint32_t) * ISHARP_LUT_TABLE_SIZE);
dscl_prog_data->sharpness_level = adp_sharpness.sharpness_level;
dscl_prog_data->isharp_en = 1;
if (data->taps.h_taps == 6) {
dscl_prog_data->isharp_noise_det.enable = 1;
spl_set_isharp_noise_det_mode(dscl_prog_data, data);
} else
dscl_prog_data->isharp_noise_det.enable = 0;
dscl_prog_data->isharp_noise_det.uthreshold = 24;
dscl_prog_data->isharp_noise_det.dthreshold = 4;
dscl_prog_data->isharp_noise_det.pwl_start_in = 3;
dscl_prog_data->isharp_noise_det.pwl_end_in = 13;
dscl_prog_data->isharp_noise_det.pwl_slope = 1623;
if (lls_pref == LLS_PREF_NO)
dscl_prog_data->isharp_fmt.mode = 1;
else
dscl_prog_data->isharp_fmt.mode = 0;
dscl_prog_data->isharp_fmt.norm = 0x3C00;
dscl_prog_data->isharp_lba.mode = 0;
if (setup == SDR_L) {
dscl_prog_data->isharp_lba.in_seg[0] = 0;
dscl_prog_data->isharp_lba.base_seg[0] = 0;
dscl_prog_data->isharp_lba.slope_seg[0] = 62;
dscl_prog_data->isharp_lba.in_seg[1] = 130;
dscl_prog_data->isharp_lba.base_seg[1] = 63;
dscl_prog_data->isharp_lba.slope_seg[1] = 0;
dscl_prog_data->isharp_lba.in_seg[2] = 450;
dscl_prog_data->isharp_lba.base_seg[2] = 63;
dscl_prog_data->isharp_lba.slope_seg[2] = 0x18D;
dscl_prog_data->isharp_lba.in_seg[3] = 520;
dscl_prog_data->isharp_lba.base_seg[3] = 0;
dscl_prog_data->isharp_lba.slope_seg[3] = 0;
dscl_prog_data->isharp_lba.in_seg[4] = 520;
dscl_prog_data->isharp_lba.base_seg[4] = 0;
dscl_prog_data->isharp_lba.slope_seg[4] = 0;
dscl_prog_data->isharp_lba.in_seg[5] = 520;
dscl_prog_data->isharp_lba.base_seg[5] = 0;
} else if (setup == HDR_L) {
dscl_prog_data->isharp_lba.in_seg[0] = 0;
dscl_prog_data->isharp_lba.base_seg[0] = 0;
dscl_prog_data->isharp_lba.slope_seg[0] = 32;
dscl_prog_data->isharp_lba.in_seg[1] = 254;
dscl_prog_data->isharp_lba.base_seg[1] = 63;
dscl_prog_data->isharp_lba.slope_seg[1] = 0;
dscl_prog_data->isharp_lba.in_seg[2] = 559;
dscl_prog_data->isharp_lba.base_seg[2] = 63;
dscl_prog_data->isharp_lba.slope_seg[2] = 0x10C;
dscl_prog_data->isharp_lba.in_seg[3] = 592;
dscl_prog_data->isharp_lba.base_seg[3] = 0;
dscl_prog_data->isharp_lba.slope_seg[3] = 0;
dscl_prog_data->isharp_lba.in_seg[4] = 1023;
dscl_prog_data->isharp_lba.base_seg[4] = 0;
dscl_prog_data->isharp_lba.slope_seg[4] = 0;
dscl_prog_data->isharp_lba.in_seg[5] = 1023;
dscl_prog_data->isharp_lba.base_seg[5] = 0;
} else {
dscl_prog_data->isharp_lba.in_seg[0] = 0;
dscl_prog_data->isharp_lba.base_seg[0] = 0;
dscl_prog_data->isharp_lba.slope_seg[0] = 40;
dscl_prog_data->isharp_lba.in_seg[1] = 204;
dscl_prog_data->isharp_lba.base_seg[1] = 63;
dscl_prog_data->isharp_lba.slope_seg[1] = 0;
dscl_prog_data->isharp_lba.in_seg[2] = 818;
dscl_prog_data->isharp_lba.base_seg[2] = 63;
dscl_prog_data->isharp_lba.slope_seg[2] = 0x1D9;
dscl_prog_data->isharp_lba.in_seg[3] = 1023;
dscl_prog_data->isharp_lba.base_seg[3] = 0;
dscl_prog_data->isharp_lba.slope_seg[3] = 0;
dscl_prog_data->isharp_lba.in_seg[4] = 1023;
dscl_prog_data->isharp_lba.base_seg[4] = 0;
dscl_prog_data->isharp_lba.slope_seg[4] = 0;
dscl_prog_data->isharp_lba.in_seg[5] = 1023;
dscl_prog_data->isharp_lba.base_seg[5] = 0;
}
if (lls_pref == LLS_PREF_YES) {
dscl_prog_data->isharp_nldelta_sclip.enable_p = 0;
dscl_prog_data->isharp_nldelta_sclip.pivot_p = 0;
dscl_prog_data->isharp_nldelta_sclip.slope_p = 0;
dscl_prog_data->isharp_nldelta_sclip.enable_n = 1;
dscl_prog_data->isharp_nldelta_sclip.pivot_n = 71;
dscl_prog_data->isharp_nldelta_sclip.slope_n = 16;
} else {
dscl_prog_data->isharp_nldelta_sclip.enable_p = 1;
dscl_prog_data->isharp_nldelta_sclip.pivot_p = 70;
dscl_prog_data->isharp_nldelta_sclip.slope_p = 24;
dscl_prog_data->isharp_nldelta_sclip.enable_n = 1;
dscl_prog_data->isharp_nldelta_sclip.pivot_n = 70;
dscl_prog_data->isharp_nldelta_sclip.slope_n = 24;
}
SPL_NAMESPACE(spl_set_blur_scale_data(dscl_prog_data, data));
}
static void determine_upsp_values(struct spl_in *spl_in, struct dscl_prog_data *dscl_prog_data)
{
dscl_prog_data->upsp_mode = spl_in->upsp_mode;
if (dscl_prog_data->upsp_mode == UPSP_BYPASS) {
dscl_prog_data->upsp_v_num_taps = UPSP_2_TAPS;
dscl_prog_data->upsp_h_num_taps = UPSP_2_TAPS;
dscl_prog_data->upsp_boundary_mode = UPSP_BOUNDARY_EDGE;
dscl_prog_data->upsp_v_init_int = 0x0;
dscl_prog_data->upsp_v_init_frac = 0x0;
dscl_prog_data->upsp_v_coef_tap0_p0 = 0x0;
dscl_prog_data->upsp_v_coef_tap1_p0 = 0x0;
dscl_prog_data->upsp_v_coef_tap2_p0 = 0x0;
dscl_prog_data->upsp_v_coef_tap3_p0 = 0x0;
dscl_prog_data->upsp_v_coef_tap0_p1 = 0x0;
dscl_prog_data->upsp_v_coef_tap1_p1 = 0x0;
dscl_prog_data->upsp_v_coef_tap2_p1 = 0x0;
dscl_prog_data->upsp_v_coef_tap3_p1 = 0x0;
dscl_prog_data->upsp_h_init_int = 0x0;
dscl_prog_data->upsp_h_init_frac = 0x0;
dscl_prog_data->upsp_h_coef_tap0_p0 = 0x0;
dscl_prog_data->upsp_h_coef_tap1_p0 = 0x0;
dscl_prog_data->upsp_h_coef_tap2_p0 = 0x0;
dscl_prog_data->upsp_h_coef_tap3_p0 = 0x0;
dscl_prog_data->upsp_h_coef_tap0_p1 = 0x0;
dscl_prog_data->upsp_h_coef_tap1_p1 = 0x0;
dscl_prog_data->upsp_h_coef_tap2_p1 = 0x0;
dscl_prog_data->upsp_h_coef_tap3_p1 = 0x0;
dscl_prog_data->upsp_clamp_max = 0x0;
dscl_prog_data->upsp_clamp_min = 0x0;
} else {
dscl_prog_data->upsp_v_num_taps = UPSP_4_TAPS;
dscl_prog_data->upsp_h_num_taps = UPSP_4_TAPS;
dscl_prog_data->upsp_boundary_mode = UPSP_BOUNDARY_EDGE;
dscl_prog_data->upsp_clamp_max = 0xFFF;
dscl_prog_data->upsp_clamp_min = 0x0;
if (spl_in->basic_in.cositing == CHROMA_COSITING_TOPLEFT) {
if (dscl_prog_data->upsp_v_num_taps == UPSP_4_TAPS) {
dscl_prog_data->upsp_v_init_int = 0x3;
dscl_prog_data->upsp_v_init_frac = 0x0;
dscl_prog_data->upsp_v_coef_tap0_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap1_p0 = 0x40;
dscl_prog_data->upsp_v_coef_tap2_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap3_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap0_p1 = 0xFC;
dscl_prog_data->upsp_v_coef_tap1_p1 = 0x24;
dscl_prog_data->upsp_v_coef_tap2_p1 = 0x24;
dscl_prog_data->upsp_v_coef_tap3_p1 = 0xFC;
} else {
dscl_prog_data->upsp_v_init_int = 0x2;
dscl_prog_data->upsp_v_init_frac = 0x0;
dscl_prog_data->upsp_v_coef_tap0_p0 = 0x40;
dscl_prog_data->upsp_v_coef_tap1_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap2_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap3_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap0_p1 = 0x20;
dscl_prog_data->upsp_v_coef_tap1_p1 = 0x20;
dscl_prog_data->upsp_v_coef_tap2_p1 = 0x00;
dscl_prog_data->upsp_v_coef_tap3_p1 = 0x00;
}
} else {
if (dscl_prog_data->upsp_v_num_taps == UPSP_4_TAPS) {
dscl_prog_data->upsp_v_init_int = 0x2;
dscl_prog_data->upsp_v_init_frac = 0x1;
dscl_prog_data->upsp_v_coef_tap0_p0 = 0xFB;
dscl_prog_data->upsp_v_coef_tap1_p0 = 0x2F;
dscl_prog_data->upsp_v_coef_tap2_p0 = 0x19;
dscl_prog_data->upsp_v_coef_tap3_p0 = 0xFD;
dscl_prog_data->upsp_v_coef_tap0_p1 = 0xFD;
dscl_prog_data->upsp_v_coef_tap1_p1 = 0x19;
dscl_prog_data->upsp_v_coef_tap2_p1 = 0x2F;
dscl_prog_data->upsp_v_coef_tap3_p1 = 0xFB;
} else {
dscl_prog_data->upsp_v_init_int = 0x1;
dscl_prog_data->upsp_v_init_frac = 0x1;
dscl_prog_data->upsp_v_coef_tap0_p0 = 0x28;
dscl_prog_data->upsp_v_coef_tap1_p0 = 0x18;
dscl_prog_data->upsp_v_coef_tap2_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap3_p0 = 0x00;
dscl_prog_data->upsp_v_coef_tap0_p1 = 0x18;
dscl_prog_data->upsp_v_coef_tap1_p1 = 0x28;
dscl_prog_data->upsp_v_coef_tap2_p1 = 0x00;
dscl_prog_data->upsp_v_coef_tap3_p1 = 0x00;
}
}
if (spl_in->basic_in.cositing == CHROMA_COSITING_LEFT || spl_in->basic_in.cositing == CHROMA_COSITING_TOPLEFT) {
if (dscl_prog_data->upsp_h_num_taps == UPSP_4_TAPS) {
dscl_prog_data->upsp_h_init_int = 0x3;
dscl_prog_data->upsp_h_init_frac = 0x0;
dscl_prog_data->upsp_h_coef_tap0_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap1_p0 = 0x40;
dscl_prog_data->upsp_h_coef_tap2_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap3_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap0_p1 = 0xFC;
dscl_prog_data->upsp_h_coef_tap1_p1 = 0x24;
dscl_prog_data->upsp_h_coef_tap2_p1 = 0x24;
dscl_prog_data->upsp_h_coef_tap3_p1 = 0xFC;
} else {
dscl_prog_data->upsp_h_init_int = 0x2;
dscl_prog_data->upsp_h_init_frac = 0x0;
dscl_prog_data->upsp_h_coef_tap0_p0 = 0x40;
dscl_prog_data->upsp_h_coef_tap1_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap2_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap3_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap0_p1 = 0x20;
dscl_prog_data->upsp_h_coef_tap1_p1 = 0x20;
dscl_prog_data->upsp_h_coef_tap2_p1 = 0x00;
dscl_prog_data->upsp_h_coef_tap3_p1 = 0x00;
}
} else {
if (dscl_prog_data->upsp_h_num_taps == UPSP_4_TAPS) {
dscl_prog_data->upsp_h_init_int = 0x2;
dscl_prog_data->upsp_h_init_frac = 0x1;
dscl_prog_data->upsp_h_coef_tap0_p0 = 0xFB;
dscl_prog_data->upsp_h_coef_tap1_p0 = 0x2F;
dscl_prog_data->upsp_h_coef_tap2_p0 = 0x19;
dscl_prog_data->upsp_h_coef_tap3_p0 = 0xFD;
dscl_prog_data->upsp_h_coef_tap0_p1 = 0xFD;
dscl_prog_data->upsp_h_coef_tap1_p1 = 0x19;
dscl_prog_data->upsp_h_coef_tap2_p1 = 0x2F;
dscl_prog_data->upsp_h_coef_tap3_p1 = 0xFB;
} else {
dscl_prog_data->upsp_h_init_int = 0x1;
dscl_prog_data->upsp_h_init_frac = 0x1;
dscl_prog_data->upsp_h_coef_tap0_p0 = 0x28;
dscl_prog_data->upsp_h_coef_tap1_p0 = 0x18;
dscl_prog_data->upsp_h_coef_tap2_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap3_p0 = 0x00;
dscl_prog_data->upsp_h_coef_tap0_p1 = 0x18;
dscl_prog_data->upsp_h_coef_tap1_p1 = 0x28;
dscl_prog_data->upsp_h_coef_tap2_p1 = 0x00;
dscl_prog_data->upsp_h_coef_tap3_p1 = 0x00;
}
}
}
}
static bool spl_calculate_number_of_taps(struct spl_in *spl_in, struct spl_scratch *spl_scratch, struct spl_out *spl_out,
bool *enable_easf_v, bool *enable_easf_h, bool *enable_isharp)
{
bool res = false;
memset(spl_scratch, 0, sizeof(struct spl_scratch));
spl_scratch->scl_data.h_active = spl_in->h_active;
spl_scratch->scl_data.v_active = spl_in->v_active;
spl_calculate_recout(spl_in, spl_scratch, spl_out);
spl_calculate_scaling_ratios(spl_in, spl_scratch, spl_out);
spl_opp_adjust_rect(&spl_scratch->scl_data.recout, &spl_in->basic_in.opp_recout_adjust);
spl_calculate_viewport_size(spl_in, spl_scratch);
res = spl_get_optimal_number_of_taps(
spl_in->basic_out.max_downscale_src_width, spl_in,
spl_scratch, &spl_in->scaling_quality, enable_easf_v,
enable_easf_h, enable_isharp);
return res;
}
bool SPL_NAMESPACE(spl_calculate_scaler_params(struct spl_in *spl_in, struct spl_out *spl_out))
{
bool res = false;
bool enable_easf_v = false;
bool enable_easf_h = false;
int vratio = 0;
int hratio = 0;
struct spl_scratch spl_scratch;
struct spl_fixed31_32 isharp_scale_ratio;
enum system_setup setup;
bool enable_isharp = false;
const struct spl_scaler_data *data = &spl_scratch.scl_data;
determine_upsp_values(spl_in, spl_out->dscl_prog_data);
res = spl_calculate_number_of_taps(spl_in, &spl_scratch, spl_out,
&enable_easf_v, &enable_easf_h, &enable_isharp);
if (res)
spl_calculate_inits_and_viewports(spl_in, &spl_scratch);
spl_handle_3d_recout(spl_in, &spl_scratch.scl_data.recout);
spl_clamp_viewport(&spl_scratch.scl_data.viewport, spl_in->min_viewport_size);
spl_set_dscl_prog_data(spl_in, &spl_scratch, spl_out, enable_easf_v, enable_easf_h, enable_isharp);
if (!res)
return res;
if (spl_in->lls_pref == LLS_PREF_YES) {
if (spl_in->is_hdr_on)
setup = HDR_L;
else
setup = SDR_L;
} else {
if (spl_in->is_hdr_on)
setup = HDR_NL;
else
setup = SDR_NL;
}
spl_set_easf_data(&spl_scratch, spl_out, enable_easf_v, enable_easf_h, spl_in->lls_pref,
spl_in->basic_in.format, setup, spl_in->sdr_white_level_nits);
vratio = spl_fixpt_ceil(spl_scratch.scl_data.ratios.vert);
hratio = spl_fixpt_ceil(spl_scratch.scl_data.ratios.horz);
if (vratio <= hratio)
isharp_scale_ratio = spl_scratch.scl_data.recip_ratios.vert;
else
isharp_scale_ratio = spl_scratch.scl_data.recip_ratios.horz;
spl_set_isharp_data(spl_out->dscl_prog_data, spl_in->adaptive_sharpness, enable_isharp,
spl_in->lls_pref, spl_in->basic_in.format, data, isharp_scale_ratio, setup,
spl_in->debug.scale_to_sharpness_policy);
return res;
}
bool SPL_NAMESPACE(spl_get_number_of_taps(struct spl_in *spl_in, struct spl_out *spl_out))
{
bool res = false;
bool enable_easf_v = false;
bool enable_easf_h = false;
bool enable_isharp = false;
struct spl_scratch spl_scratch;
struct dscl_prog_data *dscl_prog_data = spl_out->dscl_prog_data;
const struct spl_scaler_data *data = &spl_scratch.scl_data;
res = spl_calculate_number_of_taps(spl_in, &spl_scratch, spl_out,
&enable_easf_v, &enable_easf_h, &enable_isharp);
spl_set_taps_data(dscl_prog_data, data);
return res;
}