openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Openexr-devel] Read OpenEXR from memory data source ?


From: Paul Schneider
Subject: Re: [Openexr-devel] Read OpenEXR from memory data source ?
Date: Sun, 6 Mar 2005 14:04:38 -0800


Hi, Gernot,

it sounds like the buffer you're passing doesn't contain valid EXR data - that error means that it tried to read the "magic number" from the beginning of the stream, and it wasn't the correct magic number. See ImfHeader.cpp line 804 for where this error occurs.

Where are you getting the stream from? The bytes in your memory buffer should be identical to the bytes of an EXR file on disk. Also, I think that the EXR library expects the input stream to be little-endian - you don't happen to be running this on a big-endian machine, do you?

This would be a good way of testing your class:

char*  buf;
FILE* file;
int size;

// open a known-good EXR file on disk
file = fopen (path_to_exr_file, "rb");

// see how big it is
fseek (file, 0, SEEK_END);
size = ftell (file);
fseek (file, 0, SEEK_START);

// read the entire thing into a buffer
buf = new char[size];
fread (buf, size, 1, file);
fclose (file);

// read the EXR image data out of the buffer
Mem_IStream stream (buf, size);
Imf::InputFile input (stream);

// allocate framebuffer, call readPixels(), etc.
// ...



On Mar 6, 2005, at 1:19 PM, Gernot Ziegler wrote:

Hej !

I am currently implementing an OpenEXR input plugin and would need to read
from a memory source that is defined in the call:

load_openexr(unsigned char *mem, int size)

So far, I have implemented a Mem_IStream (see code below), but the problem
is that I can't get past the filename check -
OpenEXR-load: testing input
Cannot read image file "dummy". File is not an image file.

Did I miss something here ?

IStream should by design be able to read from memory, right ?

Hints are welcome :-)

----
class Mem_IStream: public IStream
{
 public:

  Mem_IStream (unsigned char *exrbuf, int exrsize):
IStream("dummy"), _exrpos (0), _exrsize(exrsize) { _exrbuf = exrbuf;
}

  virtual bool  read (char c[], int n);
  virtual Int64 tellg ();
  virtual void  seekg (Int64 pos);
  virtual void  clear ();

 private:

  Int64 _exrpos;
  Int64 _exrsize;
  unsigned char *_exrbuf;
};

bool Mem_IStream::read (char c[], int n)
{
  if (n + _exrpos < _exrsize)
    {
      memcpy(c, (void *)(_exrbuf[_exrpos]), n);
      _exrpos += n;
      return true;
    }
  else
    return false;
}

Int64 Mem_IStream::tellg ()
{
  return _exrpos;
}

void Mem_IStream::seekg (Int64 pos)
{
  _exrpos = pos;
}

void Mem_IStream::clear ()
{
}


Servus,
  Gernot

-- T----------------------------W-E-L-C-O-M- E------------------------------T | The Austria <=> Sweden <=> Germany <=> Netherlands connection..... H O http://www.mpi-sb.mpg.de/~gziegler | http://lysator.liu.se/~gz E \------------------------------F-U-T-U-R- E------------------------------/


_______________________________________________
Openexr-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/openexr-devel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]