PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Fork of PokittoLib by
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 using namespace Pokitto; 00050 00051 00052 void Display::loadRGBPalette(const unsigned char* p) { 00053 for (int i=0;i<PALETTE_SIZE;i++) palette[i] = RGBto565(p[i*3], p[i*3+1],p[i*3+2]); 00054 paletteptr = palette; 00055 } 00056 00057 void Display::load565Palette(const uint16_t* p) { 00058 for (int i=0;i<PALETTE_SIZE;i++) palette[i] = p[i]; 00059 paletteptr = palette; 00060 } 00061 00062 void Display::rotatePalette(int8_t step) { 00063 uint16_t tpal[PALETTE_SIZE]; 00064 if (step == 0) return; 00065 step = 0-step; 00066 if (step>0) { 00067 for (int i=step;i<PALETTE_SIZE;i++) tpal[i]=palette[i-step]; // palette revolves up, new color 1 becomes old color 0 00068 for (int i=0; i < step; i++) tpal[i]=palette[PALETTE_SIZE-step+i]; // overflow topmost values to bottom of new palette 00069 } else { 00070 for (int i=0;i<PALETTE_SIZE+step;i++) 00071 { 00072 tpal[i]=palette[i-step]; 00073 }// palette revolves down, new color 0 becomes old color 1 00074 for (int i=0;i<-step; i++) { 00075 tpal[PALETTE_SIZE+step+i]=palette[i]; 00076 } 00077 // overflow bottom values to top of new palette 00078 } 00079 for (int i=0; i<PALETTE_SIZE;i++) palette[i] = tpal[i]; 00080 } 00081 00082 uint16_t Display::RGBto565(uint8_t R,uint8_t G,uint8_t B) { 00083 uint16_t color; 00084 color = B>>3; 00085 color |= ((G >> 2) << 5); 00086 color |= ((R >> 3) << 11); 00087 return color; 00088 } 00089 00090 uint16_t Display::interpolateColor(uint16_t c1, uint16_t c2, uint8_t factor) { 00091 int16_t R,G,B; 00092 int16_t dR,dG,dB; 00093 uint16_t color; 00094 00095 B = (c1 & 0x1F); 00096 dB = (c2 & 0x1F)-B; 00097 dB = (dB*factor)>>8; 00098 B += dB; 00099 if (B<0) B = 0; 00100 00101 G = ((c1>>5) & 0x3F); 00102 dG = ((c2>>5) & 0x3F)-G; 00103 dG = (dG*factor)>>8; 00104 G += dG; 00105 if (G<0) G=0; 00106 00107 R = (c1>>11); 00108 dR = (c2>>11)-R; 00109 dR = (dR*factor)>>8; 00110 R += dR; 00111 if (R<0) R=0; 00112 00113 color = B; 00114 color |= (G << 5); 00115 color |= (R << 11); 00116 return color; 00117 } 00118 00119 void Display::tweenPalette(uint16_t* ram_pal, const uint16_t* pal_1, const uint16_t* pal_2, uint8_t factor) { 00120 for (uint8_t i = 0; i<16 ; i++) { 00121 ram_pal[i] = interpolateColor(pal_1[i],pal_2[i],factor); 00122 } 00123 } 00124 00125 00126
Generated on Tue Jul 12 2022 18:08:13 by 1.7.2