Back to index

lightning-sunbird  0.9+nobinonly
iccolor.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2000 SuSE, Inc.
00003  *
00004  * Permission to use, copy, modify, distribute, and sell this software and its
00005  * documentation for any purpose is hereby granted without fee, provided that
00006  * the above copyright notice appear in all copies and that both that
00007  * copyright notice and this permission notice appear in supporting
00008  * documentation, and that the name of SuSE not be used in advertising or
00009  * publicity pertaining to distribution of the software without specific,
00010  * written prior permission.  SuSE makes no representations about the
00011  * suitability of this software for any purpose.  It is provided "as is"
00012  * without express or implied warranty.
00013  *
00014  * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
00016  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00017  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00018  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
00019  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00020  *
00021  * Author:  Keith Packard, SuSE, Inc.
00022  */
00023 
00024 #include "icint.h"
00025 
00026 #ifdef ICINT_NEED_IC_ONES
00027 /* Fall back on HACKMEM 169.  */
00028 int
00029 _FbOnes (unsigned long mask)
00030 {
00031     register unsigned long y;
00032 
00033     y = (mask >> 1) &033333333333;
00034     y = mask - y - ((y >>1) & 033333333333);
00035     return (((y + (y >> 3)) & 030707070707) % 077);
00036 }
00037 #endif
00038 
00039 void
00040 pixman_color_to_pixel (const pixman_format_t     *format,
00041               const pixman_color_t *color,
00042               pixman_bits_t        *pixel)
00043 {
00044     uint32_t      r, g, b, a;
00045 
00046     r = color->red >> (16 - _FbOnes (format->redMask));
00047     g = color->green >> (16 - _FbOnes (format->greenMask));
00048     b = color->blue >> (16 - _FbOnes (format->blueMask));
00049     a = color->alpha >> (16 - _FbOnes (format->alphaMask));
00050     r = r << format->red;
00051     g = g << format->green;
00052     b = b << format->blue;
00053     a = a << format->alpha;
00054     *pixel = r|g|b|a;
00055 }
00056 slim_hidden_def(pixman_color_to_pixel);
00057 
00058 static uint16_t
00059 FbFillColor (uint32_t pixel, int bits)
00060 {
00061     while (bits < 16)
00062     {
00063        pixel |= pixel << bits;
00064        bits <<= 1;
00065     }
00066     return (uint16_t) pixel;
00067 }
00068 
00069 void
00070 pixman_pixel_to_color (const pixman_format_t     *format,
00071               const pixman_bits_t  pixel,
00072               pixman_color_t              *color)
00073 {
00074     uint32_t      r, g, b, a;
00075 
00076     r = (pixel >> format->red) & format->redMask;
00077     g = (pixel >> format->green) & format->greenMask;
00078     b = (pixel >> format->blue) & format->blueMask;
00079     a = (pixel >> format->alpha) & format->alphaMask;
00080     color->red = FbFillColor (r, _FbOnes (format->redMask));
00081     color->green = FbFillColor (r, _FbOnes (format->greenMask));
00082     color->blue = FbFillColor (r, _FbOnes (format->blueMask));
00083     color->alpha = FbFillColor (r, _FbOnes (format->alphaMask));
00084 }