/*
 * ka_scaler.c
 * Copyright (C) 2002 P.Everett <peter@everett9981.freeserve.co.uk>
 *
 * This file is part of KinoAMP, a free RISCOS MPEG program stream decoder.
 *
 * KinoAMP is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * KinoAMP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * This software is based on Kino v0.3 by eQ R&D <http://www.eqrd.net>
 */

#include "ka_scaleconv.h"

#include "inttypes.h"
#include "ka_scalers.h"

static const ka_scaler_f scalers[4][7] =
{
  // raw
  { ka_scale_raw_8bpp
  , ka_scale_raw_8bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_32bpp
  }
  // system
, { ka_scale_raw_8bpp
  , ka_scale_raw_8bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_16bpp
  , ka_scale_raw_32bpp
  }
  // linear
, { ka_scale_raw_8bpp
  , ka_scale_linear_8bpp_mono
  , ka_scale_linear_12bpp
  , ka_scale_linear_15bpp
  , ka_scale_linear_15bpp
  , ka_scale_linear_16bpp
  , ka_scale_linear_32bpp
  }
  // bilinear
, { ka_scale_raw_8bpp
  , ka_scale_bilinear_8bpp_mono
  , ka_scale_bilinear_12bpp
  , ka_scale_bilinear_t15bpp
  , ka_scale_bilinear_a15bpp
  , ka_scale_bilinear_16bpp
  , ka_scale_bilinear_32bpp
  }
};

/**
 * Selects the most appropriate scaler for the current display options.
 *
 * @param  options   Scaler options.
 *
 * @returns Scaler function to use for plotting output.
 */
void ka_scale(ka_scale_t* scale, const ka_scaleconv_t* options)
{
  ka_scaler_f fscale;
  int index = 0;

  switch(scale->col_depth)
  {
    case ka_col_depth_256:
    	index = 0;
    	if (options->config & ka_scaleconv_config_monochrome)
    		index++;
    break;
    case ka_col_depth_TBGR12:
    case ka_col_depth_TRGB12:
    case ka_col_depth_ABGR12:
    case ka_col_depth_ARGB12:
    	index = 2;
    break;
    case ka_col_depth_TBGR15:
    case ka_col_depth_TRGB15:
    	index = 3;
    break;
    case ka_col_depth_ABGR15:
    case ka_col_depth_ARGB15:
    	index = 4;
    break;
    case ka_col_depth_TBGR16:
    case ka_col_depth_TRGB16:
    case ka_col_depth_ABGR16:
    case ka_col_depth_ARGB16:
    	index = 5;
    break;
    case ka_col_depth_TBGR32:
    case ka_col_depth_TRGB32:
    case ka_col_depth_ABGR32:
    case ka_col_depth_ARGB32:
    	index = 6;
    break;
  }

  fscale = scalers[options->type][index];
  fscale(scale);
}
