Simplify scaler code

This commit is contained in:
twinaphex 2017-04-16 10:29:22 +02:00
parent 602ba5d8a6
commit 8fd0033b43

View File

@ -62,33 +62,43 @@ void scaler_free(void *ptr)
static bool allocate_frames(struct scaler_ctx *ctx)
{
uint64_t *scaled_frame = NULL;
ctx->scaled.stride = ((ctx->out_width + 7) & ~7) * sizeof(uint64_t);
ctx->scaled.width = ctx->out_width;
ctx->scaled.height = ctx->in_height;
ctx->scaled.frame = (uint64_t*)
scaler_alloc(sizeof(uint64_t),
scaled_frame = (uint64_t*)scaler_alloc(sizeof(uint64_t),
(ctx->scaled.stride * ctx->scaled.height) >> 3);
if (!ctx->scaled.frame)
if (!scaled_frame)
return false;
ctx->scaled.frame = scaled_frame;
if (ctx->in_fmt != SCALER_FMT_ARGB8888)
{
uint32_t *input_frame = NULL;
ctx->input.stride = ((ctx->in_width + 7) & ~7) * sizeof(uint32_t);
ctx->input.frame = (uint32_t*)
scaler_alloc(sizeof(uint32_t),
input_frame = (uint32_t*)scaler_alloc(sizeof(uint32_t),
(ctx->input.stride * ctx->in_height) >> 2);
if (!ctx->input.frame)
if (!input_frame)
return false;
ctx->input.frame = input_frame;
}
if (ctx->out_fmt != SCALER_FMT_ARGB8888)
{
uint32_t *output_frame = NULL;
ctx->output.stride = ((ctx->out_width + 7) & ~7) * sizeof(uint32_t);
ctx->output.frame = (uint32_t*)
scaler_alloc(sizeof(uint32_t),
output_frame = (uint32_t*)scaler_alloc(sizeof(uint32_t),
(ctx->output.stride * ctx->out_height) >> 2);
if (!ctx->output.frame)
if (!output_frame)
return false;
ctx->output.frame = output_frame;
}
return true;
@ -106,12 +116,6 @@ static bool allocate_frames(struct scaler_ctx *ctx)
**/
static bool set_direct_pix_conv(struct scaler_ctx *ctx)
{
if (ctx->in_fmt == ctx->out_fmt)
{
ctx->direct_pixconv = conv_copy;
return true;
}
switch (ctx->in_fmt)
{
case SCALER_FMT_0RGB1555:
@ -209,8 +213,31 @@ static bool set_direct_pix_conv(struct scaler_ctx *ctx)
return true;
}
static bool set_pix_conv(struct scaler_ctx *ctx)
bool scaler_ctx_gen_filter(struct scaler_ctx *ctx)
{
scaler_ctx_gen_reset(ctx);
ctx->scaler_special = NULL;
ctx->unscaled = false;
if (!allocate_frames(ctx))
return false;
if ( ctx->in_width == ctx->out_width
&& ctx->in_height == ctx->out_height)
{
ctx->unscaled = true; /* Only pixel format conversion ... */
if (ctx->in_fmt == ctx->out_fmt)
ctx->direct_pixconv = conv_copy;
else if (!set_direct_pix_conv(ctx))
return false;
}
else
{
ctx->scaler_horiz = scaler_argb8888_horiz;
ctx->scaler_vert = scaler_argb8888_vert;
switch (ctx->in_fmt)
{
case SCALER_FMT_ARGB8888:
@ -259,40 +286,9 @@ static bool set_pix_conv(struct scaler_ctx *ctx)
return false;
}
return true;
}
bool scaler_ctx_gen_filter(struct scaler_ctx *ctx)
{
scaler_ctx_gen_reset(ctx);
if (ctx->in_width == ctx->out_width && ctx->in_height == ctx->out_height)
ctx->unscaled = true; /* Only pixel format conversion ... */
else
{
ctx->scaler_horiz = scaler_argb8888_horiz;
ctx->scaler_vert = scaler_argb8888_vert;
ctx->unscaled = false;
}
ctx->scaler_special = NULL;
if (!allocate_frames(ctx))
return false;
if (ctx->unscaled)
{
if (!set_direct_pix_conv(ctx))
if (!scaler_gen_filter(ctx))
return false;
}
else
{
if (!set_pix_conv(ctx))
return false;
}
if (!ctx->unscaled && !scaler_gen_filter(ctx))
return false;
return true;
}