#ifndef n_RGBAL_H
#define n_RGBAL_H

/*
 *
 * nucleo/image/encoding/RGBAL.H --
 *
 * Copyright (C) Nicolas Roussel
 *
 * See the file LICENSE for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 */

namespace nucleo {

  // -------------------------------------------------------------

  static inline void
  L2RGB(unsigned int w, unsigned int h,
	   unsigned char *src, unsigned char *dst) {
    for (unsigned int i=w*h; i; --i) {
	 memset(dst, *src, 3) ;
	 src++ ;
	 dst += 3 ;
    }
  }

  static inline void
  L2ARGB(unsigned int w, unsigned int h,
	    unsigned char *src, unsigned char *dst) {
    for (unsigned int i=w*h; i; --i) {
	 *dst++ = 255 ;
	 memset(dst, *src, 3) ;
	 src++ ;
	 dst += 3 ;
    }
  }

  // -------------------------------------------------------------

  static inline void
  RGB2L(unsigned int w, unsigned int h,
	   unsigned char *src, unsigned char *dst) {
    for (unsigned int i=w*h; i; i--) {
	 double r=src[0], g=src[1], b=src[2] ;
	 *dst++ = (unsigned char)(0.11*b + 0.59*g + 0.3*r) ;
	 src += 3 ;
    }
  }

  static inline void
  RGB2ARGB(unsigned int w, unsigned int h,
		 unsigned char *src, unsigned char *dst) {
    for (unsigned int i=w*h; i; i--) {
	 *dst++ = 255 ;
	 memcpy(dst, src, 3) ;
	 dst += 3 ;
	 src += 3 ;
    }
  }

  // -------------------------------------------------------------

  static inline void
  ARGB2L(unsigned int w, unsigned int h,
	    unsigned char *src, unsigned char *dst) {
    for (unsigned int i=w*h; i; i--) {
	 double r=src[1], g=src[2], b=src[3] ;
	 *dst++ = (unsigned char)(0.11*b + 0.59*g + 0.3*r) ;
	 src += 4 ;
    }
  }

  static inline void
  ARGB2RGB(unsigned int w, unsigned int h,
		 unsigned char *src, unsigned char *dst) {
    src++ ;
    for (unsigned int i=w*h; i; i--) {
	 memcpy(dst, src, 3) ;
	 src += 4 ;
	 dst += 3 ;
    }
  }

  // -------------------------------------------------------------

}

#endif
