// parse object data-file ----------------------------------------------------- // int AodInput::ParseObjectData() { int faceprop_itemsread = 0; int facenorm_itemsread = 0; InfoMessage( "Processing input data file (format='AOD V1.1') ..." ); // parse sections and read data ------------------------------- m_section = _nil; while ( m_input.ReadLine( line, TEXTLINE_MAX ) != NULL ) { if ( ( m_parser_lineno++ & PARSER_DOT_SIZE ) == 0 ) printf( "." ), fflush( stdout ); if ( ( m_scanptr = strtok( line, "/, \t\n\r" ) ) == NULL ) continue; else if ( *m_scanptr == ';' ) continue; else if ( strnicmp( m_scanptr, "<end", 4 ) == 0 ) break; else if ( *m_scanptr == '#' ) { if ( strncmp( m_scanptr, _aodsig_str, strlen( _aodsig_str ) ) == 0 ) { m_section = _comment; } else if ( ( m_section = GetSectionId( m_scanptr ) ) == _nil ) { { StrScratch error; sprintf( error, "%s[Undefined section-name]: %s (line %d)", parser_err_str, m_scanptr, m_parser_lineno ); ErrorMessage( error ); } HandleCriticalError(); } } else { switch ( m_section ) { // list of vertices ------------------------------------ case _vertices : ReadVertex(); break; // vertexnums of faces --------------------------------- case _faces : ReadFace( TRUE ); break; // normals for face's planes --------------------------- case _facenormals : //NOTE: // face normals are currently ignored in the aod // file, since they are too inaccurate for later // BSP compilation purposes. if no normals are read // in, they will be calculated later on anyway. //ReadFaceNormal( facenorm_itemsread ); break; // properties of faces --------------------------------- case _faceproperties : ReadFaceProperties( faceprop_itemsread ); break; // texture->face correspondences ---------------------- case _correspondences : ReadCorrespondences(); break; // texturing data ----------------------------------- case _textures : ReadTextures(); break; // location of the object --------------------------- case _worldlocation : ReadWorldLocation(); break; // location of camera ------------------------------- case _camera : ReadCameraLocation(); break; // filename of palette file ------------------------- case _palette : ReadPaletteFilename(); break; // scalefactors for object -------------------------- case _scalefactors : ReadScaleFactors(); break; // exchange command for axes ------------------------ case _xchange : ReadXChangeCommand(); break; // set new object origin ---------------------------- case _setorigin : ReadOrigin(); break; } } } // do post processing after parsing ApplyOriginTranslation(); FilterAxesDirSwitch(); FilterScaleFactors(); FilterAxesExchange(); EnforceMaximumExtents(); m_baseobject->CheckParsedData(); InfoMessage( "\nObject data ok.\n" ); // do colorindex to rgb conversion ConvertColIndxs(); return ( m_inputok = TRUE ); }
int main(int argc, char **argv) { // Look for help for (int i = 0; i < argc; i++) { if (!strcmp(argv[i], "-help")) { ShowUsage(); } } // Read input and output image filenames if (argc < 3) ShowUsage(); argv++, argc--; // First argument is program name char *input_image_name = *argv; argv++, argc--; char *output_image_name = *argv; argv++, argc--; // Allocate image R2Image *image = new R2Image(); if (!image) { fprintf(stderr, "Unable to allocate image\n"); exit(-1); } // Read input image if (!image->Read(input_image_name)) { fprintf(stderr, "Unable to read image from %s\n", input_image_name); exit(-1); } // Initialize sampling method int sampling_method = R2_IMAGE_POINT_SAMPLING; // Parse arguments and perform operations while (argc > 0) { if (!strcmp(*argv, "-bilateral")) { CheckOption(*argv, argc, 3); double sx = atof(argv[1]); double sy = atof(argv[2]); argv += 3, argc -= 3; image->BilateralFilter(sy, sx); } else if (!strcmp(*argv, "-blackandwhite")) { argv++, argc--; image->BlackAndWhite(); } else if (!strcmp(*argv, "-blur")) { CheckOption(*argv, argc, 2); double sigma = atof(argv[1]); argv += 2, argc -= 2; image->Blur(sigma); } else if (!strcmp(*argv, "-brightness")) { CheckOption(*argv, argc, 2); double factor = atof(argv[1]); argv += 2, argc -=2; image->Brighten(factor); } else if (!strcmp(*argv, "-composite")) { CheckOption(*argv, argc, 5); R2Image *top_image = new R2Image(argv[2]); R2Image *bottom_mask = new R2Image(argv[1]); R2Image *top_mask = new R2Image(argv[3]); int operation = atoi(argv[4]); argv += 5, argc -= 5; image->CopyChannel(*bottom_mask, R2_IMAGE_BLUE_CHANNEL, R2_IMAGE_ALPHA_CHANNEL); top_image->CopyChannel(*top_mask, R2_IMAGE_BLUE_CHANNEL, R2_IMAGE_ALPHA_CHANNEL); image->Composite(*top_image, operation); delete top_image; delete bottom_mask; delete top_mask; } else if (!strcmp(*argv, "-contrast")) { CheckOption(*argv, argc, 2); double factor = atof(argv[1]); argv += 2, argc -= 2; image->ChangeContrast(factor); } else if (!strcmp(*argv, "-crop")) { CheckOption(*argv, argc, 5); int x = atoi(argv[1]); int y = atoi(argv[2]); int w = atoi(argv[3]); int h = atoi(argv[4]); argv += 5, argc -= 5; image->Crop(x, y, w, h); } else if (!strcmp(*argv, "-dither")) { CheckOption(*argv, argc, 3); int dither_method = atoi(argv[1]); int nbits = atoi(argv[2]); argv += 3, argc -= 3; if (dither_method == 0) image->RandomDither(nbits); else if (dither_method == 1) image->OrderedDither(nbits); else if (dither_method == 2) image->FloydSteinbergDither(nbits); else { fprintf(stderr, "Invalid dither method: %d\n", dither_method); exit(-1); } } else if (!strcmp(*argv, "-edge")) { argv++, argc--; image->EdgeDetect(); } else if (!strcmp(*argv, "-extract")) { CheckOption(*argv, argc, 2); int channel = atoi(argv[1]); argv += 2, argc -= 2; image->ExtractChannel(channel); } else if (!strcmp(*argv, "-fun")) { image->Fun(sampling_method); argv++, argc--; } else if (!strcmp(*argv, "-gamma")) { CheckOption(*argv, argc, 2); double factor = atof(argv[1]); argv += 2, argc -= 2; image->ApplyGamma(factor); } else if (!strcmp(*argv, "-median")) { CheckOption(*argv, argc, 2); double sigma = atof(argv[1]); argv += 2, argc -= 2; image->MedianFilter(sigma); } else if (!strcmp(*argv, "-motionblur")) { CheckOption(*argv, argc, 1); int amount = atoi(argv[1]); argv += 2, argc -= 2; image->MotionBlur(amount); } else if (!strcmp(*argv, "-morph")) { int nsegments = 0; R2Segment *source_segments = NULL; R2Segment *target_segments = NULL; CheckOption(*argv, argc, 4); R2Image *target_image = new R2Image(argv[1]); ReadCorrespondences(argv[2], source_segments, target_segments, nsegments); double t = atof(argv[3]); argv += 4, argc -= 4; image->Morph(*target_image, source_segments, target_segments, nsegments, t, sampling_method); delete target_image; } else if (!strcmp(*argv, "-noise")) { CheckOption(*argv, argc, 2); double factor = atof(argv[1]); argv += 2, argc -= 2; image->AddNoise(factor); } else if (!strcmp(*argv, "-quantize")) { CheckOption(*argv, argc, 2); int nbits = atoi(argv[1]); argv += 2, argc -= 2; image->Quantize(nbits); } else if (!strcmp(*argv, "-rotate")) { CheckOption(*argv, argc, 2); double angle = atof(argv[1]); argv += 2, argc -= 2; image->Rotate(angle, sampling_method); } else if (!strcmp(*argv, "-sampling")) { CheckOption(*argv, argc, 2); sampling_method = atoi(argv[1]); argv += 2, argc -= 2; } else if (!strcmp(*argv, "-saturation")) { CheckOption(*argv, argc, 2); double factor = atof(argv[1]); argv += 2, argc -= 2; image->ChangeSaturation(factor); } else if (!strcmp(*argv, "-scale")) { CheckOption(*argv, argc, 3); double sx = atof(argv[1]); double sy = atof(argv[2]); argv += 3, argc -= 3; image->Scale(sx, sy, sampling_method); } else if (!strcmp(*argv, "-sharpen")) { argv++, argc--; image->Sharpen(); } else { // Unrecognized program argument fprintf(stderr, "image: invalid option: %s\n", *argv); ShowUsage(); } } // Write output image if (!image->Write(output_image_name)) { fprintf(stderr, "Unable to write image to %s\n", output_image_name); exit(-1); } // Delete image delete image; // Return success return EXIT_SUCCESS; }