Exemple #1
0
static inline int
finddirsep(const GUTF8String &fname)
{
#if defined(WIN32)
    return fname.rcontains("\\/",0);
#elif defined(UNIX)
    return fname.rsearch('/',0);
#elif defined(macintosh)
    return fname.rcontains(":/",0);
#else
    return fname.rsearch('/',0);
#endif
}
Exemple #2
0
static inline int
finddirsep(const GUTF8String &fname)
{
#if defined(UNIX)
  return fname.rsearch('/',0);
#elif defined(WIN32) || defined(OS2)
  return fname.rcontains("\\/",0);
#elif defined(macintosh)
  return fname.rcontains(":/",0);
#else
#error "Define something here for your operating system"
#endif  
}
void
GIFFManager::add_chunk(GUTF8String name, const TArray<char> & data)
      // name is fully qualified name of the chunk TO BE INSERTED.
      //      it may contain brackets at the end to set the position
      // All the required chunks will be created
{
  DEBUG_MSG("GIFFManager::add_chunk(): adding plain chunk with name='" << name << "'\n");
  DEBUG_MAKE_INDENT(3);

  GUTF8String chunk_name;
  const int lastdot=name.rsearch('.');
  if(lastdot < 0)
  {
    chunk_name=name;
    name=name.substr(0,lastdot);
  }else
  {
    chunk_name=name.substr(lastdot+1,(unsigned int)-1);
  }

  int pos=-1;
  const int obracket=chunk_name.search('[');
  if (obracket >= 0)
  {
    const int cbracket=chunk_name.search(']',obracket+1);
    if (cbracket < 0)
      G_THROW( ERR_MSG("GIFFManager.unmatched") );
    if (name.length() > (unsigned int)(cbracket+1))
      G_THROW( ERR_MSG("GIFFManager.garbage") );
//    pos=atoi((const char *)chunk_name.substr(obracket+1,cbracket-obracket-1));
    pos = chunk_name.substr(obracket+1,cbracket-obracket-1).toInt();
    chunk_name=chunk_name.substr(0,obracket);
  }
  DEBUG_MSG("Creating new chunk with name " << chunk_name << "\n");
  GP<GIFFChunk> chunk;
  chunk=GIFFChunk::create(chunk_name, data);
  add_chunk(name, chunk, pos);
}
int
GIFFManager::get_chunks_number(const GUTF8String &name)
   // Returns the number of chunks with given fully qualified name
{
  DEBUG_MSG("GIFFManager::get_chunks_number(): name='" << name << "'\n");
  DEBUG_MAKE_INDENT(3);

  int retval;
  const int last_dot=name.rsearch('.');
  if (last_dot<0)
  {
    retval=top_level->get_chunks_number(name);
  }else if(!last_dot)
  {
    retval=(top_level->get_name()==name.substr(1,(unsigned int)-1))?1:0;
  }else
  {
    GP<GIFFChunk> chunk=get_chunk(name.substr(0,last_dot));
    retval=( chunk
      ?(chunk->get_chunks_number(name.substr(last_dot+1,(unsigned int)-1)))
      :0 );
  }
  return retval;
}
Exemple #5
0
void 
create_bg44_chunk(IFFByteStream &iff, const char *ckid, GUTF8String filespec)
{
  static GP<IFFByteStream> bg44iff;
  if (! bg44iff)
    {
      if (flag_contains_bg)
        DjVuPrintErrorUTF8("%s","djvumake: Duplicate BGxx chunk\n");
      int i=filespec.rsearch(':');
      for (int j=i+1; i>0 && j<(int)filespec.length(); j++)
        if (filespec[j] < '0' || filespec[j] > '9')
          i = -1;
      if (!i)
        G_THROW("djvumake: no filename specified in first BG44 specification");
      GUTF8String filename=(i<0)?filespec:GUTF8String(filespec, i);
      const GURL::Filename::UTF8 url(filename);
      const GP<ByteStream> gbs(ByteStream::create(url,"rb"));
      if(!gbs)
      {
        G_THROW("djvumake: no such file as"+filename);
      }
      bg44iff = IFFByteStream::create(gbs);
      GUTF8String chkid;
      bg44iff->get_chunk(chkid);
      if (chkid != "FORM:PM44" && chkid != "FORM:BM44")
        G_THROW("djvumake: BG44 file has incorrect format (wrong IFF header)");        
      if (i>=0)
        filespec = i+1+(const char *)filespec;
      else 
        filespec = "99";
    }
  else
    {
      if (filespec.length() && filespec[0]!=':')
        G_THROW("djvumake: filename specified in BG44 refinement");
      filespec = 1+(const char *)filespec;
    }
  const char *s=filespec;
  int nchunks = strtol((char *)s, (char **)&s, 10);
  if (nchunks<1 || nchunks>99)
    G_THROW("djvumake: invalid number of chunks in BG44 specification");    
  if (*s)
    G_THROW("djvumake: invalid BG44 specification (syntax error)");
  
  int flag = (nchunks>=99);
  GUTF8String chkid;
  while (nchunks-->0 && bg44iff->get_chunk(chkid))
    {
      if (chkid!="PM44" && chkid!="BM44")
        {
          DjVuPrintErrorUTF8("%s","djvumake: BG44 file contains unrecognized chunks (fixed)\n");
          nchunks += 1;
          bg44iff->close_chunk();
          continue;
        }
      GP<ByteStream> gmbs=ByteStream::create();
      ByteStream &mbs=*gmbs;
      mbs.copy(*(bg44iff->get_bytestream()));
      bg44iff->close_chunk();  
      mbs.seek(0);
      if (mbs.readall((void*)&primary, sizeof(primary)) != sizeof(primary))
        G_THROW("djvumake: BG44 file is corrupted (cannot read primary header)\n");    
      if (primary.serial == 0)
        {
          if (mbs.readall((void*)&secondary, sizeof(secondary)) != sizeof(secondary))
            G_THROW("djvumake: BG44 file is corrupted (cannot read secondary header)\n");    
          int iw = (secondary.xhi<<8) + secondary.xlo;
          int ih = (secondary.yhi<<8) + secondary.ylo;
          int red;
          for (red=1; red<=12; red++)
            if (iw==(w+red-1)/red && ih==(h+red-1)/red)
              break;
          flag_contains_bg = red;
          if (red>12)
            DjVuPrintErrorUTF8("%s","djvumake: BG44 subsampling is not in [1..12] range\n");
        }
      mbs.seek(0);
      iff.put_chunk(ckid);
      iff.copy(mbs);
      iff.close_chunk();
      flag = 1;
    }
  if (!flag)
    DjVuPrintErrorUTF8("%s","djvumake: no more chunks in BG44 file\n");
}