void
readHeader (const char fileName[])
{
    //
    // Read an image's header from a file, and if the header
    // contains comments and camera transformation attributes,
    // print the values of those attributes.
    //
    //	- open the file
    //	- get the file header
    //	- look for the attributes
    //

    RgbaInputFile file (fileName);

    const StringAttribute *comments =
        file.header().findTypedAttribute <StringAttribute> ("comments");

    const M44fAttribute *cameraTransform =
        file.header().findTypedAttribute <M44fAttribute> ("cameraTransform");

    if (comments)
        cout << "comments\n   " << comments->value() << endl;

    if (cameraTransform)
        cout << "cameraTransform\n" << cameraTransform->value() << flush;
}
Esempio n. 2
0
bool ImageIO::readImage(const QString& filePath,
                        Array<Rgba>& pixels,
                        int& width,
                        int &height)
{
    RgbaInputFile* in;
    try
    {
        QString remapped = remapFilePath(filePath);
        in = new RgbaInputFile(remapped.toStdString().c_str());
    }
    catch (const std::exception &e)
    {
        qWarning() << e.what();
        return false;
    }

    Header header = in->header();

    Box2i &dataWindow = header.dataWindow();
    int dw = dataWindow.max.x - dataWindow.min.x + 1;
    int dh = dataWindow.max.y - dataWindow.min.y + 1;
    int dx = dataWindow.min.x;
    int dy = dataWindow.min.y;

    pixels.resizeErase(dw * dh);
    in->setFrameBuffer(pixels - dx - dy * dw, 1, dw);

    try
    {
        in->readPixels (dataWindow.min.y, dataWindow.max.y);
    }
    catch (const std::exception &e)
    {
        delete in;
        qWarning() << e.what();
        return false;
    }

    width = dw;
    height = dh;

    delete in;
    return true;
}
Esempio n. 3
0
void
exrCtlExr (const char inFileName[],
	   const char outFileName[],
	   const std::vector<std::string> &transformNames,
	   const AttrMap &extraAttrs,
	   int numThreads,
	   bool verbose)
{
    setGlobalThreadCount (numThreads);

    //
    // Read the input file
    //

    if (verbose)
	cout << "reading file " << inFileName << endl;

    RgbaInputFile in (inFileName);
    const Box2i &dw = in.dataWindow();
    int w = dw.max.x - dw.min.x + 1;
    int h = dw.max.y - dw.min.y + 1;

    Array2D<Rgba> inPixels (h, w);

    in.setFrameBuffer (&inPixels[0][0] - dw.min.x - dw.min.y * w, 1, w);
    in.readPixels (dw.min.y, dw.max.y);

    //
    // Apply the CTL transforms to the R, G and B channels of the input file
    //

    if (verbose)
    {
	cout << "applying CTL transforms:";

	for (int i = 0; i < transformNames.size(); ++i)
	    cout << " " << transformNames[i];

	cout << endl;
    }

    Header outHeader = in.header();
    Array2D<Rgba> outPixels (h, w);

    applyCtlExrToExr (in.header(), outHeader,
		      inPixels, outPixels,
		      w, h,
		      transformNames,
		      extraAttrs);

    //
    // Just in case one of the CTL transforms decided to mess
    // with the data window in the output header, avoid a crash
    // by resetting the data window to its original value.
    //

    outHeader.dataWindow() = in.header().dataWindow();

    //
    // If the input pixels have an A channel, copy it into
    // the output pixels.
    //

    if (in.channels() & WRITE_A)
    {
	const Rgba *inPtr = &inPixels[0][0];
	Rgba *outPtr = &outPixels[0][0];
	size_t numPixels = w * h;

	for (size_t i = 0; i < numPixels; ++i)
	    (outPtr++)->a = (inPtr++)->a;
    }

    //
    // Write the output file
    //

    if (verbose)
	cout << "writing file " << outFileName << endl;

    RgbaOutputFile out (outFileName, outHeader, in.channels());
    out.setFrameBuffer (&outPixels[0][0] - dw.min.x - dw.min.y * w, 1, w);
    out.writePixels (h);
}
Esempio n. 4
0
void
exrToDpx (const char exrFileName[],
	  const char dpxFileName[],
	  std::vector<std::string> transformNames,
	  bool verbose)
{
    //
    // Read the OpenEXR file
    //

    if (verbose)
	cout << "reading file " << exrFileName << endl;

    RgbaInputFile in (exrFileName);
    Box2i dw = in.dataWindow();
    unsigned int width  = (unsigned int) (dw.max.x - dw.min.x + 1);
    unsigned int height = (unsigned int) (dw.max.y - dw.min.y + 1);

    Array2D<Rgba> pixels (height, width);
    in.setFrameBuffer (&pixels[0][0] - dw.min.x - dw.min.y * width, 1, width);
    in.readPixels (dw.min.y, dw.max.y);

    //
    // Apply the CTL transforms
    //

    if (verbose)
    {
	cout << "applyging CTL transforms:";

	for (int i = 0; i < transformNames.size(); ++i)
	    cout << " " << transformNames[i];

	cout << endl;
    }

    applyCtlExrToDpx (transformNames,
		      in.header(),
		      pixels,
		      width, height,
		      pixels);

    //
    // Write the DPX file
    //

    if (verbose)
	cout << "writing file " << dpxFileName << endl;

    ofstream out (dpxFileName, ios_base::binary);

    if (!out)
    {
	THROW_ERRNO ("Cannot open file " << dpxFileName << " "
		     "for writing (%T).");
    }

    writeHeader (out, dpxFileName, width, height);
    writePixels (out, dpxFileName, width, height, pixels);

    if (verbose)
	cout << "done" << endl;
}