Path: blob/master/3rdparty/openexr/IlmImf/ImfCRgbaFile.cpp
16337 views
///////////////////////////////////////////////////////////////////////////1//2// Copyright (c) 2004, Industrial Light & Magic, a division of Lucas3// Digital Ltd. LLC4//5// All rights reserved.6//7// Redistribution and use in source and binary forms, with or without8// modification, are permitted provided that the following conditions are9// met:10// * Redistributions of source code must retain the above copyright11// notice, this list of conditions and the following disclaimer.12// * Redistributions in binary form must reproduce the above13// copyright notice, this list of conditions and the following disclaimer14// in the documentation and/or other materials provided with the15// distribution.16// * Neither the name of Industrial Light & Magic nor the names of17// its contributors may be used to endorse or promote products derived18// from this software without specific prior written permission.19//20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31//32///////////////////////////////////////////////////////////////////////////333435//-----------------------------------------------------------------------------36//37// C interface to C++ classes Imf::RgbaOutputFile and Imf::RgbaInputFile38//39//-----------------------------------------------------------------------------404142#include <ImfCRgbaFile.h>43#include <ImfRgbaFile.h>44#include <ImfTiledRgbaFile.h>45#include <ImfIntAttribute.h>46#include <ImfFloatAttribute.h>47#include <ImfDoubleAttribute.h>48#include <ImfStringAttribute.h>49#include <ImfBoxAttribute.h>50#include <ImfVecAttribute.h>51#include <ImfMatrixAttribute.h>52#include <ImfChannelList.h>53#include <ImfLut.h>54#include "half.h"55#include <string.h>5657using Imath::Box2i;58using Imath::Box2f;59using Imath::V2i;60using Imath::V2f;61using Imath::V3i;62using Imath::V3f;63using Imath::M33f;64using Imath::M44f;656667namespace {686970const int MAX_ERR_LENGTH = 1024;71char errorMessage[MAX_ERR_LENGTH];727374void75setErrorMessage (const std::exception &e)76{77strncpy (errorMessage, e.what(), MAX_ERR_LENGTH - 1);78errorMessage[MAX_ERR_LENGTH - 1] = 0;79}808182inline Imf::Header *83header (ImfHeader *hdr)84{85return (Imf::Header *)(hdr);86}878889inline const Imf::Header *90header (const ImfHeader *hdr)91{92return (const Imf::Header *)(hdr);93}949596inline Imf::RgbaOutputFile *97outfile (ImfOutputFile *out)98{99return (Imf::RgbaOutputFile *) out;100}101102103inline const Imf::RgbaOutputFile *104outfile (const ImfOutputFile *out)105{106return (const Imf::RgbaOutputFile *) out;107}108109110inline Imf::TiledRgbaOutputFile *111outfile (ImfTiledOutputFile *out)112{113return (Imf::TiledRgbaOutputFile *) out;114}115116117inline const Imf::TiledRgbaOutputFile *118outfile (const ImfTiledOutputFile *out)119{120return (const Imf::TiledRgbaOutputFile *) out;121}122123124inline Imf::RgbaInputFile *125infile (ImfInputFile *in)126{127return (Imf::RgbaInputFile *) in;128}129130131inline const Imf::RgbaInputFile *132infile (const ImfInputFile *in)133{134return (const Imf::RgbaInputFile *) in;135}136137138inline Imf::TiledRgbaInputFile *139infile (ImfTiledInputFile *in)140{141return (Imf::TiledRgbaInputFile *) in;142}143144145inline const Imf::TiledRgbaInputFile *146infile (const ImfTiledInputFile *in)147{148return (const Imf::TiledRgbaInputFile *) in;149}150151152} // namespace153154155void156ImfFloatToHalf (float f, ImfHalf *h)157{158*h = half(f).bits();159}160161162void163ImfFloatToHalfArray (int n, const float f[/*n*/], ImfHalf h[/*n*/])164{165for (int i = 0; i < n; ++i)166h[i] = half(f[i]).bits();167}168169170float171ImfHalfToFloat (ImfHalf h)172{173return float (*((half *)&h));174}175176177void178ImfHalfToFloatArray (int n, const ImfHalf h[/*n*/], float f[/*n*/])179{180for (int i = 0; i < n; ++i)181f[i] = float (*((half *)(h + i)));182}183184185ImfHeader *186ImfNewHeader (void)187{188try189{190return (ImfHeader *) new Imf::Header;191}192catch (const std::exception &e)193{194setErrorMessage (e);195return 0;196}197}198199200void201ImfDeleteHeader (ImfHeader *hdr)202{203delete header (hdr);204}205206207ImfHeader *208ImfCopyHeader (const ImfHeader *hdr)209{210try211{212return (ImfHeader *) new Imf::Header (*header (hdr));213}214catch (const std::exception &e)215{216setErrorMessage (e);217return 0;218}219}220221222void223ImfHeaderSetDisplayWindow (ImfHeader *hdr,224int xMin, int yMin,225int xMax, int yMax)226{227header(hdr)->displayWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));228}229230231void232ImfHeaderDisplayWindow (const ImfHeader *hdr,233int *xMin, int *yMin,234int *xMax, int *yMax)235{236const Box2i dw = header(hdr)->displayWindow();237*xMin = dw.min.x;238*yMin = dw.min.y;239*xMax = dw.max.x;240*yMax = dw.max.y;241}242243244void245ImfHeaderSetDataWindow (ImfHeader *hdr,246int xMin, int yMin,247int xMax, int yMax)248{249header(hdr)->dataWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));250}251252253void254ImfHeaderDataWindow (const ImfHeader *hdr,255int *xMin, int *yMin,256int *xMax, int *yMax)257{258const Box2i dw = header(hdr)->dataWindow();259*xMin = dw.min.x;260*yMin = dw.min.y;261*xMax = dw.max.x;262*yMax = dw.max.y;263}264265266void267ImfHeaderSetPixelAspectRatio (ImfHeader *hdr, float pixelAspectRatio)268{269header(hdr)->pixelAspectRatio() = pixelAspectRatio;270}271272273float274ImfHeaderPixelAspectRatio (const ImfHeader *hdr)275{276return header(hdr)->pixelAspectRatio();277}278279280void281ImfHeaderSetScreenWindowCenter (ImfHeader *hdr, float x, float y)282{283header(hdr)->screenWindowCenter() = V2f (x, y);284}285286287void288ImfHeaderScreenWindowCenter (const ImfHeader *hdr, float *x, float *y)289{290const V2i &swc = header(hdr)->screenWindowCenter();291*x = swc.x;292*y = swc.y;293}294295296void297ImfHeaderSetScreenWindowWidth (ImfHeader *hdr, float width)298{299header(hdr)->screenWindowWidth() = width;300}301302303float304ImfHeaderScreenWindowWidth (const ImfHeader *hdr)305{306return header(hdr)->screenWindowWidth();307}308309310void311ImfHeaderSetLineOrder (ImfHeader *hdr, int lineOrder)312{313header(hdr)->lineOrder() = Imf::LineOrder (lineOrder);314}315316317int318ImfHeaderLineOrder (const ImfHeader *hdr)319{320return header(hdr)->lineOrder();321}322323324void325ImfHeaderSetCompression (ImfHeader *hdr, int compression)326{327header(hdr)->compression() = Imf::Compression (compression);328}329330331int332ImfHeaderCompression (const ImfHeader *hdr)333{334return header(hdr)->compression();335}336337338int339ImfHeaderSetIntAttribute (ImfHeader *hdr, const char name[], int value)340{341try342{343if (header(hdr)->find(name) == header(hdr)->end())344{345header(hdr)->insert (name, Imf::IntAttribute (value));346}347else348{349header(hdr)->typedAttribute<Imf::IntAttribute>(name).value() =350value;351}352353return 1;354}355catch (const std::exception &e)356{357setErrorMessage (e);358return 0;359}360}361362363int364ImfHeaderIntAttribute (const ImfHeader *hdr, const char name[], int *value)365{366try367{368*value = header(hdr)->typedAttribute<Imf::IntAttribute>(name).value();369return 1;370}371catch (const std::exception &e)372{373setErrorMessage (e);374return 0;375}376}377378379int380ImfHeaderSetFloatAttribute (ImfHeader *hdr, const char name[], float value)381{382try383{384if (header(hdr)->find(name) == header(hdr)->end())385{386header(hdr)->insert (name, Imf::FloatAttribute (value));387}388else389{390header(hdr)->typedAttribute<Imf::FloatAttribute>(name).value() =391value;392}393394return 1;395}396catch (const std::exception &e)397{398setErrorMessage (e);399return 0;400}401}402403404int405ImfHeaderSetDoubleAttribute (ImfHeader *hdr, const char name[], double value)406{407try408{409if (header(hdr)->find(name) == header(hdr)->end())410{411header(hdr)->insert (name, Imf::DoubleAttribute (value));412}413else414{415header(hdr)->typedAttribute<Imf::DoubleAttribute>(name).value() =416value;417}418419return 1;420}421catch (const std::exception &e)422{423setErrorMessage (e);424return 0;425}426}427428429int430ImfHeaderFloatAttribute (const ImfHeader *hdr, const char name[], float *value)431{432try433{434*value = header(hdr)->typedAttribute<Imf::FloatAttribute>(name).value();435return 1;436}437catch (const std::exception &e)438{439setErrorMessage (e);440return 0;441}442}443444445int446ImfHeaderDoubleAttribute (const ImfHeader *hdr,447const char name[],448double *value)449{450try451{452*value = header(hdr)->453typedAttribute<Imf::DoubleAttribute>(name).value();454455return 1;456}457catch (const std::exception &e)458{459setErrorMessage (e);460return 0;461}462}463464465int466ImfHeaderSetStringAttribute (ImfHeader *hdr,467const char name[],468const char value[])469{470try471{472if (header(hdr)->find(name) == header(hdr)->end())473{474header(hdr)->insert (name, Imf::StringAttribute (value));475}476else477{478header(hdr)->typedAttribute<Imf::StringAttribute>(name).value() =479value;480}481482return 1;483}484catch (const std::exception &e)485{486setErrorMessage (e);487return 0;488}489}490491492int493ImfHeaderStringAttribute (const ImfHeader *hdr,494const char name[],495const char **value)496{497try498{499*value = header(hdr)->500typedAttribute<Imf::StringAttribute>(name).value().c_str();501502return 1;503}504catch (const std::exception &e)505{506setErrorMessage (e);507return 0;508}509}510511512int513ImfHeaderSetBox2iAttribute (ImfHeader *hdr,514const char name[],515int xMin, int yMin,516int xMax, int yMax)517{518try519{520Box2i box (V2i (xMin, yMin), V2i (xMax, yMax));521522if (header(hdr)->find(name) == header(hdr)->end())523{524header(hdr)->insert (name, Imf::Box2iAttribute (box));525}526else527{528header(hdr)->typedAttribute<Imf::Box2iAttribute>(name).value() =529box;530}531532return 1;533}534catch (const std::exception &e)535{536setErrorMessage (e);537return 0;538}539}540541542int543ImfHeaderBox2iAttribute (const ImfHeader *hdr,544const char name[],545int *xMin, int *yMin,546int *xMax, int *yMax)547{548try549{550const Box2i &box =551header(hdr)->typedAttribute<Imf::Box2iAttribute>(name).value();552553*xMin = box.min.x;554*yMin = box.min.y;555*xMax = box.max.x;556*yMax = box.max.y;557558return 1;559}560catch (const std::exception &e)561{562setErrorMessage (e);563return 0;564}565}566567568int569ImfHeaderSetBox2fAttribute (ImfHeader *hdr,570const char name[],571float xMin, float yMin,572float xMax, float yMax)573{574try575{576Box2f box (V2f (xMin, yMin), V2f (xMax, yMax));577578if (header(hdr)->find(name) == header(hdr)->end())579{580header(hdr)->insert (name, Imf::Box2fAttribute (box));581}582else583{584header(hdr)->typedAttribute<Imf::Box2fAttribute>(name).value() =585box;586}587588return 1;589}590catch (const std::exception &e)591{592setErrorMessage (e);593return 0;594}595}596597598int599ImfHeaderBox2fAttribute (const ImfHeader *hdr,600const char name[],601float *xMin, float *yMin,602float *xMax, float *yMax)603{604try605{606const Box2f &box =607header(hdr)->typedAttribute<Imf::Box2fAttribute>(name).value();608609*xMin = box.min.x;610*yMin = box.min.y;611*xMax = box.max.x;612*yMax = box.max.y;613614return 1;615}616catch (const std::exception &e)617{618setErrorMessage (e);619return 0;620}621}622623624int625ImfHeaderSetV2iAttribute (ImfHeader *hdr,626const char name[],627int x, int y)628{629try630{631V2i v (x, y);632633if (header(hdr)->find(name) == header(hdr)->end())634header(hdr)->insert (name, Imf::V2iAttribute (v));635else636header(hdr)->typedAttribute<Imf::V2iAttribute>(name).value() = v;637638return 1;639}640catch (const std::exception &e)641{642setErrorMessage (e);643return 0;644}645}646647648int649ImfHeaderV2iAttribute (const ImfHeader *hdr,650const char name[],651int *x, int *y)652{653try654{655const V2i &v =656header(hdr)->typedAttribute<Imf::V2iAttribute>(name).value();657658*x = v.x;659*y = v.y;660661return 1;662}663catch (const std::exception &e)664{665setErrorMessage (e);666return 0;667}668}669670671int672ImfHeaderSetV2fAttribute (ImfHeader *hdr,673const char name[],674float x, float y)675{676try677{678V2f v (x, y);679680if (header(hdr)->find(name) == header(hdr)->end())681header(hdr)->insert (name, Imf::V2fAttribute (v));682else683header(hdr)->typedAttribute<Imf::V2fAttribute>(name).value() = v;684685return 1;686}687catch (const std::exception &e)688{689setErrorMessage (e);690return 0;691}692}693694695int696ImfHeaderV2fAttribute (const ImfHeader *hdr,697const char name[],698float *x, float *y)699{700try701{702const V2f &v =703header(hdr)->typedAttribute<Imf::V2fAttribute>(name).value();704705*x = v.x;706*y = v.y;707708return 1;709}710catch (const std::exception &e)711{712setErrorMessage (e);713return 0;714}715}716717718int719ImfHeaderSetV3iAttribute (ImfHeader *hdr,720const char name[],721int x, int y, int z)722{723try724{725V3i v (x, y, z);726727if (header(hdr)->find(name) == header(hdr)->end())728header(hdr)->insert (name, Imf::V3iAttribute (v));729else730header(hdr)->typedAttribute<Imf::V3iAttribute>(name).value() = v;731732return 1;733}734catch (const std::exception &e)735{736setErrorMessage (e);737return 0;738}739}740741742int743ImfHeaderV3iAttribute (const ImfHeader *hdr,744const char name[],745int *x, int *y, int *z)746{747try748{749const V3i &v =750header(hdr)->typedAttribute<Imf::V3iAttribute>(name).value();751752*x = v.x;753*y = v.y;754*z = v.z;755756return 1;757}758catch (const std::exception &e)759{760setErrorMessage (e);761return 0;762}763}764765766int767ImfHeaderSetV3fAttribute (ImfHeader *hdr,768const char name[],769float x, float y, float z)770{771try772{773V3f v (x, y, z);774775if (header(hdr)->find(name) == header(hdr)->end())776header(hdr)->insert (name, Imf::V3fAttribute (v));777else778header(hdr)->typedAttribute<Imf::V3fAttribute>(name).value() = v;779780return 1;781}782catch (const std::exception &e)783{784setErrorMessage (e);785return 0;786}787}788789790int791ImfHeaderV3fAttribute (const ImfHeader *hdr,792const char name[],793float *x, float *y, float *z)794{795try796{797const V3f &v =798header(hdr)->typedAttribute<Imf::V3fAttribute>(name).value();799800*x = v.x;801*y = v.y;802*z = v.z;803804return 1;805}806catch (const std::exception &e)807{808setErrorMessage (e);809return 0;810}811}812813814int815ImfHeaderSetM33fAttribute (ImfHeader *hdr,816const char name[],817const float m[3][3])818{819try820{821M33f m3 (m);822823if (header(hdr)->find(name) == header(hdr)->end())824header(hdr)->insert (name, Imf::M33fAttribute (m3));825else826header(hdr)->typedAttribute<Imf::M33fAttribute>(name).value() = m3;827828return 1;829}830catch (const std::exception &e)831{832setErrorMessage (e);833return 0;834}835}836837838int839ImfHeaderM33fAttribute (const ImfHeader *hdr,840const char name[],841float m[3][3])842{843try844{845const M33f &m3 =846header(hdr)->typedAttribute<Imf::M33fAttribute>(name).value();847848m[0][0] = m3[0][0];849m[0][1] = m3[0][1];850m[0][2] = m3[0][2];851852m[1][0] = m3[1][0];853m[1][1] = m3[1][1];854m[1][2] = m3[1][2];855856m[2][0] = m3[2][0];857m[2][1] = m3[2][1];858m[2][2] = m3[2][2];859860return 1;861}862catch (const std::exception &e)863{864setErrorMessage (e);865return 0;866}867}868869870int871ImfHeaderSetM44fAttribute (ImfHeader *hdr,872const char name[],873const float m[4][4])874{875try876{877M44f m4 (m);878879if (header(hdr)->find(name) == header(hdr)->end())880header(hdr)->insert (name, Imf::M44fAttribute (m4));881else882header(hdr)->typedAttribute<Imf::M44fAttribute>(name).value() = m4;883884return 1;885}886catch (const std::exception &e)887{888setErrorMessage (e);889return 0;890}891}892893894int895ImfHeaderM44fAttribute (const ImfHeader *hdr,896const char name[],897float m[4][4])898{899try900{901const M44f &m4 =902header(hdr)->typedAttribute<Imf::M44fAttribute>(name).value();903904m[0][0] = m4[0][0];905m[0][1] = m4[0][1];906m[0][2] = m4[0][2];907m[0][3] = m4[0][3];908909m[1][0] = m4[1][0];910m[1][1] = m4[1][1];911m[1][2] = m4[1][2];912m[1][3] = m4[1][3];913914m[2][0] = m4[2][0];915m[2][1] = m4[2][1];916m[2][2] = m4[2][2];917m[2][3] = m4[2][3];918919m[3][0] = m4[3][0];920m[3][1] = m4[3][1];921m[3][2] = m4[3][2];922m[3][3] = m4[3][3];923924return 1;925}926catch (const std::exception &e)927{928setErrorMessage (e);929return 0;930}931}932933934ImfOutputFile *935ImfOpenOutputFile (const char name[], const ImfHeader *hdr, int channels)936{937try938{939return (ImfOutputFile *) new Imf::RgbaOutputFile940(name, *header(hdr), Imf::RgbaChannels (channels));941}942catch (const std::exception &e)943{944setErrorMessage (e);945return 0;946}947}948949950int951ImfCloseOutputFile (ImfOutputFile *out)952{953try954{955delete outfile (out);956return 1;957}958catch (const std::exception &e)959{960setErrorMessage (e);961return 0;962}963}964965966int967ImfOutputSetFrameBuffer (ImfOutputFile *out,968const ImfRgba *base,969size_t xStride,970size_t yStride)971{972try973{974outfile(out)->setFrameBuffer ((Imf::Rgba *)base, xStride, yStride);975return 1;976}977catch (const std::exception &e)978{979setErrorMessage (e);980return 0;981}982}983984985int986ImfOutputWritePixels (ImfOutputFile *out, int numScanLines)987{988try989{990outfile(out)->writePixels (numScanLines);991return 1;992}993catch (const std::exception &e)994{995setErrorMessage (e);996return 0;997}998}99910001001int1002ImfOutputCurrentScanLine (const ImfOutputFile *out)1003{1004return outfile(out)->currentScanLine();1005}100610071008const ImfHeader *1009ImfOutputHeader (const ImfOutputFile *out)1010{1011return (const ImfHeader *) &outfile(out)->header();1012}101310141015int1016ImfOutputChannels (const ImfOutputFile *out)1017{1018return outfile(out)->channels();1019}102010211022ImfTiledOutputFile *1023ImfOpenTiledOutputFile (const char name[],1024const ImfHeader *hdr,1025int channels,1026int xSize, int ySize,1027int mode, int rmode)1028{1029try1030{1031return (ImfTiledOutputFile *) new Imf::TiledRgbaOutputFile1032(name, *header(hdr),1033Imf::RgbaChannels (channels),1034xSize, ySize,1035Imf::LevelMode (mode),1036Imf::LevelRoundingMode (rmode));1037}1038catch (const std::exception &e)1039{1040setErrorMessage (e);1041return 0;1042}1043}104410451046int1047ImfCloseTiledOutputFile (ImfTiledOutputFile *out)1048{1049try1050{1051delete outfile (out);1052return 1;1053}1054catch (const std::exception &e)1055{1056setErrorMessage (e);1057return 0;1058}1059}106010611062int1063ImfTiledOutputSetFrameBuffer (ImfTiledOutputFile *out,1064const ImfRgba *base,1065size_t xStride,1066size_t yStride)1067{1068try1069{1070outfile(out)->setFrameBuffer ((Imf::Rgba *)base, xStride, yStride);1071return 1;1072}1073catch (const std::exception &e)1074{1075setErrorMessage (e);1076return 0;1077}1078}107910801081int1082ImfTiledOutputWriteTile (ImfTiledOutputFile *out,1083int dx, int dy,1084int lx, int ly)1085{1086try1087{1088outfile(out)->writeTile (dx, dy, lx, ly);1089return 1;1090}1091catch (const std::exception &e)1092{1093setErrorMessage (e);1094return 0;1095}1096}109710981099int1100ImfTiledOutputWriteTiles (ImfTiledOutputFile *out,1101int dxMin, int dxMax,1102int dyMin, int dyMax,1103int lx, int ly)1104{1105try1106{1107outfile(out)->writeTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);1108return 1;1109}1110catch (const std::exception &e)1111{1112setErrorMessage (e);1113return 0;1114}1115}111611171118const ImfHeader *1119ImfTiledOutputHeader (const ImfTiledOutputFile *out)1120{1121return (const ImfHeader *) &outfile(out)->header();1122}112311241125int1126ImfTiledOutputChannels (const ImfTiledOutputFile *out)1127{1128return outfile(out)->channels();1129}113011311132int1133ImfTiledOutputTileXSize (const ImfTiledOutputFile *out)1134{1135return outfile(out)->tileXSize();1136}113711381139int1140ImfTiledOutputTileYSize (const ImfTiledOutputFile *out)1141{1142return outfile(out)->tileYSize();1143}114411451146int1147ImfTiledOutputLevelMode (const ImfTiledOutputFile *out)1148{1149return outfile(out)->levelMode();1150}115111521153int1154ImfTiledOutputLevelRoundingMode (const ImfTiledOutputFile *out)1155{1156return outfile(out)->levelRoundingMode();1157}115811591160ImfInputFile *1161ImfOpenInputFile (const char name[])1162{1163try1164{1165return (ImfInputFile *) new Imf::RgbaInputFile (name);1166}1167catch (const std::exception &e)1168{1169setErrorMessage (e);1170return 0;1171}1172}117311741175int1176ImfCloseInputFile (ImfInputFile *in)1177{1178try1179{1180delete infile (in);1181return 1;1182}1183catch (const std::exception &e)1184{1185setErrorMessage (e);1186return 0;1187}1188}118911901191int1192ImfInputSetFrameBuffer (ImfInputFile *in,1193ImfRgba *base,1194size_t xStride,1195size_t yStride)1196{1197try1198{1199infile(in)->setFrameBuffer ((Imf::Rgba *) base, xStride, yStride);1200return 1;1201}1202catch (const std::exception &e)1203{1204setErrorMessage (e);1205return 0;1206}1207}120812091210int1211ImfInputReadPixels (ImfInputFile *in, int scanLine1, int scanLine2)1212{1213try1214{1215infile(in)->readPixels (scanLine1, scanLine2);1216return 1;1217}1218catch (const std::exception &e)1219{1220setErrorMessage (e);1221return 0;1222}1223}122412251226const ImfHeader *1227ImfInputHeader (const ImfInputFile *in)1228{1229return (const ImfHeader *) &infile(in)->header();1230}123112321233int1234ImfInputChannels (const ImfInputFile *in)1235{1236return infile(in)->channels();1237}123812391240const char *1241ImfInputFileName (const ImfInputFile *in)1242{1243return infile(in)->fileName();1244}124512461247ImfTiledInputFile *1248ImfOpenTiledInputFile (const char name[])1249{1250try1251{1252return (ImfTiledInputFile *) new Imf::TiledRgbaInputFile (name);1253}1254catch (const std::exception &e)1255{1256setErrorMessage (e);1257return 0;1258}1259}126012611262int1263ImfCloseTiledInputFile (ImfTiledInputFile *in)1264{1265try1266{1267delete infile (in);1268return 1;1269}1270catch (const std::exception &e)1271{1272setErrorMessage (e);1273return 0;1274}1275}127612771278int1279ImfTiledInputSetFrameBuffer (ImfTiledInputFile *in,1280ImfRgba *base,1281size_t xStride,1282size_t yStride)1283{1284try1285{1286infile(in)->setFrameBuffer ((Imf::Rgba *) base, xStride, yStride);1287return 1;1288}1289catch (const std::exception &e)1290{1291setErrorMessage (e);1292return 0;1293}1294}129512961297int1298ImfTiledInputReadTile (ImfTiledInputFile *in,1299int dx, int dy,1300int lx, int ly)1301{1302try1303{1304infile(in)->readTile (dx, dy, lx, ly);1305return 1;1306}1307catch (const std::exception &e)1308{1309setErrorMessage (e);1310return 0;1311}1312}131313141315int1316ImfTiledInputReadTiles (ImfTiledInputFile *in,1317int dxMin, int dxMax,1318int dyMin, int dyMax,1319int lx, int ly)1320{1321try1322{1323infile(in)->readTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);1324return 1;1325}1326catch (const std::exception &e)1327{1328setErrorMessage (e);1329return 0;1330}1331}133213331334const ImfHeader *1335ImfTiledInputHeader (const ImfTiledInputFile *in)1336{1337return (const ImfHeader *) &infile(in)->header();1338}133913401341int1342ImfTiledInputChannels (const ImfTiledInputFile *in)1343{1344return infile(in)->channels();1345}134613471348const char *1349ImfTiledInputFileName (const ImfTiledInputFile *in)1350{1351return infile(in)->fileName();1352}135313541355int1356ImfTiledInputTileXSize (const ImfTiledInputFile *in)1357{1358return infile(in)->tileXSize();1359}136013611362int1363ImfTiledInputTileYSize (const ImfTiledInputFile *in)1364{1365return infile(in)->tileYSize();1366}136713681369int1370ImfTiledInputLevelMode (const ImfTiledInputFile *in)1371{1372return infile(in)->levelMode();1373}137413751376int1377ImfTiledInputLevelRoundingMode (const ImfTiledInputFile *in)1378{1379return infile(in)->levelRoundingMode();1380}138113821383ImfLut *1384ImfNewRound12logLut (int channels)1385{1386try1387{1388return (ImfLut *) new Imf::RgbaLut1389(Imf::round12log, Imf::RgbaChannels (channels));1390}1391catch (const std::exception &e)1392{1393setErrorMessage (e);1394return 0;1395}1396}139713981399ImfLut *1400ImfNewRoundNBitLut (unsigned int n, int channels)1401{1402try1403{1404return (ImfLut *) new Imf::RgbaLut1405(Imf::roundNBit (n), Imf::RgbaChannels (channels));1406}1407catch (const std::exception &e)1408{1409setErrorMessage (e);1410return 0;1411}1412}141314141415void1416ImfDeleteLut (ImfLut *lut)1417{1418delete (Imf::RgbaLut *) lut;1419}142014211422void1423ImfApplyLut (ImfLut *lut, ImfRgba *data, int nData, int stride)1424{1425((Imf::RgbaLut *)lut)->apply ((Imf::Rgba *)data, nData, stride);1426}142714281429const char *1430ImfErrorMessage ()1431{1432return errorMessage;1433}143414351436