Logo Search packages:      
Sourcecode: codeblocks version File versions  Download package

wxMemoryOutputStream * wxPdfParser::ASCII85Decode ( wxMemoryOutputStream *  osIn  )  [protected]

Decode a stream that has the ASCII85Decode filter.

Parameters:
osIn the input data
Returns:
the decoded data

Definition at line 99 of file pdfdecode.cpp.

References wxPdfTokenizer::IsWhitespace().

Referenced by GetStreamBytes().

{
  wxMemoryInputStream in(*osIn);
  wxMemoryOutputStream* osOut = new wxMemoryOutputStream();
  int state = 0;
  int chn[5];
  size_t inLength = in.GetSize();
  size_t k;
  for (k = 0; k < inLength; k++)
  {
    int ch = in.GetC() & 0xff;
    if (ch == '~')
      break;
    if (wxPdfTokenizer::IsWhitespace(ch))
      continue;
    if (ch == 'z' && state == 0)
    {
      osOut->PutC(0);
      osOut->PutC(0);
      osOut->PutC(0);
      osOut->PutC(0);
      continue;
    }
    if (ch < '!' || ch > 'u')
    {
      wxLogError(_T("wxPdfParser::ASCII85Decode: Illegal character."));
      osOut->Close();
      delete osOut;
      return NULL;
    }
    chn[state] = ch - '!';
    ++state;
    if (state == 5)
    {
      state = 0;
      int r = 0;
      for (int j = 0; j < 5; ++j)
      {
        r = r * 85 + chn[j];
      }
      osOut->PutC((char)((r >> 24) & 0xff));
      osOut->PutC((char)((r >> 16) & 0xff));
      osOut->PutC((char)((r >>  8) & 0xff));
      osOut->PutC((char)( r        & 0xff));
    }
  }
  int r = 0;
  if (state == 1)
  {
    wxLogError(_T("wxPdfParser::ASCII85Decode: Illegal length."));
    osOut->Close();
    delete osOut;
    return NULL;
  }
  if (state == 2)
  {
    r = chn[0] * 85 * 85 * 85 * 85 + chn[1] * 85 * 85 * 85;
    osOut->PutC((char)((r >> 24) & 0xff));
  }
  else if (state == 3)
  {
    r = chn[0] * 85 * 85 * 85 * 85 + chn[1] * 85 * 85 * 85  + chn[2] * 85 * 85;
    osOut->PutC((char)((r >> 24) & 0xff));
    osOut->PutC((char)((r >> 16) & 0xff));
  }
  else if (state == 4)
  {
    r = chn[0] * 85 * 85 * 85 * 85 + chn[1] * 85 * 85 * 85  + chn[2] * 85 * 85  + chn[3] * 85 ;
    osOut->PutC((char)((r >> 24) & 0xff));
    osOut->PutC((char)((r >> 16) & 0xff));
    osOut->PutC((char)((r >>  8) & 0xff));
  }

  osOut->Close();
  return osOut;
}


Generated by  Doxygen 1.6.0   Back to index