diff options
| -rw-r--r-- | CONTRIBUTORS | 5 | ||||
| -rw-r--r-- | HISTORY | 2 | ||||
| -rw-r--r-- | tools.c | 54 | ||||
| -rw-r--r-- | tools.h | 25 | 
4 files changed, 84 insertions, 2 deletions
| diff --git a/CONTRIBUTORS b/CONTRIBUTORS index df7deef0..845cf917 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1565,3 +1565,8 @@ Christof Steininger <christof.steininger@t-online.de>  Kendy Kutzner <kutzner@ira.uka.de>   for making the version number of EPG events be stored in the epg.data file + +Bob Withers <bwit@pobox.com> + for publishing a Base64 encoder at http://www.ruffboy.com/download.htm + (http://www.ruffboy.com/code/Base64.zip), part of which was used when writing + the cBase64Encoder class @@ -4017,3 +4017,5 @@ Video Disk Recorder Revision History    function cDevice::GrabImageFile() can be used to write the grabbed image    directly to a file. Plugins that used the old version of cDevice::GrabImage()    need to be adapted to the new interface. +- The new class cBase64Encoder (see tools.h) can be used to encode data in +  base64 (thanks to Bob Withers for publishing his Base64 class). @@ -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) @@ -4,7 +4,7 @@   * See the main source file 'vdr.c' for copyright information and   * how to reach the author.   * - * $Id: tools.h 1.86 2005/12/29 11:09:43 kls Exp $ + * $Id: tools.h 1.87 2005/12/29 15:48:46 kls Exp $   */  #ifndef __TOOLS_H @@ -131,6 +131,29 @@ uchar *RgbToJpeg(uchar *Mem, int Width, int Height, int &Size, int Quality = 100      ///< the result and has to delete it once it is no longer needed.      ///< The result may be NULL in case of an error. +class cBase64Encoder { +private: +  const uchar *data; +  int length; +  int maxResult; +  int i; +  char *result; +  static const char *b64; +public: +  cBase64Encoder(const uchar *Data, int Length, int MaxResult = 64); +      ///< Sets up a new base 64 encoder for the given Data, with the given Length. +      ///< Data will not be copied and must be valid for the entire lifetime of the +      ///< encoder. MaxResult defines the maximum number of characters in any +      ///< result line. The resulting lines may be shorter than MaxResult in case +      ///< its value is not a multiple of 4. +  ~cBase64Encoder(); +  const char *NextLine(void); +      ///< Returns the next line of encoded data (terminated by '\0'), or NULL if +      ///< there is no more encoded data. The caller must call NextLine() and process +      ///< each returned line until NULL is returned, in order to get the entire +      ///< data encoded. +  }; +  class cTimeMs {  private:    uint64 begin; | 
