Home | History | Annotate | Download | only in deimage
      1 #ifndef _DEARGB_H
      2 #define _DEARGB_H
      3 /*-------------------------------------------------------------------------
      4  * drawElements Image Library
      5  * --------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief Image library.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "deDefs.h"
     27 #include "deInt32.h"
     28 
     29 /* ARGB color in descending A, R, G, B order (alpha is in most significant byte). */
     30 typedef deUint32 deARGB;
     31 
     32 DE_INLINE deARGB	deARGB_set (int r, int g, int b, int a)
     33 {
     34 	DE_ASSERT(deInBounds32(r, 0, 256));
     35 	DE_ASSERT(deInBounds32(g, 0, 256));
     36 	DE_ASSERT(deInBounds32(b, 0, 256));
     37 	DE_ASSERT(deInBounds32(a, 0, 256));
     38 	return (a<<24) | (r<<16) | (g<<8) | (b<<0);
     39 }
     40 
     41 DE_INLINE deARGB	deARGB_white 		(void) 			{ return deARGB_set(0xFF, 0xFF, 0xFF, 0xFF); }
     42 DE_INLINE deARGB	deARGB_black 		(void) 			{ return deARGB_set(0, 0, 0, 0xFF); }
     43 
     44 DE_INLINE int		deARGB_getRed		(deARGB argb)	{ return (int)((argb >> 16) & 0xFF); }
     45 DE_INLINE int		deARGB_getGreen		(deARGB argb)	{ return (int)((argb >>  8) & 0xFF); }
     46 DE_INLINE int		deARGB_getBlue		(deARGB argb)	{ return (int)((argb >>  0) & 0xFF); }
     47 DE_INLINE int		deARGB_getAlpha		(deARGB argb)	{ return (int)((argb >> 24) & 0xFF); }
     48 
     49 DE_INLINE deARGB deARGB_multiply (deARGB argb, int f)
     50 {
     51 	DE_ASSERT(deInRange32(f, 0, 256));
     52 	{
     53 		int r = (deARGB_getRed(argb) * f + 128) >> 8;
     54 		int g = (deARGB_getGreen(argb) * f + 128) >> 8;
     55 		int b = (deARGB_getBlue(argb) * f + 128) >> 8;
     56 		int a = (deARGB_getAlpha(argb) * f + 128) >> 8;
     57 		return deARGB_set(r, g, b, a);
     58 	}
     59 }
     60 
     61 DE_INLINE deARGB deARGB_add (deARGB a, deARGB b)
     62 {
     63 	return deARGB_set(deClamp32(deARGB_getRed(a)   + deARGB_getRed(b),   0, 255),
     64 					  deClamp32(deARGB_getGreen(a) + deARGB_getGreen(b), 0, 255),
     65 					  deClamp32(deARGB_getBlue(a)  + deARGB_getBlue(b),  0, 255),
     66 					  deClamp32(deARGB_getAlpha(a) + deARGB_getAlpha(b), 0, 255));
     67 }
     68 
     69 #endif /* _DEARGB_H */
     70