void loadImage (const char fileName[], const char channel[], const char layer[], bool preview, int lx, int ly, int partnum, int &zsize, Header &header, Array<Rgba> &pixels, Array<float*> &zbuffer, Array<unsigned int> &sampleCount) { zsize = 0; MultiPartInputFile inmaster (fileName); Header h = inmaster.header(partnum); std::string type = h.type(); if (type == "deeptile") { loadDeepTileImage(inmaster, partnum, zsize, header, pixels, zbuffer, sampleCount); } else if(type == "deepscanline") { loadDeepScanlineImage(inmaster, partnum, zsize, header, pixels, zbuffer, sampleCount); } else if (preview) { loadPreviewImage (fileName, partnum, header, pixels); } else if (lx >= 0 || ly >= 0) { if (channel) { loadTiledImageChannel (fileName, channel, lx, ly, partnum, header, pixels); } else { loadTiledImage (fileName, layer, lx, ly, partnum, header, pixels); } } else { if (channel) { loadImageChannel (fileName, channel, partnum, header, pixels); } else { loadImage (fileName, layer, partnum, header, pixels); } } }
void printInfo (const char fileName[]) { MultiPartInputFile in (fileName); int parts = in.parts(); // // check to see if any parts are incomplete // bool is_complete=true; for (size_t i = 0; i < parts && is_complete; ++i) { is_complete &= in.partComplete(i); } cout << "\n" << fileName << (is_complete ? "": " (incomplete file)") << ":\n\n"; cout << "file format version: " << getVersion (in.version()) << ", " "flags 0x" << setbase (16) << getFlags (in.version()) << setbase (10) << "\n"; for (size_t p = 0; p < parts ; ++p) { const Header & h = in.header(p); if( parts != 1 ) { cout << "\n\n part " << p << ( in.partComplete(p) ? "": " (incomplete)") << ":\n"; } for (Header::ConstIterator i = h.begin(); i != h.end(); ++i) { const Attribute *a = &i.attribute(); cout << i.name() << " (type " << a->typeName() << ")"; if (const Box2iAttribute *ta = dynamic_cast <const Box2iAttribute *> (a)) { cout << ": " << ta->value().min << " - " << ta->value().max; } else if (const Box2fAttribute *ta = dynamic_cast <const Box2fAttribute *> (a)) { cout << ": " << ta->value().min << " - " << ta->value().max; } else if (const ChannelListAttribute *ta = dynamic_cast <const ChannelListAttribute *> (a)) { cout << ":"; printChannelList (ta->value()); } else if (const ChromaticitiesAttribute *ta = dynamic_cast <const ChromaticitiesAttribute *> (a)) { cout << ":\n" " red " << ta->value().red << "\n" " green " << ta->value().green << "\n" " blue " << ta->value().blue << "\n" " white " << ta->value().white; } else if (const CompressionAttribute *ta = dynamic_cast <const CompressionAttribute *> (a)) { cout << ": "; printCompression (ta->value()); } else if (const DoubleAttribute *ta = dynamic_cast <const DoubleAttribute *> (a)) { cout << ": " << ta->value(); } else if (const EnvmapAttribute *ta = dynamic_cast <const EnvmapAttribute *> (a)) { cout << ": "; printEnvmap (ta->value()); } else if (const FloatAttribute *ta = dynamic_cast <const FloatAttribute *> (a)) { cout << ": " << ta->value(); } else if (const IntAttribute *ta = dynamic_cast <const IntAttribute *> (a)) { cout << ": " << ta->value(); } else if (const KeyCodeAttribute *ta = dynamic_cast <const KeyCodeAttribute *> (a)) { cout << ":\n" " film manufacturer code " << ta->value().filmMfcCode() << "\n" " film type code " << ta->value().filmType() << "\n" " prefix " << ta->value().prefix() << "\n" " count " << ta->value().count() << "\n" " perf offset " << ta->value().perfOffset() << "\n" " perfs per frame " << ta->value().perfsPerFrame() << "\n" " perfs per count " << ta->value().perfsPerCount(); } else if (const LineOrderAttribute *ta = dynamic_cast <const LineOrderAttribute *> (a)) { cout << ": "; printLineOrder (ta->value()); } else if (const M33fAttribute *ta = dynamic_cast <const M33fAttribute *> (a)) { cout << ":\n" " (" << ta->value()[0][0] << " " << ta->value()[0][1] << " " << ta->value()[0][2] << "\n " << ta->value()[1][0] << " " << ta->value()[1][1] << " " << ta->value()[1][2] << "\n " << ta->value()[2][0] << " " << ta->value()[2][1] << " " << ta->value()[2][2] << ")"; } else if (const M44fAttribute *ta = dynamic_cast <const M44fAttribute *> (a)) { cout << ":\n" " (" << ta->value()[0][0] << " " << ta->value()[0][1] << " " << ta->value()[0][2] << " " << ta->value()[0][3] << "\n " << ta->value()[1][0] << " " << ta->value()[1][1] << " " << ta->value()[1][2] << " " << ta->value()[1][3] << "\n " << ta->value()[2][0] << " " << ta->value()[2][1] << " " << ta->value()[2][2] << " " << ta->value()[2][3] << "\n " << ta->value()[3][0] << " " << ta->value()[3][1] << " " << ta->value()[3][2] << " " << ta->value()[3][3] << ")"; } else if (const PreviewImageAttribute *ta = dynamic_cast <const PreviewImageAttribute *> (a)) { cout << ": " << ta->value().width() << " by " << ta->value().height() << " pixels"; } else if (const StringAttribute *ta = dynamic_cast <const StringAttribute *> (a)) { cout << ": \"" << ta->value() << "\""; } else if (const StringVectorAttribute * ta = dynamic_cast<const StringVectorAttribute *>(a)) { cout << ":"; for (StringVector::const_iterator i = ta->value().begin(); i != ta->value().end(); ++i) { cout << "\n \"" << *i << "\""; } } else if (const RationalAttribute *ta = dynamic_cast <const RationalAttribute *> (a)) { cout << ": " << ta->value().n << "/" << ta->value().d << " (" << double (ta->value()) << ")"; } else if (const TileDescriptionAttribute *ta = dynamic_cast <const TileDescriptionAttribute *> (a)) { cout << ":\n "; printLevelMode (ta->value().mode); cout << "\n tile size " << ta->value().xSize << " by " << ta->value().ySize << " pixels"; if (ta->value().mode != ONE_LEVEL) { cout << "\n level sizes rounded "; printLevelRoundingMode (ta->value().roundingMode); } } else if (const TimeCodeAttribute *ta = dynamic_cast <const TimeCodeAttribute *> (a)) { cout << ":\n"; printTimeCode (ta->value()); } else if (const V2iAttribute *ta = dynamic_cast <const V2iAttribute *> (a)) { cout << ": " << ta->value(); } else if (const V2fAttribute *ta = dynamic_cast <const V2fAttribute *> (a)) { cout << ": " << ta->value(); } else if (const V3iAttribute *ta = dynamic_cast <const V3iAttribute *> (a)) { cout << ": " << ta->value(); } else if (const V3fAttribute *ta = dynamic_cast <const V3fAttribute *> (a)) { cout << ": " << ta->value(); } cout << '\n'; } } cout << endl; }
int main(int argc, char **argv) { const char *inFile = 0; const char *outFile = 0; LevelMode mode = ONE_LEVEL; LevelRoundingMode roundingMode = ROUND_DOWN; Compression compression = ZIP_COMPRESSION; int tileSizeX = 64; int tileSizeY = 64; set<string> doNotFilter; Extrapolation extX = CLAMP; Extrapolation extY = CLAMP; bool verbose = false; // // Parse the command line. // if (argc < 2) usageMessage (argv[0], true); int i = 1; int partnum = 0; while (i < argc) { if (!strcmp (argv[i], "-o")) { // // generate a ONE_LEVEL image // mode = ONE_LEVEL; i += 1; } else if (!strcmp (argv[i], "-m")) { // // Generate a MIPMAP_LEVELS image // mode = MIPMAP_LEVELS; i += 1; } else if (!strcmp (argv[i], "-r")) { // // Generate a RIPMAP_LEVELS image // mode = RIPMAP_LEVELS; i += 1; } else if (!strcmp (argv[i], "-f")) { // // Don't low-pass filter the specified image channel // if (i > argc - 2) usageMessage (argv[0]); doNotFilter.insert (argv[i + 1]); i += 2; } else if (!strcmp (argv[i], "-e")) { // // Set x and y extrapolation method // if (i > argc - 3) usageMessage (argv[0]); extX = getExtrapolation (argv[i + 1]); extY = getExtrapolation (argv[i + 2]); i += 3; } else if (!strcmp (argv[i], "-t")) { // // Set tile size // if (i > argc - 3) usageMessage (argv[0]); tileSizeX = strtol (argv[i + 1], 0, 0); tileSizeY = strtol (argv[i + 2], 0, 0); if (tileSizeX <= 0 || tileSizeY <= 0) { cerr << "Tile size must be greater than zero." << endl; return 1; } i += 3; } else if (!strcmp (argv[i], "-d")) { // // Round down // roundingMode = ROUND_DOWN; i += 1; } else if (!strcmp (argv[i], "-u")) { // // Round down // roundingMode = ROUND_UP; i += 1; } else if (!strcmp (argv[i], "-z")) { // // Set compression method // if (i > argc - 2) usageMessage (argv[0]); compression = getCompression (argv[i + 1]); i += 2; } else if (!strcmp (argv[i], "-v")) { // // Verbose mode // verbose = true; i += 1; } else if (!strcmp (argv[i], "-h")) { // // Print help message // usageMessage (argv[0], true); } else if (!strcmp (argv[i], "-p")) { getPartNum (argc, argv, i, &partnum); } else { // // Image file name // if (inFile == 0) inFile = argv[i]; else outFile = argv[i]; i += 1; } } if (inFile == 0 || outFile == 0) usageMessage (argv[0]); if (!strcmp (inFile, outFile)) { cerr << "Input and output cannot be the same file." << endl; return 1; } // // Load inFile, and save a tiled version in outFile. // int exitStatus = 0; // // check input // { MultiPartInputFile input (inFile); int parts = input.parts(); if (partnum < 0 || partnum >= parts){ cerr << "ERROR: you asked for part " << partnum << " in " << inFile; cerr << ", which only has " << parts << " parts\n"; exit(1); } Header h = input.header (partnum); if (h.type() == DEEPTILE || h.type() == DEEPSCANLINE) { cerr << "Cannot make tile for deep data" << endl; exit(1); } } try { makeTiled (inFile, outFile, partnum, mode, roundingMode, compression, tileSizeX, tileSizeY, doNotFilter, extX, extY, verbose); } catch (const exception &e) { cerr << e.what() << endl; exitStatus = 1; } return exitStatus; }