/* Copyright 1996 Acorn Computers Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/************************************************************************/
/* � Acorn Computers Ltd, 1992.                                         */
/*                                                                      */
/* This file forms part of an unsupported source release of RISC_OSLib. */
/*                                                                      */
/* It may be freely used to create executable images for saleable       */
/* products but cannot be sold in source form or as an object library   */
/* without the prior written consent of Acorn Computers Ltd.            */
/*                                                                      */
/* If this file is re-distributed (even if modified) it should retain   */
/* this copyright notice.                                               */
/*                                                                      */
/************************************************************************/

/*
 * Title:  colourtran.c
 * Purpose: C interface to the ColourTrans SWIs
 * History: IDJ: 05-Feb-92: prepared for source release
 *
 */

#include <stddef.h>
#include "colourtran.h"
#include "os.h"
#include "wimp.h"

/* -------------------- ColourTrans SWIs -------------------------- */

#define ColourTrans_SelectTable                     0x00040740
#define ColourTrans_SelectGCOLTable                 0x00040741
#define ColourTrans_ReturnGCOL                      0x00040742
#define ColourTrans_SetGCOL                         0x00040743
#define ColourTrans_ReturnColourNumber              0x00040744
#define ColourTrans_ReturnGCOLForMode               0x00040745
#define ColourTrans_ReturnColourNumberForMode       0x00040746
#define ColourTrans_ReturnOppGCOL                   0x00040747
#define ColourTrans_SetOppGCOL                      0x00040748
#define ColourTrans_ReturnOppColourNumber           0x00040749
#define ColourTrans_ReturnOppGCOLForMode            0x0004074a
#define ColourTrans_ReturnOppColourNumberForMode    0x0004074b
#define ColourTrans_GCOLToColourNumber              0x0004074c
#define ColourTrans_ColourNumberToGCOL              0x0004074d
#define ColourTrans_ReturnFontColours               0x0004074e
#define ColourTrans_SetFontColours                  0x0004074f
#define ColourTrans_InvalidateCache                 0x00040750
#define ColourTrans_SetCalibration                  0x00040751
#define ColourTrans_ReadCalibration                 0x00040752
#define ColourTrans_ConvertDeviceColour             0x00040753
#define ColourTrans_ConvertDevicePalette            0x00040754
#define ColourTrans_ConvertRGBToCIE                 0x00040755
#define ColourTrans_ConvertCIEToRGB                 0x00040756

#pragma -s1

os_error *colourtran_select_table (int source_mode,
                                   wimp_paletteword *source_palette,
                                   int dest_mode,
                                   wimp_paletteword *dest_palette,
                                   void *buffer)
{
  os_regset r;
  os_error*e;

  r.r[0] = source_mode;
  r.r[1] = (int)source_palette;
  r.r[2] = dest_mode;
  r.r[3] = (int)dest_palette;
  r.r[4] = (int)buffer;

  e = os_swix(ColourTrans_SelectTable, &r);

  return(e);
}

#ifndef UROM
os_error *colourtran_select_GCOLtable (int source_mode,
                                       wimp_paletteword *source_palette,
                                       int dest_mode,
                                       wimp_paletteword *dest_palette,
                                       void *buffer)
{
  os_regset r;
  os_error *e;

  r.r[0] = source_mode;
  r.r[1] = (int)source_palette;
  r.r[2] = dest_mode;
  r.r[3] = (int)dest_palette;
  r.r[4] = (int)buffer;

  e = os_swix(ColourTrans_SelectGCOLTable, &r);

  return(e);
}
#endif

#ifndef UROM
os_error *colourtran_returnGCOL (wimp_paletteword entry, int *gcol)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;

  e = os_swix(ColourTrans_ReturnGCOL, &r);

  if (e == 0)
    *gcol = r.r[0];

  return(e);
}
#endif

os_error *colourtran_setGCOL (wimp_paletteword entry, int fore_back,
                              int gcol_in, int *gcol_out)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;
  r.r[3] = fore_back & 0x000fffff;
  r.r[4] = gcol_in & 0x000fffff;

  e = os_swix(ColourTrans_SetGCOL, &r);

  if (e == 0)
    *gcol_out = r.r[0];

  return(e);
}

#ifndef UROM
os_error *colourtran_return_colournumber (wimp_paletteword entry, int *col)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;

  e = os_swix(ColourTrans_ReturnColourNumber, &r);

  if (e == 0)
    *col = r.r[0];

  return(e);
}
#endif


os_error *colourtran_return_GCOLformode (wimp_paletteword entry,
                                           int dest_mode,
                                           wimp_paletteword *dest_palette,
                                           int *gcol)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;
  r.r[1] = dest_mode;
  r.r[2] = (int)dest_palette;

  e = os_swix(ColourTrans_ReturnGCOLForMode, &r);

  if (e == 0)
    *gcol = r.r[0];

  return(e);
}


os_error *colourtran_return_colourformode (wimp_paletteword entry,
                                           int dest_mode,
                                           wimp_paletteword *dest_palette,
                                           int *col)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;
  r.r[1] = dest_mode;
  r.r[2] = (int)dest_palette;

  e = os_swix(ColourTrans_ReturnColourNumberForMode, &r);

  if (e == 0)
    *col = r.r[0];

  return(e);
}

#ifndef UROM
os_error *colourtran_return_OppGCOL (wimp_paletteword entry, int *gcol)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;

  e = os_swix(ColourTrans_ReturnOppGCOL, &r);

  if (e == 0)
    *gcol = r.r[0];

  return(e);
}
#endif

#ifndef UROM
os_error *colourtran_setOppGCOL (wimp_paletteword entry, int fore_back,
                                int gcol_in, int *gcol_out)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;
  r.r[3] = fore_back & 0x000fffff;
  r.r[4] = gcol_in & 0x000fffff;

  e = os_swix(ColourTrans_SetOppGCOL, &r);

  if (e == 0)
    *gcol_out = r.r[0];

  return(e);
}
#endif

#ifndef UROM
os_error *colourtran_return_Oppcolournumber (wimp_paletteword entry,
                                            int *col)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;

  e = os_swix(ColourTrans_ReturnOppColourNumber, &r);

  if (e == 0)
    *col = r.r[0];

  return(e);
}
#endif

#ifndef UROM
os_error *colourtran_return_OppGCOLformode (wimp_paletteword entry,
                                            int dest_mode,
                                            wimp_paletteword *dest_palette,
                                            int *gcol)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;
  r.r[1] = dest_mode;
  r.r[2] = (int)dest_palette;

  e = os_swix(ColourTrans_ReturnOppGCOLForMode, &r);

  if (e == 0)
    *gcol = r.r[0];

  return(e);
}
#endif

#ifndef UROM
os_error *colourtran_return_Oppcolourformode (wimp_paletteword entry,
                                              int dest_mode,
                                              wimp_paletteword *dest_palette,
                                              int *col)
{
  os_regset r;
  os_error *e;

  r.r[0] = entry.word;
  r.r[1] = dest_mode;
  r.r[2] = (int)dest_palette;

  e = os_swix(ColourTrans_ReturnOppColourNumberForMode, &r);

  if (e == 0)
    *col = r.r[0];

  return(e);
}
#endif


#ifndef UROM
os_error *colourtran_GCOL_tocolournumber (int gcol, int *col)
{
  os_regset r;
  os_error *e;

  r.r[0] = gcol;

  e = os_swix(ColourTrans_GCOLToColourNumber, &r);

  if (e == 0)
    *col = r.r[0];

  return(e);
}
#endif

#ifndef UROM
os_error *colourtran_colournumbertoGCOL (int gcol, int *col)
{
  os_regset r;
  os_error *e;

  r.r[0] = gcol;

  e = os_swix(ColourTrans_ColourNumberToGCOL, &r);

  if (e == 0)
    *col = r.r[0];

  return(e);
}
#endif

#ifndef UROM
os_error *colourtran_returnfontcolours (font *handle,
                                        wimp_paletteword *backgnd,
                                        wimp_paletteword *foregnd,
                                        int *max_offset)
{
  os_regset r;
  os_error *e;

  r.r[0] = (int)*handle;
  r.r[1] = backgnd->word;
  r.r[2] = foregnd->word;
  r.r[3] = (int)*max_offset;

  e = os_swix(ColourTrans_ReturnFontColours, &r);

  if (e == 0)
  {
    *handle = r.r[0];
    backgnd->word = r.r[1];
    foregnd->word = r.r[2];
    *max_offset = r.r[3];
  }

  return(e);
}
#endif

os_error *colourtran_setfontcolours (font *handle,
                                     wimp_paletteword *backgnd,
                                     wimp_paletteword *foregnd,
                                     int *max_offset)
{
  os_regset r;
  os_error *e;

  r.r[0] = (int)*handle;
  r.r[1] = backgnd->word;
  r.r[2] = foregnd->word;
  r.r[3] = (int)*max_offset;

  e = os_swix(ColourTrans_SetFontColours, &r);

  if (e == 0)
  {
    *handle = r.r[0];
    backgnd->word = r.r[1];
    foregnd->word = r.r[2];
    *max_offset = r.r[3];
  }

  return(e);
}

#ifndef UROM
os_error *colourtran_invalidate_cache (void)
{
  os_regset r;

  return(os_swix(ColourTrans_InvalidateCache, &r));
}
#endif

os_error *colourtran_convert_device_colour (wimp_paletteword device, wimp_paletteword *rgb)
{
  os_regset r;
  os_error *e;

  r.r[1] = device.word;
  r.r[3] = 0;

  e = os_swix(ColourTrans_ConvertDeviceColour, &r);

  if (e == 0)
    (*rgb).word = r.r[2];

  return e;
}

#pragma -s0

/* end colourtran.c */