summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/tools.c b/tools.c
index 1f474c8b..4bcf110f 100644
--- a/tools.c
+++ b/tools.c
@@ -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)