Casio fx-CG series port (#324)

* Initial test - working on Linux

* Try to make it work with liba

* Stop using liba and the filesystem

* IT WORKS

* Key input, full res, fix some of the crashes

* Fix the hang when doing calculations

* Add some more key mappings

* Fix the square root issue

* Icons

* Better key mappings, brightness control, better gamma correction, more effficient framebuffer

* Cleanup stage 1

* Cleanup stage 2

* Make the build system build a g3a

* Make it not exit when you press the menu button

* Add Casio port to README

* Use omega-master instead of omega-dev

* Fix mistake with cherry-picking in the README

* Fix internal storage crash

* Fix compile error on Numworks calculators

* Upsilon branding

* Sharper icon

* Make the CI work

* Add power off and improve menu

* Map Alpha + up/down to the brightness shortcut

* Add missing file

* Fix web CI build

* Revert "Fix web CI build"

This reverts commit f19657d9fc.

* Change "prizm" to "fxcg"

* Add FASTLOAD option for Add-in Push

* Add some charatcers to the catalog on Casio and improve key mappings

* Build with -Os -flto

* Disable LTO for now as it's causing crashes

* Put back the fonts I accidently changed

I'd like to add an option for this though as I prefer the ones from Epsilon
This commit is contained in:
circuit10
2023-05-10 17:28:18 +01:00
committed by GitHub
parent aadcd37f31
commit b44a95a9b3
77 changed files with 1617 additions and 49 deletions

View File

@@ -2,6 +2,7 @@
#define KANDINSKY_POSTPROCESS_GAMMA_CONTEXT_H
#include <kandinsky/postprocess_context.h>
#include <stdint.h>
class KDPostProcessGammaContext : public KDPostProcessContext {
public:
@@ -13,7 +14,16 @@ private:
void pushRect(KDRect rect, const KDColor * pixels) override;
void pushRectUniform(KDRect rect, KDColor color) override;
void pullRect(KDRect rect, KDColor * pixels) override;
KDColor correctColor(KDColor color);
int m_redGamma, m_greenGamma, m_blueGamma;
// Lookup tables to do gamma correction
// 5 bits of red
uint8_t m_redGammaTable[32];
// 6 bits of green
uint8_t m_greenGammaTable[64];
// 5 bits of blue
uint8_t m_blueGammaTable[32];
void updateGammaTables();
};
#endif

View File

@@ -1,6 +1,8 @@
#include <kandinsky/color.h>
#include <kandinsky/postprocess_gamma_context.h>
#include <ion.h>
#include <math.h>
#include <stdint.h>
constexpr int MaxGammaStates = 7;
constexpr float MaxGammaGamut = 0.75;
@@ -13,8 +15,28 @@ constexpr int clampGamma(int gamma) {
return gamma < -MaxGammaStates ? -MaxGammaStates : (gamma > MaxGammaStates ? MaxGammaStates : gamma);
}
void KDPostProcessGammaContext::updateGammaTables() {
const float redGamma = toGamma(m_redGamma);
const float greenGamma = toGamma(m_greenGamma);
const float blueGamma = toGamma(m_blueGamma);
for (int i = 0; i < 32; i++) {
uint8_t r = (uint8_t)(powf((i << 3) / 255.f, redGamma) * 255);
m_redGammaTable[i] = r >> 3;
}
for (int i = 0; i < 64; i++) {
uint8_t g = (uint8_t)(powf((i << 2) / 255.f, greenGamma) * 255);
m_greenGammaTable[i] = g >> 2;
}
for (int i = 0; i < 32; i++) {
uint8_t b = (uint8_t)(powf((i << 3 )/ 255.f, blueGamma) * 255);
m_blueGammaTable[i] = b >> 3;
}
}
KDPostProcessGammaContext::KDPostProcessGammaContext() :
m_redGamma(0), m_greenGamma(0), m_blueGamma(0) {}
m_redGamma(0), m_greenGamma(0), m_blueGamma(0) {
updateGammaTables();
}
void KDPostProcessGammaContext::gamma(int& red, int& green, int& blue) {
red = m_redGamma;
@@ -32,12 +54,20 @@ void KDPostProcessGammaContext::setGamma(int red, int green, int blue) {
m_redGamma = clampGamma(red);
m_greenGamma = clampGamma(green);
m_blueGamma = clampGamma(blue);
updateGammaTables();
}
KDColor KDPostProcessGammaContext::correctColor(KDColor color) {
uint8_t r5 = (((uint16_t )color)>>11)&0x1F;
r5 = m_redGammaTable[r5];
uint8_t g6 = (((uint16_t )color)>>5)&0x3F;
g6 = m_greenGammaTable[g6];
uint8_t b5 = ((uint16_t )color)&0x1F;
b5 = m_blueGammaTable[b5];
return KDColor::RGB16(r5<<11 | g6<<5 | b5);
}
void KDPostProcessGammaContext::pushRect(KDRect rect, const KDColor * pixels) {
const float redGamma = toGamma(m_redGamma);
const float greenGamma = toGamma(m_greenGamma);
const float blueGamma = toGamma(m_blueGamma);
KDColor workingBuffer[rect.width()];
for (KDCoordinate y = 0; y < rect.height(); y++) {
@@ -45,10 +75,7 @@ void KDPostProcessGammaContext::pushRect(KDRect rect, const KDColor * pixels) {
for (KDCoordinate x = 0; x < rect.width(); x++) {
const KDColor color = pixels[y*rect.width()+x];
const KDColor result = KDColor::RGB888(
(uint8_t)(powf(color.red()/255.f, redGamma)*255),
(uint8_t)(powf(color.green()/255.f, greenGamma)*255),
(uint8_t)(powf(color.blue()/255.f, blueGamma)*255));
const KDColor result = correctColor(color);
workingBuffer[x] = result;
}
KDPostProcessContext::pushRect(workingRect, workingBuffer);
@@ -56,15 +83,7 @@ void KDPostProcessGammaContext::pushRect(KDRect rect, const KDColor * pixels) {
}
void KDPostProcessGammaContext::pushRectUniform(KDRect rect, KDColor color) {
const float redGamma = toGamma(m_redGamma);
const float greenGamma = toGamma(m_greenGamma);
const float blueGamma = toGamma(m_blueGamma);
const KDColor result = KDColor::RGB888(
(uint8_t)(powf(color.red()/255.f, redGamma)*255),
(uint8_t)(powf(color.green()/255.f, greenGamma)*255),
(uint8_t)(powf(color.blue()/255.f, blueGamma)*255));
KDPostProcessContext::pushRectUniform(rect, result);
KDPostProcessContext::pushRectUniform(rect, correctColor(color));
}
void KDPostProcessGammaContext::pullRect(KDRect rect, KDColor * pixels) {