153874Sgreen/*- 2110598Sdes * Copyright (c) 2013 The FreeBSD Foundation 3226101Sdes * All rights reserved. 453874Sgreen * 553874Sgreen * This software was developed by Aleksandr Rybalko under sponsorship from the 6110598Sdes * FreeBSD Foundation. 7110598Sdes * 8110598Sdes * Redistribution and use in source and binary forms, with or without 9110598Sdes * modification, are permitted provided that the following conditions 1087398Sdes * are met: 1153874Sgreen * 1. Redistributions of source code must retain the above copyright 1253874Sgreen * notice, this list of conditions and the following disclaimer. 1353874Sgreen * 2. Redistributions in binary form must reproduce the above copyright 1453874Sgreen * notice, this list of conditions and the following disclaimer in the 1553874Sgreen * documentation and/or other materials provided with the distribution. 1653874Sgreen * 1753874Sgreen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1853874Sgreen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19110598Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20110598Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21110598Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2253874Sgreen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2353874Sgreen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2453874Sgreen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2553874Sgreen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2653874Sgreen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2753874Sgreen * SUCH DAMAGE. 2853874Sgreen * 2953874Sgreen * $FreeBSD$ 3053874Sgreen */ 3153874Sgreen 3253874Sgreen#include <sys/param.h> 3353874Sgreen 3453874Sgreen#include <dev/vt/colors/vt_termcolors.h> 3553874Sgreen 3684218Sdillonstatic struct { 3784218Sdillon unsigned char r; /* Red percentage value. */ 3853874Sgreen unsigned char g; /* Green percentage value. */ 3953874Sgreen unsigned char b; /* Blue percentage value. */ 4080542Smarkm} color_def[16] = { 4153874Sgreen {0, 0, 0}, /* black */ 42120231Sdes {0, 0, 50}, /* dark blue */ 4393804Sdes {0, 50, 0}, /* dark green */ 44110598Sdes {0, 50, 50}, /* dark cyan */ 4553874Sgreen {50, 0, 0}, /* dark red */ 4680542Smarkm {50, 0, 50}, /* dark magenta */ 4753874Sgreen {50, 50, 0}, /* brown */ 4853874Sgreen {75, 75, 75}, /* light gray */ 4953874Sgreen {50, 50, 50}, /* dark gray */ 5053874Sgreen {0, 0, 100}, /* light blue */ 5193804Sdes {0, 100, 0}, /* light green */ 5287398Sdes {0, 100, 100}, /* light cyan */ 5387398Sdes {100, 0, 0}, /* light red */ 5490229Sdes {100, 0, 100}, /* light magenta */ 5553874Sgreen {100, 100, 0}, /* yellow */ 5694216Sdes {100, 100, 100}, /* white */ 5753874Sgreen}; 5880542Smarkm 5961087Skrisint 6061087Skrisvt_generate_vga_palette(uint32_t *palette, int format, uint32_t rmax, int roffset, 61162900Sru uint32_t gmax, int goffset, uint32_t bmax, int boffset) 6253874Sgreen{ 6361087Skris int i; 6453874Sgreen 65204917Sdes#define CF(_f, _i) ((_f ## max * color_def[(_i)]._f / 100) << _f ## offset) 66204917Sdes for (i = 0; i < 16; i++) { 67204917Sdes switch (format) { 68110598Sdes case COLOR_FORMAT_VGA: 6993984Sdes palette[i] = i; 70110598Sdes break; 71110598Sdes case COLOR_FORMAT_RGB: 72110598Sdes palette[i] = CF(r, i) | CF(g, i) | CF(b, i); 73110598Sdes break; 7453874Sgreen default: 75110598Sdes return (ENODEV); 76110598Sdes } 7753874Sgreen } 78110598Sdes#undef CF 79110598Sdes return (0); 80110598Sdes} 81110598Sdes