00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef RASTER_DPXFILE_C_DEFINED
00039 #define RASTER_DPXFILE_C_DEFINED
00040
00041 #include "Raster/DpxFile.H"
00042 #include "Util/log.H"
00043 #include <cstdio>
00044
00045 DpxFile::DpxFile(const char* fname)
00046 {
00047 LDEBUG("sizeof(DpxFile::FileHeader) = %"ZU, sizeof(DpxFile::FileHeader));
00048
00049 FILE* fp = fopen(fname, "r");
00050 if (fp == 0)
00051 LFATAL("couldn't open '%s' for reading", fname);
00052
00053 if (fread(&this->fh, sizeof(this->fh), 1, fp) != 1)
00054 LFATAL("couldn't read file header from '%s'", fname);
00055
00056
00057
00058 if (this->fh.MagicNumber == 0x53445058)
00059
00060 ;
00061 else if (this->fh.MagicNumber == 0x58504453)
00062 {
00063
00064 LFATAL("byte-swapping not yet implemented for DPX images");
00065 }
00066 else
00067 LFATAL("invalid DPX magic number '%d' in '%s'",
00068 this->fh.MagicNumber, fname);
00069
00070 #define SHOW(x) LDEBUG("(%s) " #x " = %u", fname, x)
00071 #define SHOWF(x) LDEBUG("(%s) " #x " = %f", fname, x)
00072 #define SHOWS(x,w) LDEBUG("(%s) " #x " = '%." #w "s'", fname, x)
00073
00074 SHOW(this->fh.MagicNumber);
00075 SHOW(this->fh.ImageDataOffset);
00076 SHOW(this->fh.FileSize);
00077 SHOW(this->fh.DittoKey);
00078 SHOW(this->fh.GenericHeaderSize);
00079 SHOW(this->fh.IndustryHeaderSize);
00080 SHOW(this->fh.UserDefinedDataSize);
00081 SHOW(this->fh.EncryptKey);
00082
00083 SHOWS(this->fh.HeaderVersion, 8);
00084 SHOWS(this->fh.ImageFilename, 100);
00085 SHOWS(this->fh.CreateTime, 23);
00086 SHOWS(this->fh.Creator, 100);
00087 SHOWS(this->fh.Project, 200);
00088 SHOWS(this->fh.Copyright, 200);
00089
00090 LDEBUG("sizeof(DpxFile::ImageHeader) = %"ZU,
00091 sizeof(DpxFile::ImageHeader));
00092
00093 if (fread(&this->ih, sizeof(this->ih), 1, fp) != 1)
00094 LFATAL("couldn't read image header from '%s'", fname);
00095
00096 SHOW(this->ih.Orientation);
00097 SHOW(this->ih.NumberElements);
00098 SHOW(this->ih.PixelsPerLine);
00099 SHOW(this->ih.LinesPerElement);
00100 SHOW(this->ih.ImageElement[0].DataSign);
00101 SHOW(this->ih.ImageElement[0].LowData);
00102 SHOWF(this->ih.ImageElement[0].LowQuantity);
00103 SHOW(this->ih.ImageElement[0].HighData);
00104 SHOWF(this->ih.ImageElement[0].HighQuantity);
00105 SHOW(this->ih.ImageElement[0].Descriptor);
00106 SHOW(this->ih.ImageElement[0].Transfer);
00107 SHOW(this->ih.ImageElement[0].Colorimetric);
00108 SHOW(this->ih.ImageElement[0].BitSize);
00109 SHOW(this->ih.ImageElement[0].Packing);
00110 SHOW(this->ih.ImageElement[0].Encoding);
00111 SHOW(this->ih.ImageElement[0].DataOffset);
00112 SHOW(this->ih.ImageElement[0].EndOfLinePadding);
00113 SHOW(this->ih.ImageElement[0].EndOfImagePadding);
00114 SHOWS(this->ih.ImageElement[0].Description, 32);
00115
00116 LDEBUG("sizeof(DpxFile::OrientationHeader) = %"ZU,
00117 sizeof(DpxFile::OrientationHeader));
00118
00119 if (fread(&this->oh, sizeof(this->oh), 1, fp) != 1)
00120 LFATAL("couldn't read orientation header from '%s'", fname);
00121
00122 SHOW(this->oh.XOffset);
00123 SHOW(this->oh.YOffset);
00124 SHOWF(this->oh.XCenter);
00125 SHOWF(this->oh.YCenter);
00126 SHOW(this->oh.XOriginalSize);
00127 SHOW(this->oh.YOriginalSize);
00128 SHOWS(this->oh.FileName, 100);
00129 SHOWS(this->oh.TimeDate, 24);
00130 SHOWS(this->oh.InputName, 32);
00131 SHOWS(this->oh.InputSN, 32);
00132 SHOW(this->oh.Border[0]);
00133 SHOW(this->oh.Border[1]);
00134 SHOW(this->oh.Border[2]);
00135 SHOW(this->oh.Border[3]);
00136 SHOW(this->oh.AspectRatio[0]);
00137 SHOW(this->oh.AspectRatio[1]);
00138
00139 LDEBUG("sizeof(DpxFile::FilmIndustryHeader) = %"ZU,
00140 sizeof(DpxFile::FilmIndustryHeader));
00141
00142 if (fread(&this->fih, sizeof(this->fih), 1, fp) != 1)
00143 LFATAL("couldn't read film industry header from '%s'", fname);
00144
00145 SHOWS(this->fih.FilmMfgId, 2);
00146 SHOWS(this->fih.FilmType, 2);
00147 SHOWS(this->fih.Offset, 2);
00148 SHOWS(this->fih.Prefix, 6);
00149 SHOWS(this->fih.Count, 4);
00150 SHOWS(this->fih.Format, 32);
00151 SHOW(this->fih.FramePosition);
00152 SHOW(this->fih.SequenceLen);
00153 SHOW(this->fih.HeldCount);
00154 SHOWF(this->fih.FrameRate);
00155 SHOWF(this->fih.ShutterAngle);
00156 SHOWS(this->fih.FrameId, 32);
00157 SHOWS(this->fih.SlateInfo, 100);
00158
00159 LDEBUG("sizeof(DpxFile::TelevisionIndustryHeader) = %"ZU,
00160 sizeof(DpxFile::TelevisionIndustryHeader));
00161
00162 if (fread(&this->tih, sizeof(this->tih), 1, fp) != 1)
00163 LFATAL("couldn't read television industry header from '%s'", fname);
00164
00165 SHOW(this->tih.TimeCode);
00166 SHOW(this->tih.UserBits);
00167 SHOW(this->tih.Interlace);
00168 SHOW(this->tih.FiledNumber);
00169 SHOW(this->tih.VideoSignal);
00170 SHOW(this->tih.Padding);
00171 SHOWF(this->tih.HorzSampleRate);
00172 SHOWF(this->tih.VertSampleRate);
00173 SHOWF(this->tih.FrameRate);
00174 SHOWF(this->tih.TimeOffset);
00175 SHOWF(this->tih.Gamma);
00176 SHOWF(this->tih.BlackLevel);
00177 SHOWF(this->tih.BlackGain);
00178 SHOWF(this->tih.Breakpoint);
00179 SHOWF(this->tih.WhiteLevel);
00180 SHOWF(this->tih.IntegrationTimes);
00181
00182 if (fseek(fp, this->fh.ImageDataOffset, SEEK_SET) != 0)
00183 LFATAL("couldn't fseek() to start of image data in '%s'", fname);
00184
00185 ASSERT(this->ih.PixelsPerLine > 0);
00186 ASSERT(this->ih.LinesPerElement > 0);
00187
00188 this->dims = Dims(this->ih.PixelsPerLine, this->ih.LinesPerElement);
00189 this->rawimage = Image<uint16>(this->dims, NO_INIT);
00190
00191 ASSERT(this->ih.ImageElement[0].BitSize == 16);
00192 ASSERT(this->ih.ImageElement[0].EndOfLinePadding == 0xFFFF);
00193
00194 if (fread(this->rawimage.getArrayPtr(),
00195 sizeof(*(this->rawimage.getArrayPtr())),
00196 this->dims.sz(), fp)
00197 != size_t(this->dims.sz()))
00198 LFATAL("couldn't read image data from '%s'", fname);
00199
00200 fclose(fp);
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210 #endif // RASTER_DPXFILE_C_DEFINED