2010-08-09 13:28:56 +00:00
|
|
|
#ifndef NALL_BASE64_HPP
|
|
|
|
#define NALL_BASE64_HPP
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
|
|
|
|
namespace nall {
|
Update to v084r03 release.
(r02 was not posted to the WIP thread)
byuu says:
Internally, all color is processed with 30-bit precision. The filters
also operate at 30-bit depth.
There's a new config file setting, video.depth, which defaults to 24.
This causes the final output to downsample to 24-bit, as most will
require.
If you set it to 30-bit, the downsampling will not occur, and bsnes will
ask ruby for a 30-bit surface. If you don't have one available, you're
going to get bad colors. Or maybe even a crash with OpenGL.
I don't yet have detection code to make sure you have an appropriate
visual in place.
30-bit mode will really only work if you are running Linux, running Xorg
at Depth 30, use the OpenGL or XShm driver, have an nVidia Quadro or AMD
FireGL card with the official drivers, and have a 30-bit capable
monitor.
Lots of planning and work for very little gain here, but it's nice that
it's finally finished.
Oh, I had to change the contrast/brightness formulas a tiny bit, but
they still work and look nice.
2011-12-03 03:22:54 +00:00
|
|
|
struct base64 {
|
2010-08-09 13:28:56 +00:00
|
|
|
static bool encode(char *&output, const uint8_t* input, unsigned inlength) {
|
|
|
|
output = new char[inlength * 8 / 6 + 6]();
|
|
|
|
|
|
|
|
unsigned i = 0, o = 0;
|
|
|
|
while(i < inlength) {
|
|
|
|
switch(i % 3) {
|
|
|
|
case 0: {
|
|
|
|
output[o++] = enc(input[i] >> 2);
|
|
|
|
output[o] = enc((input[i] & 3) << 4);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 1: {
|
|
|
|
uint8_t prev = dec(output[o]);
|
|
|
|
output[o++] = enc(prev + (input[i] >> 4));
|
|
|
|
output[o] = enc((input[i] & 15) << 2);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
uint8_t prev = dec(output[o]);
|
|
|
|
output[o++] = enc(prev + (input[i] >> 6));
|
|
|
|
output[o++] = enc(input[i] & 63);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool decode(uint8_t *&output, unsigned &outlength, const char *input) {
|
|
|
|
unsigned inlength = strlen(input), infix = 0;
|
|
|
|
output = new uint8_t[inlength]();
|
|
|
|
|
|
|
|
unsigned i = 0, o = 0;
|
|
|
|
while(i < inlength) {
|
|
|
|
uint8_t x = dec(input[i]);
|
|
|
|
|
|
|
|
switch(i++ & 3) {
|
|
|
|
case 0: {
|
|
|
|
output[o] = x << 2;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 1: {
|
|
|
|
output[o++] |= x >> 4;
|
|
|
|
output[o] = (x & 15) << 4;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 2: {
|
|
|
|
output[o++] |= x >> 2;
|
|
|
|
output[o] = (x & 3) << 6;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case 3: {
|
|
|
|
output[o++] |= x;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
outlength = o;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static char enc(uint8_t n) {
|
2011-09-22 00:03:11 +00:00
|
|
|
//base64 for URL encodings
|
2010-08-09 13:28:56 +00:00
|
|
|
static char lookup_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
|
|
return lookup_table[n & 63];
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t dec(char n) {
|
|
|
|
if(n >= 'A' && n <= 'Z') return n - 'A';
|
|
|
|
if(n >= 'a' && n <= 'z') return n - 'a' + 26;
|
|
|
|
if(n >= '0' && n <= '9') return n - '0' + 52;
|
|
|
|
if(n == '-') return 62;
|
|
|
|
if(n == '_') return 63;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|