52 lines
2.3 KiB
C
52 lines
2.3 KiB
C
/*
|
|
Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
|
|
|
|
This file is part of Aedrix.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#include <framebuffer.h>
|
|
|
|
int fb_write_pixel_8bit(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) {
|
|
unsigned char pixel = (((b >> 6) << 6) & 0xC0) | (((g >> 5) << 3) & 0x38) | ((r >> 5) & 0x7);
|
|
((char*)f->device->fbaddr)[y*f->device->pixelwidth + x] = pixel;
|
|
return 0;
|
|
}
|
|
|
|
int fb_write_pixel_16bit(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) {
|
|
unsigned int pixel = (((b >> 3) << 11) & 0xF800) | (((g >> 2) << 6) & 0x7E0) | ((r >> 3) & 0x1F);
|
|
((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x) << 1] = (char)pixel;
|
|
((char*)f->device->fbaddr)[((y*f->device->pixelwidth + x) << 1) + 1] = (char)(pixel >> 8);
|
|
return 0;
|
|
}
|
|
|
|
int fb_write_pixel_24bit(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) {
|
|
((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*4] = (char)r;
|
|
((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*4 + 1] = (char)g;
|
|
((char*)f->device->fbaddr)[(y*f->device->pixelwidth + x)*4 + 2] = (char)b;
|
|
return 0;
|
|
}
|
|
|
|
int fb_write_pixel(struct fb *f, unsigned int x, unsigned int y, unsigned int r, unsigned int g, unsigned int b) {
|
|
if (f->device->color_depth == FB_COLOR_DEPTH_8)
|
|
return fb_write_pixel_8bit(f, x, y, r, g, b);
|
|
else if (f->device->color_depth == FB_COLOR_DEPTH_16)
|
|
return fb_write_pixel_16bit(f, x, y, r, g, b);
|
|
else if (f->device->color_depth == FB_COLOR_DEPTH_24)
|
|
return fb_write_pixel_24bit(f, x, y, r, g, b);
|
|
return -1;
|
|
}
|