STE-Industries: utilities testing
Main.cpp File Reference
#include "Graphic.h"
#include "Bitmap.h"
#include "RandomGenerator.h"
#include "FileException.h"
#include "IntegerException.h"
#include "FloatException.h"
#include "NameException.h"
#include "ParameterDescriptor.h"
#include "NumericParameterDescriptor.h"
#include "EnumeratedParameterDescriptor.h"
#include "Thread.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
Include dependency graph for Main.cpp:

Go to the source code of this file.

Functions

static void Application (const char *InputPathname, const char *OutputPathname, const Bitmap::CorrectionParameters &Parameters) noexcept(false)
 
int main (int argc, char *argv[])
 
static void Randomize (const Bitmap::CorrectionParameters &Parameters, Bitmap &CurrentBitmap) noexcept
 
static void Usage (void) noexcept(false)
 
static void WriteProperties (const Bitmap &CurrentBitmap, const char *Path) noexcept(false)
 

Variables

static constexpr const char * BITS_PER_PIXEL_FORMAT
 
static constexpr const char * CORRECTING_MESSAGE
 
static const Bitmap::CorrectionParameters DefaultParameters
 
const ParameterDescriptor *const DescriptorTable []
 
static constexpr const char * END_CORRECTION_FORMAT
 
static constexpr const char * END_READING_FORMAT
 
static constexpr const char * END_WRITING_FORMAT
 
static constexpr const char * FILE_SIZE_FORMAT = "File size = %lu\n"
 
static constexpr const char * IMAGE_SIZE_FORMAT
 
static constexpr const char * INVALID_OPTION_FORMAT
 
static constexpr unsigned int MAJOR_VERSION_NUMBER = 1
 
static constexpr unsigned int MINOR_VERSION_NUMBER = 1
 
static constexpr const char *const OpenWriteText = "w"
 
static constexpr const char * READING_FORMAT = "Reading %s\n"
 
static constexpr const char * RESOLUTION_FORMAT
 
static constexpr const char * USAGE_FORMAT
 
static constexpr const char * VERSION_FORMAT
 
static constexpr const char * WRITING_FORMAT = "Writing %s\n"
 

Function Documentation

◆ Application()

void Application ( const char *  InputPathName,
const char *  OutputPathName,
const Bitmap::CorrectionParameters Parameters 
)
staticnoexcept
Description:
Application.
Parameters
InputPathNamePointer to the string containing the pathname of the input bitmap file.
OutputPathNamePointer to the string containing the pathname of the output bitmap file.
ParametersReference to the struct containing the correction parameters.
Exceptions
FileExceptionType::FILE_OPEN_ERRORIf an error occurs while opening the input or output bitmap file.
FileExceptionType::FILE_SEEK_ERRORIf an error occurs while seeking the input bitmap file.
FileExceptionType::FILE_READ_ERRORIf an error occurs while reading the input bitmap file.
FileExceptionType::FILE_WRITE_ERRORIf an error occurs while writing the output bitmap file.
FileExceptionType::FILE_CLOSE_ERRORIf an error occurs while closing the input or output bitmap file.
IntegerExceptionType::INVALID_FILE_SIZEIf the bitmap file size in the header of the bitmap file is not equal to the actual file size.
IntegerExceptionType::INVALID_BITMAP_OFFSETIf the bitmap offset in the header of the bitmap file is not equal to HEADER_SIZE + DIB_HEADER_SIZE.
IntegerExceptionType::INVALID_DIB_HEADER_SIZEIf the DIB header size in the header of the bitmap file is not equal to DIB_HEADER_SIZE.
IntegerExceptionType::INVALID_IMAGE_WIDTHIf the image width in the bitmap file is 0 or greater than MAXIMUM_WIDTH.
IntegerExceptionType::INVALID_COLOR_PLANESIf the number of color planes in the bitmap file is not NUMBER_OF_COLOR_PLANES.
IntegerExceptionType::INVALID_BITS_PER_PIXELIf the number of bits per pixel in the bitmap file is not NUMBER_OF_COLORS * CHAR_BIT.
IntegerExceptionType::INVALID_COMPRESSIONIf the value of compression in the bitmap file is not VALID_COMPRESSION.
IntegerExceptionType::INVALID_IMAGE_SIZEIf the image size in the bitmap file is not valid.
IntegerExceptionType::INVALID_NUMBER_OF_COLORSIf the number of color in the bitmap file is not zero.
IntegerExceptionType::INVALID_NUMBER_OF_IMPORTANT_COLORSIf the number of important colors in the bitmap file is not zero.
IntegerExceptionType::INVALID_NUMBER_OF_TERMITESIf the number of termites is not a valid number, it is 0 or greater than MAXIMUM_NUMBER_OF_TERMITES.
IntegerExceptionType::INVALID_NUMBER_OF_STEPSIf the number of steps is not a valid number, it is 0 or greater than MAXIMUM_NUMBER_OF_STEPS.
FloatExceptionType::INVALID_REPULSION_STEPIf the repulsion step is not a valid number, it is less than 0 or greater than 1.
FloatExceptionType::INVALID_ALPHAIf Alpha is is not a valid number, it less than 0 or greater than 1.
FloatExceptionType::INVALID_BETAIf Beta is is not a valid number, it less than 0 or greater than 1.
Returns
None.
Note
if PathName is not a valid pointer to a properly terminated string, the behavior is undefined.
See also
STANDARD_OUTPUT
READING_FORMAT
END_READING_FORMAT
CORRECTING_MESSAGE
END_CORRECTION_FORMAT
WRITING_FORMAT
END_WRITING_FORMAT

Definition at line 435 of file Main.cpp.

References GraphicSpace::Bitmap::Correct(), CORRECTING_MESSAGE, END_CORRECTION_FORMAT, END_READING_FORMAT, END_WRITING_FORMAT, GraphicSpace::FILE_WRITE_ERROR, Randomize(), GraphicSpace::Bitmap::ReadFile(), READING_FORMAT, STANDARD_OUTPUT, GraphicSpace::Bitmap::WriteFile(), WriteProperties(), and WRITING_FORMAT.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)
Description:
Main program.
Parameters
argcNumber of command line arguments.
argvArray of command line arguments.
Exceptions
None.
Returns
int EXIT_SUCCESS, if the program terminates normally, EXIT_FAILURE otherwise.
See also
STANDARD_OUTPUT
VERSION_FORMAT
MAJOR_VERSION_NUMBER
MINOR_VERSION_NUMBER
INVALID_OPTION_FORMAT

Definition at line 493 of file Main.cpp.

References Application(), DefaultParameters, DescriptorTable, GraphicSpace::ParameterDescriptor::EQUAL_CHARACTER, GraphicSpace::FILE_WRITE_ERROR, GraphicSpace::Thread::Finalize(), IgnoreValue, GraphicSpace::Thread::Initialize(), INVALID_OPTION_FORMAT, MAJOR_VERSION_NUMBER, MINOR_VERSION_NUMBER, NumberOfElements, STANDARD_OUTPUT, Usage(), VERSION_FORMAT, and GraphicSpace::Exception::Write().

Here is the call graph for this function:

◆ Randomize()

static void Randomize ( const Bitmap::CorrectionParameters Parameters,
Bitmap CurrentBitmap 
)
staticnoexcept
Description:
Create a set of values to initialize a random numbers generator with a non reproducible value.
Parameters
ParametersReference to the struct containing the correction parameters.
CurrentBitmapReference to the Bitmap object that will correct the image.
Exceptions
None.
Returns
None

Definition at line 187 of file Main.cpp.

References DefaultParameters, GraphicSpace::RandomGenerator::NUMBER_OF_GENERATORS, and NumberOfElements.

Referenced by Application().

Here is the caller graph for this function:

◆ Usage()

static void Usage ( void  )
staticnoexcept
Description:
Write on standard output a string describing how to use the program and stop the program.
Exceptions
FileExceptionType::FILE_WRITE_ERRORIf an error occurs while writing the string.
Returns
The function does nor return.
See also
STANDARD_OUTPUT
USAGE_FORMAT

Definition at line 317 of file Main.cpp.

References DefaultParameters, DescriptorTable, GraphicSpace::FILE_WRITE_ERROR, NumberOfElements, STANDARD_OUTPUT, and USAGE_FORMAT.

Referenced by main().

Here is the caller graph for this function:

◆ WriteProperties()

static void WriteProperties ( const Bitmap CurrentBitmap,
const char *  Path 
)
staticnoexcept
Description:
Write the properties of a bitmap image.
Parameters
CurrentBitmapReference to the bitmap.
PathPathname of the file.
Exceptions
FileExceptionType::FILE_OPEN_ERRORIf an error occurs while opening the file.
FileExceptionType::FILE_WRITE_ERRORIf an error occurs while writing the file.
FileExceptionType::FILE_CLOSE_ERRORIf an error occurs while closing the file.
Returns
None
Note
If Path is not a valid pointer to a zero terminated string, the behavior is undefined.
See also
IMAGE_SIZE_FORMAT
BITS_PER_PIXEL_FORMAT
FILE_SIZE_FORMAT
RESOLUTION_FORMAT

Definition at line 269 of file Main.cpp.

References BITS_PER_PIXEL_FORMAT, GraphicSpace::Bitmap::DIB_HEADER_SIZE, GraphicSpace::FILE_CLOSE_ERROR, GraphicSpace::FILE_OPEN_ERROR, FILE_SIZE_FORMAT, GraphicSpace::FILE_WRITE_ERROR, GraphicSpace::Bitmap::HEADER_SIZE, IMAGE_SIZE_FORMAT, OpenWriteText, and RESOLUTION_FORMAT.

Referenced by Application().

Here is the caller graph for this function:

Variable Documentation

◆ BITS_PER_PIXEL_FORMAT

BITS_PER_PIXEL_FORMAT
staticconstexpr
Initial value:
=
"Bits per pixel = %u\n"

Format string used to write the number of bits per pixel of the bitmap.

Definition at line 44 of file Main.cpp.

Referenced by WriteProperties().

◆ CORRECTING_MESSAGE

CORRECTING_MESSAGE
staticconstexpr
Initial value:
=
"Correcting the image with %u thread(s)\n"

Message that declares that image correction started.

Definition at line 87 of file Main.cpp.

Referenced by Application().

◆ DefaultParameters

DefaultParameters
static
Initial value:
=
{
1, 100, 100, 1.0, 0.5, 0.5, false, Bitmap::ChoiceType::MAXIMUM, false,
false
}

Correction parameters, initialized with default values.

Definition at line 109 of file Main.cpp.

Referenced by main(), GraphicSpace::NumericParameterDescriptor< NUMERIC_TYPE, EXCEPTION_TYPE >::PrintUsage(), GraphicSpace::EnumeratedParameterDescriptor< ENUMERATED_TYPE >::PrintUsage(), Randomize(), and Usage().

◆ DescriptorTable

DescriptorTable
Initial value:
=
{
("-Threads", 1, Bitmap::MAXIMUM_NUMBER_OF_THREADS,
&Bitmap::CorrectionParameters::Threads,
IntegerExceptionType::INVALID_NUMBER_OF_THREADS),
("-Termites", 1, Bitmap::MAXIMUM_NUMBER_OF_TERMITES,
&Bitmap::CorrectionParameters::Termites,
IntegerExceptionType::INVALID_NUMBER_OF_TERMITES),
("-Steps", 1, Bitmap::MAXIMUM_NUMBER_OF_STEPS,
&Bitmap::CorrectionParameters::Steps,
IntegerExceptionType::INVALID_NUMBER_OF_STEPS),
1.0, &Bitmap::CorrectionParameters::RepulsionStep,
FloatExceptionType::INVALID_REPULSION_STEP),
1.0, &Bitmap::CorrectionParameters::Alpha,
FloatExceptionType::INVALID_REPULSION_STEP),
1.0, &Bitmap::CorrectionParameters::Beta,
FloatExceptionType::INVALID_REPULSION_STEP),
&Bitmap::CorrectionParameters::RandomizeFlag,
EnumeratedExceptionType::INVALID_RANDOMIZE_PARAMETER),
&Bitmap::CorrectionParameters::ChoiceKind,
EnumeratedExceptionType::INVALID_PATH_CHOICE_PARAMETER),
&Bitmap::CorrectionParameters::TruncatePath,
EnumeratedExceptionType::INVALID_TRUNCATE_PATH_PARAMETER),
&Bitmap::CorrectionParameters::Quiet,
EnumeratedExceptionType::INVALID_QUIET_PARAMETER)
}

Table of descriptors of correction parameters.

Note
The order of the parameters correspond to the order in which they are printed when describing the usage of the program.

Definition at line 121 of file Main.cpp.

Referenced by main(), and Usage().

◆ END_CORRECTION_FORMAT

END_CORRECTION_FORMAT
staticconstexpr
Initial value:
=
"End of correction; elapsed time = %lu\n"

Format string used to write the message that declares that the correction is terminated.

Definition at line 93 of file Main.cpp.

Referenced by Application().

◆ END_READING_FORMAT

END_READING_FORMAT
staticconstexpr
Initial value:
=
"End of reading; elapsed time = %lu\n"

Format string used to write the message that declares that reading the input file is terminated.

Definition at line 82 of file Main.cpp.

Referenced by Application().

◆ END_WRITING_FORMAT

END_WRITING_FORMAT
staticconstexpr
Initial value:
=
"End of writing; elapsed time = %lu\n"

Format string used to write the message that declares that writing the output file is terminated.

Definition at line 104 of file Main.cpp.

Referenced by Application().

◆ FILE_SIZE_FORMAT

FILE_SIZE_FORMAT = "File size = %lu\n"
staticconstexpr

Format string used to write the file size of the bitmap.

Definition at line 49 of file Main.cpp.

Referenced by WriteProperties().

◆ IMAGE_SIZE_FORMAT

IMAGE_SIZE_FORMAT
staticconstexpr
Initial value:
=
"Width = %" PRIuFAST32 ", Height = %" PRIuFAST32 ", Size = %" PRIuFAST32
"\n"

Format string used to write the width and height of the bitmap.

Definition at line 38 of file Main.cpp.

Referenced by WriteProperties().

◆ INVALID_OPTION_FORMAT

INVALID_OPTION_FORMAT
staticconstexpr
Initial value:
=
"Invalid option %s\n"

Format string used to write the usage message.

Definition at line 71 of file Main.cpp.

Referenced by main().

◆ MAJOR_VERSION_NUMBER

MAJOR_VERSION_NUMBER = 1
staticconstexpr

Major version number.

Definition at line 26 of file Main.cpp.

Referenced by main().

◆ MINOR_VERSION_NUMBER

MINOR_VERSION_NUMBER = 1
staticconstexpr

Minor version number.

Definition at line 30 of file Main.cpp.

Referenced by main().

◆ OpenWriteText

OpenWriteText = "w"
staticconstexpr

String used to specify text write only mode when opening a file.

Definition at line 34 of file Main.cpp.

Referenced by WriteProperties().

◆ READING_FORMAT

READING_FORMAT = "Reading %s\n"
staticconstexpr

Format string used to write the message that declares that reading the input file is in progress.

Definition at line 77 of file Main.cpp.

Referenced by Application().

◆ RESOLUTION_FORMAT

RESOLUTION_FORMAT
staticconstexpr
Initial value:
=
"Horizontal resolution = %" PRIuFAST32 ", Vertical resolution = %"
PRIuFAST32 "\n"

Format string used to write the horizontal and vertical resolution of the bitmap.

Definition at line 54 of file Main.cpp.

Referenced by WriteProperties().

◆ USAGE_FORMAT

USAGE_FORMAT
staticconstexpr
Initial value:
=
"Usage: Graphic <Input Pathname> <Output Pathname> { <Options> }\n"
"where Options can be:\n"

Format string used to write the usage message.

Definition at line 65 of file Main.cpp.

Referenced by Usage().

◆ VERSION_FORMAT

VERSION_FORMAT
staticconstexpr
Initial value:
=
"Termite-Retinex correction program, version %u.%u\n\n"

Format string used to write the version number.

Definition at line 60 of file Main.cpp.

Referenced by main().

◆ WRITING_FORMAT

WRITING_FORMAT = "Writing %s\n"
staticconstexpr

Format string used to write the message that declares that writing the output file is in progress.

Definition at line 99 of file Main.cpp.

Referenced by Application().

GraphicSpace::EnumeratedParameterDescriptor
Definition: EnumeratedParameterDescriptor.h:37
GraphicSpace::NumericParameterDescriptor
Definition: NumericParameterDescriptor.h:41