PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Dependents: YATTT sd_map_test cPong SnowDemo ... more
PokittoPalette.cpp
00001 /**************************************************************************/ 00002 /*! 00003 @file PokittoPalette.cpp 00004 @author Jonne Valola 00005 00006 @section LICENSE 00007 00008 Software License Agreement (BSD License) 00009 00010 Copyright (c) 2016, Jonne Valola 00011 All rights reserved. 00012 00013 Redistribution and use in source and binary forms, with or without 00014 modification, are permitted provided that the following conditions are met: 00015 1. Redistributions of source code must retain the above copyright 00016 notice, this list of conditions and the following disclaimer. 00017 2. Redistributions in binary form must reproduce the above copyright 00018 notice, this list of conditions and the following disclaimer in the 00019 documentation and/or other materials provided with the distribution. 00020 3. Neither the name of the copyright holders nor the 00021 names of its contributors may be used to endorse or promote products 00022 derived from this software without specific prior written permission. 00023 00024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 00025 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00028 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 */ 00035 /**************************************************************************/ 00036 00037 #include "PokittoDisplay.h " 00038 #include "Pokitto_settings.h " 00039 #include "GBcompatibility.h" 00040 #include <stdio.h> 00041 #include <string.h> 00042 00043 #ifndef POK_SIM 00044 #include "HWLCD.h " 00045 #else 00046 #include "SimLCD.h" 00047 #endif 00048 00049 #if PROJ_SCREENMODE != 13 && PROJ_SCREENMODE != 64 && !defined(PROJ_MODE13) && !defined(PROJ_MODE64) 00050 #define PALSIZE 16 00051 #else 00052 #define PALSIZE 256 00053 #endif 00054 00055 using namespace Pokitto; 00056 00057 00058 void Display::loadRGBPalette(const unsigned char* p) { 00059 for (int i=0;i<PALSIZE;i++) palette[i] = RGBto565(p[i*3], p[i*3+1],p[i*3+2]); 00060 paletteptr = palette; 00061 } 00062 00063 void Display::load565Palette(const uint16_t* p) { 00064 for (int i=0;i<PALSIZE;i++) palette[i] = p[i]; 00065 paletteptr = palette; 00066 } 00067 00068 void Display::rotatePalette(int8_t step) { 00069 uint16_t tpal[PALSIZE]; 00070 if (step == 0) return; 00071 step = 0-step; 00072 if (step>0) { 00073 for (int i=step;i<PALSIZE;i++) tpal[i]=palette[i-step]; // palette revolves up, new color 1 becomes old color 0 00074 for (int i=0; i < step; i++) tpal[i]=palette[PALSIZE-step+i]; // overflow topmost values to bottom of new palette 00075 } else { 00076 for (int i=0;i<PALSIZE+step;i++) 00077 { 00078 tpal[i]=palette[i-step]; 00079 }// palette revolves down, new color 0 becomes old color 1 00080 for (int i=0;i<-step; i++) { 00081 tpal[PALSIZE+step+i]=palette[i]; 00082 } 00083 // overflow bottom values to top of new palette 00084 } 00085 for (int i=0; i<PALSIZE;i++) palette[i] = tpal[i]; 00086 } 00087 00088 uint16_t Display::RGBto565(uint8_t R,uint8_t G,uint8_t B) { 00089 uint16_t color; 00090 color = B>>3; 00091 color |= ((G >> 2) << 5); 00092 color |= ((R >> 3) << 11); 00093 return color; 00094 } 00095 00096 uint16_t Display::interpolateColor(uint16_t c1, uint16_t c2, uint8_t factor) { 00097 int16_t R,G,B; 00098 int16_t dR,dG,dB; 00099 uint16_t color; 00100 00101 B = (c1 & 0x1F); 00102 dB = (c2 & 0x1F)-B; 00103 dB = (dB*factor)>>8; 00104 B += dB; 00105 if (B<0) B = 0; 00106 00107 G = ((c1>>5) & 0x3F); 00108 dG = ((c2>>5) & 0x3F)-G; 00109 dG = (dG*factor)>>8; 00110 G += dG; 00111 if (G<0) G=0; 00112 00113 R = (c1>>11); 00114 dR = (c2>>11)-R; 00115 dR = (dR*factor)>>8; 00116 R += dR; 00117 if (R<0) R=0; 00118 00119 color = B; 00120 color |= (G << 5); 00121 color |= (R << 11); 00122 return color; 00123 } 00124 00125 void Display::tweenPalette(uint16_t* ram_pal, const uint16_t* pal_1, const uint16_t* pal_2, uint8_t factor) { 00126 for (uint8_t i = 0; i<16 ; i++) { 00127 ram_pal[i] = interpolateColor(pal_1[i],pal_2[i],factor); 00128 } 00129 } 00130 00131 00132 00133
Generated on Tue Jul 12 2022 11:20:37 by 1.7.2