62 lines
1.1 KiB
C
Raw Normal View History

2021-01-29 12:31:58 +01:00
#pragma once
//
// FILE: gamma.h
// AUTHOR: Rob Tillaart
2022-11-08 17:03:54 +01:00
// VERSION: 0.3.1
2021-01-29 12:31:58 +01:00
// DATE: 2020-08-08
// PURPOSE: Arduino Library to efficiently hold a gamma lookup table
#include "Arduino.h"
2022-11-08 17:03:54 +01:00
#define GAMMA_LIB_VERSION (F("0.3.1"))
2021-12-18 17:16:37 +01:00
2022-11-08 17:03:54 +01:00
#define GAMMA_DEFAULT_SIZE 32
#define GAMMA_MAX_SIZE 256
2021-01-29 12:31:58 +01:00
class GAMMA
{
public:
2022-07-25 15:25:14 +02:00
GAMMA(uint16_t size = GAMMA_DEFAULT_SIZE);
~GAMMA();
// allocates memory
// sets default gamma = 2.8
2022-07-26 13:16:03 +02:00
// Returns false if allocation fails
bool begin();
2022-07-25 15:25:14 +02:00
// CORE
2022-07-26 13:16:03 +02:00
// Returns false if gamma <= 0
bool setGamma(float gamma);
2022-07-25 15:25:14 +02:00
float getGamma();
// access values with index operator
2022-07-26 13:16:03 +02:00
// index = 0 .. size
2022-07-25 15:25:14 +02:00
uint8_t operator[] (uint8_t index);
// META INFO
uint16_t size();
uint16_t distinct();
// DEBUG
2022-07-26 13:16:03 +02:00
bool dump(Stream *str = &Serial);
bool dumpArray(Stream *str = &Serial);
2021-01-29 12:31:58 +01:00
private:
uint8_t _shift = 0;
uint8_t _mask = 0;
uint16_t _size = 0;
uint8_t _interval = 0;
2022-07-26 13:16:03 +02:00
float _gamma = 1.0; // 1.0 == no gamma, linear.
2021-11-02 15:15:11 +01:00
uint8_t * _table = NULL;
2022-07-26 13:16:03 +02:00
float fastPow(float a, float b);
2021-01-29 12:31:58 +01:00
};
2021-11-02 15:15:11 +01:00
2021-01-29 12:31:58 +01:00
// -- END OF FILE --
2021-11-02 15:15:11 +01:00