2011-08-31 15:33:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011, Mickael Savinaud, Communications & Systemes <mickael.savinaud@c-s.fr>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* compareRAWimages.c
|
|
|
|
*
|
|
|
|
* Created on: 31 August 2011
|
|
|
|
* Author: mickael
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
2011-09-01 13:24:08 +02:00
|
|
|
#include "opj_getopt.h"
|
2011-08-31 15:33:40 +02:00
|
|
|
|
|
|
|
void compareRAWimages_help_display(void);
|
|
|
|
|
|
|
|
typedef struct test_cmp_parameters
|
|
|
|
{
|
|
|
|
/** */
|
|
|
|
char* base_filename;
|
|
|
|
/** */
|
|
|
|
char* test_filename;
|
|
|
|
} test_cmp_parameters;
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Command line help function
|
|
|
|
*******************************************************************************/
|
|
|
|
void compareRAWimages_help_display(void) {
|
|
|
|
fprintf(stdout,"\nList of parameters for the comparePGX function \n");
|
|
|
|
fprintf(stdout,"\n");
|
|
|
|
fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n");
|
|
|
|
fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n");
|
|
|
|
fprintf(stdout,"\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* Parse command line
|
|
|
|
*******************************************************************************/
|
2012-10-15 17:47:56 +02:00
|
|
|
static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param)
|
2011-08-31 15:33:40 +02:00
|
|
|
{
|
|
|
|
int sizemembasefile, sizememtestfile;
|
|
|
|
int index;
|
|
|
|
const char optlist[] = "b:t:";
|
|
|
|
int c;
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* Init parameters*/
|
2011-08-31 15:33:40 +02:00
|
|
|
param->base_filename = NULL;
|
|
|
|
param->test_filename = NULL;
|
|
|
|
|
2011-09-01 13:24:08 +02:00
|
|
|
opj_opterr = 0;
|
2011-09-02 10:34:38 +02:00
|
|
|
while ((c = opj_getopt(argc, argv, optlist)) != -1)
|
2011-08-31 15:33:40 +02:00
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'b':
|
2011-09-01 13:24:08 +02:00
|
|
|
sizemembasefile = (int)strlen(opj_optarg)+1;
|
2011-08-31 15:33:40 +02:00
|
|
|
param->base_filename = (char*) malloc(sizemembasefile);
|
|
|
|
param->base_filename[0] = '\0';
|
2011-09-01 13:24:08 +02:00
|
|
|
strncpy(param->base_filename, opj_optarg, strlen(opj_optarg));
|
|
|
|
param->base_filename[strlen(opj_optarg)] = '\0';
|
2012-03-02 16:07:07 +01:00
|
|
|
/*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/
|
2011-08-31 15:33:40 +02:00
|
|
|
break;
|
|
|
|
case 't':
|
2011-09-01 13:24:08 +02:00
|
|
|
sizememtestfile = (int) strlen(opj_optarg) + 1;
|
2011-08-31 15:33:40 +02:00
|
|
|
param->test_filename = (char*) malloc(sizememtestfile);
|
|
|
|
param->test_filename[0] = '\0';
|
2011-09-01 13:24:08 +02:00
|
|
|
strncpy(param->test_filename, opj_optarg, strlen(opj_optarg));
|
|
|
|
param->test_filename[strlen(opj_optarg)] = '\0';
|
2012-03-02 16:07:07 +01:00
|
|
|
/*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/
|
2011-08-31 15:33:40 +02:00
|
|
|
break;
|
|
|
|
case '?':
|
2011-09-01 13:24:08 +02:00
|
|
|
if ((opj_optopt == 'b') || (opj_optopt == 't'))
|
|
|
|
fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt);
|
2011-08-31 15:33:40 +02:00
|
|
|
else
|
2011-09-01 13:24:08 +02:00
|
|
|
if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt);
|
|
|
|
else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt);
|
2011-08-31 15:33:40 +02:00
|
|
|
return 1;
|
|
|
|
default:
|
2011-09-01 13:24:08 +02:00
|
|
|
fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg);
|
2011-08-31 15:33:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-01 13:24:08 +02:00
|
|
|
if (opj_optind != argc) {
|
|
|
|
for (index = opj_optind; index < argc; index++)
|
2011-08-31 15:33:40 +02:00
|
|
|
fprintf(stderr,"Non-option argument %s\n", argv[index]);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* MAIN
|
|
|
|
*******************************************************************************/
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
test_cmp_parameters inParam;
|
|
|
|
FILE *file_test=NULL, *file_base=NULL;
|
|
|
|
unsigned char equal = 1;
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* Get parameters from command line*/
|
2011-08-31 15:33:40 +02:00
|
|
|
if (parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE)
|
|
|
|
{
|
|
|
|
compareRAWimages_help_display();
|
2011-10-19 15:06:49 +02:00
|
|
|
|
|
|
|
/* Free Memory */
|
|
|
|
if (inParam.base_filename){
|
|
|
|
free(inParam.base_filename);
|
|
|
|
inParam.base_filename = NULL;
|
|
|
|
}
|
|
|
|
if (inParam.test_filename){
|
|
|
|
free(inParam.test_filename);
|
|
|
|
inParam.test_filename = NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-31 15:33:40 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_test = fopen(inParam.test_filename, "rb");
|
|
|
|
if (!file_test) {
|
|
|
|
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename);
|
2011-10-19 15:06:49 +02:00
|
|
|
|
|
|
|
/* Free Memory */
|
|
|
|
if (inParam.base_filename){
|
|
|
|
free(inParam.base_filename);
|
|
|
|
inParam.base_filename = NULL;
|
|
|
|
}
|
|
|
|
if (inParam.test_filename){
|
|
|
|
free(inParam.test_filename);
|
|
|
|
inParam.test_filename = NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-31 15:33:40 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_base = fopen(inParam.base_filename, "rb");
|
|
|
|
if (!file_base) {
|
|
|
|
fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename);
|
2011-10-19 15:06:49 +02:00
|
|
|
|
|
|
|
/* Free Memory */
|
|
|
|
if (inParam.base_filename){
|
|
|
|
free(inParam.base_filename);
|
|
|
|
inParam.base_filename = NULL;
|
|
|
|
}
|
|
|
|
if (inParam.test_filename){
|
|
|
|
free(inParam.test_filename);
|
|
|
|
inParam.test_filename = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(file_test);
|
2011-08-31 15:33:40 +02:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* Read simultaneously the two files*/
|
2011-08-31 15:33:40 +02:00
|
|
|
while (equal)
|
|
|
|
{
|
|
|
|
unsigned char value_test = 0;
|
|
|
|
unsigned char eof_test = 0;
|
|
|
|
unsigned char value_base = 0;
|
|
|
|
unsigned char eof_base = 0;
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* Read one byte*/
|
2011-08-31 15:33:40 +02:00
|
|
|
if (!fread(&value_test, 1, 1, file_test)) {
|
|
|
|
eof_test = 1;
|
|
|
|
}
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* Read one byte*/
|
2011-08-31 15:33:40 +02:00
|
|
|
if (!fread(&value_base, 1, 1, file_base)) {
|
|
|
|
eof_base = 1;;
|
|
|
|
}
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* End of file reached by the two files?*/
|
2011-08-31 15:33:40 +02:00
|
|
|
if (eof_test && eof_base)
|
|
|
|
break;
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* End of file reached only by one file?*/
|
2011-08-31 15:33:40 +02:00
|
|
|
if (eof_test || eof_base)
|
|
|
|
{
|
|
|
|
fprintf(stdout,"Files have different sizes.\n");
|
|
|
|
equal = 0;
|
|
|
|
}
|
|
|
|
|
2012-03-02 16:07:07 +01:00
|
|
|
/* Binary values are equal?*/
|
2011-08-31 15:33:40 +02:00
|
|
|
if (value_test != value_base)
|
|
|
|
{
|
|
|
|
fprintf(stdout,"Binary values read in the file are different.\n");
|
|
|
|
equal = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-19 15:06:49 +02:00
|
|
|
/* Free Memory */
|
|
|
|
if (inParam.base_filename){
|
|
|
|
free(inParam.base_filename);
|
|
|
|
inParam.base_filename = NULL;
|
|
|
|
}
|
|
|
|
if (inParam.test_filename){
|
|
|
|
free(inParam.test_filename);
|
|
|
|
inParam.test_filename = NULL;
|
|
|
|
}
|
|
|
|
|
2011-08-31 15:33:40 +02:00
|
|
|
fclose(file_test);
|
|
|
|
fclose(file_base);
|
|
|
|
|
|
|
|
if (equal)
|
|
|
|
{
|
|
|
|
fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n");
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|