Logo Search packages:      
Sourcecode: hermes1 version File versions  Download package

c_genrc_a.c

/*
   Generic format conversion routines for the HERMES library
   Copyright (c) 1998 Christian Nentwich (c.nentwich@cs.ucl.ac.uk)
   This source code is licensed under the GNU LGPL
  
   Please refer to the file COPYING.LIB contained in the distribution for
   licensing conditions
*/

#include "HermConf.h"
#include "HeadC.h"
#include "Debug.h"


void ConvertC_Generic32_A_Generic32_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 32A to 32A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=READ32(source);

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((s_pixel>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;
    
      WRITE32(dest,(r|g|b|a));
    
      source+=4;
      dest+=4;
    } while(--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic32_A_Generic24_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  char8 *d_ptr=(char8 *)((int)&s_pixel);
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 32A to 24A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=READ32(source);

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
    
      s_pixel=(r|g|b|a);

      *(dest+R_24)=*(d_ptr+R_32);
      *(dest+G_24)=*(d_ptr+G_32);
      *(dest+B_24)=*(d_ptr+B_32);

      source+=4;
      dest+=3;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic32_A_Generic16_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 32A to 16A\n","");
  do {
    count=iface->s_width>>1;

    if (count)
    do
    { 
      r=((READ32(source)>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((READ32(source)>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((READ32(source)>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((READ32(source)>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;

      s_pixel=DWORD_BYTE0(r|g|b|a);
      
      r=((READ32(source+1)>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;           
      g=((READ32(source+1)>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;           
      b=((READ32(source+1)>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b; 
      a=((READ32(source+1)>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a; 
    
      s_pixel|=DWORD_BYTE2(r|g|b|a);
      
      WRITE32(dest,s_pixel);
      
      source+=8;
      dest+=4;
    } while (--count);


    /* Trailing pixel */
    
    if (iface->s_width&1) {
      r=((READ32(source)>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((READ32(source)>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((READ32(source)>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((READ32(source)>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;

      WRITE16(dest,(short16)(r|g|b|a));
      dest+=2;
      source+=4;
    }

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic32_A_Generic8_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 32A to 8A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=READ32(source);

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((s_pixel>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;
    
      *(dest)=(char8)(r|g|b|a);
    
      source+=4;
      dest++;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}





void ConvertC_Generic24_A_Generic32_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
    DEBUG_PRINT("Conversion for 24A to 32A\n","");
  do {
    count=iface->s_width;

    do
    { 
      s_pixel=(((int32)*(source+R_24))<<16)|
              (((int32)*(source+G_24))<<8)|
              ((int32)*(source+B_24));
    
      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
    
      WRITE32(dest,(r|g|b));
    
      source+=3;
      dest+=4;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic24_A_Generic24_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  char8 *d_ptr=(char8 *)&s_pixel;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 24A to 24A\n","");
  do {
    count=iface->s_width;

    do
    { 
      s_pixel=(((int32)*(source+R_24))<<16)|
              (((int32)*(source+G_24))<<8)|
               ((int32)*(source+B_24));
    
      r=((s_pixel<<iface->info.r_left)>>iface->info.r_right)&
        iface->mask_r;
      g=((s_pixel<<iface->info.g_left)>>iface->info.g_right)&
        iface->mask_g;
      b=((s_pixel<<iface->info.b_left)>>iface->info.b_right)&
        iface->mask_b;

      s_pixel=(r|g|b);
    
      *(dest+R_24)=*(d_ptr+R_32);
      *(dest+G_24)=*(d_ptr+G_32);
      *(dest+B_24)=*(d_ptr+B_32);
    
      source+=3;
      dest+=3;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (iface->s_height--);
}



void ConvertC_Generic24_A_Generic16_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 16A to 16A\n","");
  do {
    count=iface->s_width;

    do
    { 
      s_pixel=(((int32)*(source+R_24))<<16)|
              (((int32)*(source+G_24))<<8)|
               ((int32)*(source+B_24));
    
      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
    
      WRITE16(dest,(short16)(r|g|b));
    
      source+=3;
      dest+=2;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic24_A_Generic8_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 24A to 8A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=(((int32)*(source+R_24))<<16)|
              (((int32)*(source+G_24))<<8)|
               ((int32)*(source+B_24));

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
    
      *(dest)=(char8)(r|g|b);
    
      source+=3;
      dest++;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}




void ConvertC_Generic16_A_Generic32_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 16A to 32A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=(int32)READ16(source);

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((s_pixel>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;
    
      WRITE32(dest,(r|g|b|a));
    
      source+=2;
      dest+=4;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic16_A_Generic24_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  char8 *d_ptr=(char8 *)((int)&s_pixel);
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 16A to 24A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=(int32)READ16(source);

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
    
      s_pixel=(r|g|b);

      *(dest+R_24)=*(d_ptr+R_32);
      *(dest+G_24)=*(d_ptr+G_32);
      *(dest+B_24)=*(d_ptr+B_32);

      source+=2;
      dest+=3;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic16_A_Generic16_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 16A to 16A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=(int32)READ16(source);

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((s_pixel>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;
    
      WRITE16(dest,(short16)(r|g|b|a));
    
      source+=2;
      dest+=2;
    } while(--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


void ConvertC_Generic16_A_Generic8_A(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source=iface->s_pixels,*dest=iface->d_pixels;
  DEBUG_PRINT("Conversion for 16A to 8A\n","");
  do {
    count=iface->s_width;

    do
    { s_pixel=(int32)READ16(source);

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((s_pixel>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;
    
      *dest=(char8)(r|g|b|a);
    
      source+=2;
      dest++;
    } while (--count);

    source+=iface->s_add;
    dest+=iface->d_add;
  } while (--iface->s_height);
}


/* -------------------------------------------------------------------------

                              STRETCH CONVERTERS
   
   ------------------------------------------------------------------------- */


void ConvertC_Generic32_A_Generic32_A_S(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  char8 *source,*dest=iface->d_pixels;
  unsigned int dy=(iface->s_height<<16)/iface->d_height;
  unsigned int dx=(iface->s_width<<16)/iface->d_width;
  unsigned int y=0,x;
  DEBUG_PRINT("Conversion for 32A to 32A stretch\n","");
  do {
    count=iface->d_width;
    x=0;
    source=iface->s_pixels;

    do
    { s_pixel=READ32(source+(x>>16));

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((s_pixel>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;
    
      WRITE32(dest,(r|g|b|a));
    
      x+=dx;
      dest+=4;
    } while(--count);
    
    dest+=iface->d_add;
    
    y+=dy;
    source+=(y>>16)*iface->s_pitch;
    y &= (1<<16)-1;

  } while (--iface->d_height);
}


void ConvertC_Generic32_A_Generic16_A_S(HermesConverterInterface *iface)
{ int32 s_pixel,r,g,b,a;
  unsigned int count;
  int32 *source=(int32*)iface->s_pixels;
  char8 *dest=iface->d_pixels;
  unsigned int dy=(iface->s_height<<16)/iface->d_height;
  unsigned int dx=(iface->s_width<<16)/iface->d_width;
  unsigned int y=0,x;
  DEBUG_PRINT("Conversion for 32A to 16A stretch\n","");
  DEBUG_FNAME("ConvertC_Generic32_A_Generic16_A_S")

  do {

    count=iface->d_width;
    x=0;

    do
    { s_pixel=*(source+(x>>16));

      r=((s_pixel>>iface->info.r_right)<<iface->info.r_left)&
        iface->mask_r;
      g=((s_pixel>>iface->info.g_right)<<iface->info.g_left)&
        iface->mask_g;
      b=((s_pixel>>iface->info.b_right)<<iface->info.b_left)&
        iface->mask_b;
      a=((s_pixel>>iface->info.a_right)<<iface->info.a_left)&
        iface->mask_a;
    
      WRITE16(dest,(short16)(r|g|b|a));
    
      x+=dx;
      dest+=2;
    } while (--count);
    
    dest+=iface->d_add;

    y+=dy;
      
    source=(int32*)((char8*)source+(y>>16)*iface->s_pitch);
    y &= 0xffff;
  } while (--iface->d_height);
}

Generated by  Doxygen 1.6.0   Back to index