|
MHVLib
20111227
An efficiency oriented runtime library for AVR microcontrollers
|
00001 /* Copyright (c) 2011, Make, Hack, Void Inc 00002 * All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * * Redistributions of source code must retain the above copyright 00007 * notice, this list of conditions and the following disclaimer. 00008 * * Redistributions in binary form must reproduce the above copyright 00009 * notice, this list of conditions and the following disclaimer in the 00010 * documentation and/or other materials provided with the distribution. 00011 * * Neither the name of the Make, Hack, Void nor the 00012 * names of its contributors may be used to endorse or promote products 00013 * derived from this software without specific prior written permission. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00016 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00018 * DISCLAIMED. IN NO EVENT SHALL MAKE, HACK, VOID BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00020 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00021 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00022 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00024 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 */ 00026 00027 #ifndef MHV_GAMMACORRECT_H_ 00028 #define MHV_GAMMACORRECT_H_ 00029 00030 #include <inttypes.h> 00031 #include <math.h> 00032 #include <avr/pgmspace.h> 00033 00034 const uint8_t mhv_gammaValues[] PROGMEM = { 00035 0, 0, 0, 0, 0, 0, 0, 0, 00036 0, 0, 0, 0, 0, 0, 0, 0, 00037 0, 0, 0, 0, 0, 0, 1, 1, 00038 1, 1, 1, 1, 1, 1, 1, 1, 00039 1, 2, 2, 2, 2, 2, 2, 2, 00040 2, 3, 3, 3, 3, 3, 4, 4, 00041 4, 4, 4, 5, 5, 5, 5, 6, 00042 6, 6, 6, 7, 7, 7, 7, 8, 00043 8, 8, 9, 9, 9, 10, 10, 10, 00044 11, 11, 12, 12, 12, 13, 13, 14, 00045 14, 15, 15, 15, 16, 16, 17, 17, 00046 18, 18, 19, 19, 20, 20, 21, 22, 00047 22, 23, 23, 24, 25, 25, 26, 26, 00048 27, 28, 28, 29, 30, 30, 31, 32, 00049 33, 33, 34, 35, 36, 36, 37, 38, 00050 39, 40, 40, 41, 42, 43, 44, 45, 00051 46, 46, 47, 48, 49, 50, 51, 52, 00052 53, 54, 55, 56, 57, 58, 59, 60, 00053 61, 62, 63, 64, 65, 67, 68, 69, 00054 70, 71, 72, 73, 75, 76, 77, 78, 00055 80, 81, 82, 83, 85, 86, 87, 89, 00056 90, 91, 93, 94, 95, 97, 98, 99, 00057 101, 102, 104, 105, 107, 108, 110, 111, 00058 113, 114, 116, 117, 119, 121, 122, 124, 00059 125, 127, 129, 130, 132, 134, 135, 137, 00060 139, 141, 142, 144, 146, 148, 150, 151, 00061 153, 155, 157, 159, 161, 163, 165, 166, 00062 168, 170, 172, 174, 176, 178, 180, 182, 00063 184, 186, 189, 191, 193, 195, 197, 199, 00064 201, 204, 206, 208, 210, 212, 215, 217, 00065 219, 221, 224, 226, 228, 231, 233, 235, 00066 238, 240, 243, 245, 248, 250, 253, 255 00067 }; 00068 00069 00070 uint8_t mhv_calculatedGammaCorrect(uint8_t value); 00071 00072 /* Gamma correct a value via a lookup table 00073 * This uses less program memory than calculated value, and uses less clocks 00074 * param value the value to gamma correct 00075 * return the gamma corrected value 00076 */ 00077 inline uint8_t mhv_precalculatedGammaCorrect(uint8_t value) { 00078 return pgm_read_byte(mhv_gammaValues + value); 00079 } 00080 00081 #define MHV_PRECALCULATED_GAMMA_CORRECT mhv_precalculatedGammaCorrect 00082 00083 #endif /* MHV_GAMMACORRECT_H_ */