/*-------------------------------------------------------------------*/ /* PROTO.C Pasi Fränti */ /* */ /* - Prototype for image processing software. */ /* - Makes copy of the input image */ /* */ /*-------------------------------------------------------------------*/ #define ProgName "PROTO" #define VersionNumber "Version 0.02" #define LastUpdated "3.7.00" /*-------------------------------------------------------------------*/ #include #include #include #include #define FACTFILE "proto.fac" #include "parametr.c" #include "pgm.h" #include "dip.h" #include "image.h" #include "file.h" #include "memctrl.h" #include "owntypes.h" /* ========================= Time functions ============================= */ static long SetWatch(long* start) { time_t tmp; return( *start = (long)time(&tmp) ); } /* ----------------------------------------------------------------- */ static void PrintTime(long start) { time_t tmp; int hours, minutes, seconds; long elapsed; elapsed = (long)time(&tmp) - start; hours = (int)(elapsed / 3600); elapsed = (int)(elapsed % 3600); minutes = (int)(elapsed / 60); seconds = (int)(elapsed % 60); switch( Value(QuietLevel) ) { case 0: break; case 1: printf(" %i:%02i:%02i", hours, minutes, seconds); break; default: printf("Time: %i:%02i:%02i\n", hours, minutes, seconds); break; } } /*========================== P R I N T ============================*/ void PrintInfo(void) { printf("%s %s (last modified %s)\n",ProgName,VersionNumber,LastUpdated); printf("Bit plane separation.\n"); printf("Usage: %s inputfile outputfile [%coptions]\n", ProgName, OPTION_SYMBOL); printf("\n Options:\n"); PrintOptions(); printf("\n%s %s\n",ProgName,VersionNumber); } /*-------------------------------------------------------------------*/ static void PrintOperatingInfo(char* InputFileName, char* OutputFileName, IMAGE* InputImage, IMAGE* OutputImage) { if( Value(QuietLevel) >= 1 ) { printf("\n%s %s %s\n", ProgName, VersionNumber, LastUpdated); printf("Input file: %12s (%ix%i)\n", InputFileName, InputImage->ImageSizeX, InputImage->ImageSizeY); printf("Output file: %12s (%ix%i)\n", OutputFileName, OutputImage->ImageSizeX, OutputImage->ImageSizeY); printf("\n"); PrintSelectedOptions(); printf("\n"); } } /*-------------------------------------------------------------------*/ static void PrintProgress(int y, int total) { if( Value(QuietLevel) >= 2 ) { printf("%5.1f %% done.\r", (float)(y + 1) * 100 / total); fflush(stdout); } } /* ========================= P R O C E S S ======================= */ static int ProcessPixel(IMAGE* Image, int x, int y, int v) { /* Currently, this routine only returns the input value as such. */ /* You may practice using various routines found in the DIP.H. */ return v; } /*-------------------------------------------------------------------*/ static void ProcessImage(IMAGE* InputImage, IMAGE* OutputImage) { int x,y; BYTE value; for(y=1; y<=InputImage->ImageSizeY; y++) { ScrollBuffer(InputImage); for(x=1; x<=InputImage->ImageSizeX; x++) { value = GetBufferGray(InputImage, x, 0); value = ProcessPixel(InputImage, x, 0, value); PutBufferGray(OutputImage, x, 0, value); } WriteCurrentLine(OutputImage); PrintProgress(y, InputImage->ImageSizeY); } } /*=========================== M A I N =============================*/ void main(int argc, char* argv[]) { char InputFileName[64] = { '\0' }; char OutputFileName[64] = { '\0' }; FILE* InputFile; FILE* OutputFile; IMAGE InputImage; IMAGE OutputImage; long watch; ParameterInfo paraminfo[2] = { { InputFileName, "PGM", 0, INFILE }, { OutputFileName, "PGM", 0, OUTFILE } }; ParseParameters(argc, argv, 2, paraminfo); InputFile = OpenFile(InputFileName, INPUT, NO); OutputFile = OpenFile(OutputFileName, OUTPUT, Value(OverWrite)); InitializeImage(InputFile, &InputImage, INPUT, WINDOWBUFFER, 1); CopyImageHeader(&InputImage, &OutputImage); InitializeImage(OutputFile, &OutputImage, OUTPUT, WINDOWBUFFER, 1); PrintOperatingInfo(InputFileName, OutputFileName, &InputImage, &OutputImage); SetWatch(&watch); ProcessImage(&InputImage, &OutputImage); PrintTime(watch); FreeImage(&InputImage); FreeImage(&OutputImage); fclose(InputFile); fclose(OutputFile); checkmemory(); }