Implemented cBase64Encoder

This commit is contained in:
Klaus Schmidinger
2005-12-29 16:02:37 +01:00
parent cb428520e6
commit 61fefd00bf
4 changed files with 84 additions and 2 deletions

54
tools.c
View File

@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: tools.c 1.106 2005/12/29 11:20:28 kls Exp $
* $Id: tools.c 1.107 2005/12/29 16:02:37 kls Exp $
*/
#include "tools.h"
@@ -745,6 +745,58 @@ uchar *RgbToJpeg(uchar *Mem, int Width, int Height, int &Size, int Quality)
return jcd.mem;
}
// --- cBase64Encoder --------------------------------------------------------
const char *cBase64Encoder::b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
cBase64Encoder::cBase64Encoder(const uchar *Data, int Length, int MaxResult)
{
data = Data;
length = Length;
maxResult = MaxResult;
i = 0;
result = MALLOC(char, maxResult + 1);
}
cBase64Encoder::~cBase64Encoder()
{
free(result);
}
const char *cBase64Encoder::NextLine(void)
{
int r = 0;
while (i < length && r < maxResult - 3) {
result[r++] = b64[(data[i] >> 2) & 0x3F];
char c = (data[i] << 4) & 0x3F;
if (++i < length)
c |= (data[i] >> 4) & 0x0F;
result[r++] = b64[c];
if (i < length) {
c = (data[i] << 2) & 0x3F;
if (++i < length)
c |= (data[i] >> 6) & 0x03;
result[r++] = b64[c];
}
else {
i++;
result[r++] = '=';
}
if (i < length) {
c = data[i] & 0x3F;
result[r++] = b64[c];
}
else
result[r++] = '=';
i++;
}
if (r > 0) {
result[r] = 0;
return result;
}
return NULL;
}
// --- cReadLine -------------------------------------------------------------
cReadLine::cReadLine(void)