diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2017-05-09 15:44:46 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2017-05-09 20:46:20 +0200 |
| commit | 563bd8499e63db976ca8358216138647593354bc (patch) | |
| tree | 003599ed2b0cffd932d2122c3f72c142070efafd /src/bin/jpip | |
| parent | d4e54e9f35d532062533f1d369c159810b01d224 (diff) | |
Reformat whole codebase with astyle.options (#128)
Diffstat (limited to 'src/bin/jpip')
| -rw-r--r-- | src/bin/jpip/opj_dec_server.c | 63 | ||||
| -rw-r--r-- | src/bin/jpip/opj_jpip_addxml.c | 207 | ||||
| -rw-r--r-- | src/bin/jpip/opj_jpip_test.c | 36 | ||||
| -rw-r--r-- | src/bin/jpip/opj_jpip_transcode.c | 107 | ||||
| -rw-r--r-- | src/bin/jpip/opj_server.c | 91 |
5 files changed, 259 insertions, 245 deletions
diff --git a/src/bin/jpip/opj_dec_server.c b/src/bin/jpip/opj_dec_server.c index f0b7fc13..8a42b982 100644 --- a/src/bin/jpip/opj_dec_server.c +++ b/src/bin/jpip/opj_dec_server.c @@ -42,7 +42,7 @@ * quit\n * Be sure all image viewers are closed.\n * Cache file in JPT format is stored in the working directly before it quites. - * + * */ #include <stdio.h> @@ -54,40 +54,45 @@ WSADATA initialisation_win32; #endif -int main(int argc, char *argv[]){ - - dec_server_record_t *server_record; - client_t client; - int port = 50000; - int erreur; - (void)erreur; +int main(int argc, char *argv[]) +{ + + dec_server_record_t *server_record; + client_t client; + int port = 50000; + int erreur; + (void)erreur; - if( argc > 1) - port = atoi( argv[1]); + if (argc > 1) { + port = atoi(argv[1]); + } #ifdef _WIN32 - erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32); - if( erreur!=0) - fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError()); - else - printf( "Initialisation Winsock\n"); + erreur = WSAStartup(MAKEWORD(2, 2), &initialisation_win32); + if (erreur != 0) { + fprintf(stderr, "Erreur initialisation Winsock error : %d %d\n", erreur, + WSAGetLastError()); + } else { + printf("Initialisation Winsock\n"); + } #endif /*_WIN32*/ - - server_record = init_dec_server( port); - - while(( client = accept_connection( server_record)) != -1 ) - if(!handle_clientreq( client, server_record)) - break; - - terminate_dec_server( &server_record); + + server_record = init_dec_server(port); + + while ((client = accept_connection(server_record)) != -1) + if (!handle_clientreq(client, server_record)) { + break; + } + + terminate_dec_server(&server_record); #ifdef _WIN32 - if( WSACleanup() != 0){ - printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError()); - }else{ - printf("\nWSACleanup OK\n"); - } + if (WSACleanup() != 0) { + printf("\nError in WSACleanup : %d %d", erreur, WSAGetLastError()); + } else { + printf("\nWSACleanup OK\n"); + } #endif - return 0; + return 0; } diff --git a/src/bin/jpip/opj_jpip_addxml.c b/src/bin/jpip/opj_jpip_addxml.c index 626fc5d1..22fdd05b 100644 --- a/src/bin/jpip/opj_jpip_addxml.c +++ b/src/bin/jpip/opj_jpip_addxml.c @@ -36,7 +36,7 @@ * -# Input/output image file in JP2 format, this JP2 file is being modified * -# Input XML file with metadata contents\n * % ./addXMLinJP2 image.jp2 metadata.xml\n - * + * * Currently, this program does not parse XML file, and the XML file contents is directly embedded as a XML Box.\n * The following is an example of XML file contents specifying Region Of Interests with target names.\n * <xmlbox>\n @@ -60,7 +60,7 @@ * @param[in] filename file name string * @return file descriptor */ -FILE * open_jp2file( const char filename[]); +FILE * open_jp2file(const char filename[]); /** @@ -70,115 +70,118 @@ FILE * open_jp2file( const char filename[]); * @param[out] fsize file byte size * @return pointer to the xml file content buffer */ -char * read_xmlfile( const char filename[], long *fsize); +char * read_xmlfile(const char filename[], long *fsize); int main(int argc, char *argv[]) { - FILE *fp; - char *xmldata, type[]="xml "; - long fsize, boxsize; - - if( argc<3){ - fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] ); - return -1; - } - - fp = open_jp2file( argv[1]); - if( !fp) - return -1; - - xmldata = read_xmlfile( argv[2], &fsize); - if( fsize < 0 ) return -1; - boxsize = fsize + 8; - - fputc( (boxsize>>24)&0xff, fp); - fputc( (boxsize>>16)&0xff, fp); - fputc( (boxsize>>8)&0xff, fp); - fputc( boxsize&0xff, fp); - fwrite( type, 4, 1, fp); - fwrite( xmldata, (size_t)fsize, 1, fp); - - free( xmldata); - fclose(fp); - - return 0; + FILE *fp; + char *xmldata, type[] = "xml "; + long fsize, boxsize; + + if (argc < 3) { + fprintf(stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0]); + return -1; + } + + fp = open_jp2file(argv[1]); + if (!fp) { + return -1; + } + + xmldata = read_xmlfile(argv[2], &fsize); + if (fsize < 0) { + return -1; + } + boxsize = fsize + 8; + + fputc((boxsize >> 24) & 0xff, fp); + fputc((boxsize >> 16) & 0xff, fp); + fputc((boxsize >> 8) & 0xff, fp); + fputc(boxsize & 0xff, fp); + fwrite(type, 4, 1, fp); + fwrite(xmldata, (size_t)fsize, 1, fp); + + free(xmldata); + fclose(fp); + + return 0; } -FILE * open_jp2file( const char filename[]) +FILE * open_jp2file(const char filename[]) { - FILE *fp; - char *data; - - if( !(fp = fopen( filename, "a+b"))){ - fprintf( stderr, "Original JP2 %s not found\n", filename); - return NULL; - } - /* Check resource is a JP family file. */ - if( fseek( fp, 0, SEEK_SET)==-1){ - fclose(fp); - fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename); - return NULL; - } - - data = (char *)malloc( 12); /* size of header */ - if( fread( data, 12, 1, fp) != 1){ - free( data); - fclose(fp); - fprintf( stderr, "Original JP2 %s broken (read error)\n", filename); - return NULL; - } - - if( *data || *(data + 1) || *(data + 2) || - *(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){ - free( data); - fclose(fp); - fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename); - return NULL; - } - free( data); - return fp; + FILE *fp; + char *data; + + if (!(fp = fopen(filename, "a+b"))) { + fprintf(stderr, "Original JP2 %s not found\n", filename); + return NULL; + } + /* Check resource is a JP family file. */ + if (fseek(fp, 0, SEEK_SET) == -1) { + fclose(fp); + fprintf(stderr, "Original JP2 %s broken (fseek error)\n", filename); + return NULL; + } + + data = (char *)malloc(12); /* size of header */ + if (fread(data, 12, 1, fp) != 1) { + free(data); + fclose(fp); + fprintf(stderr, "Original JP2 %s broken (read error)\n", filename); + return NULL; + } + + if (*data || *(data + 1) || *(data + 2) || + *(data + 3) != 12 || strncmp(data + 4, "jP \r\n\x87\n", 8)) { + free(data); + fclose(fp); + fprintf(stderr, "No JPEG 2000 Signature box in target %s\n", filename); + return NULL; + } + free(data); + return fp; } -char * read_xmlfile( const char filename[], long *fsize) +char * read_xmlfile(const char filename[], long *fsize) { - FILE *fp; - char *data; - - /* fprintf( stderr, "open %s\n", filename);*/ - if(!(fp = fopen( filename, "r"))){ - fprintf( stderr, "XML file %s not found\n", filename); - return NULL; - } - - if( fseek( fp, 0, SEEK_END) == -1){ - fprintf( stderr, "XML file %s broken (seek error)\n", filename); - fclose( fp); - return NULL; - } - - if( (*fsize = ftell( fp)) == -1){ - fprintf( stderr, "XML file %s broken (seek error)\n", filename); - fclose( fp); - return NULL; - } - assert( *fsize >= 0 ); - - if( fseek( fp, 0, SEEK_SET) == -1){ - fprintf( stderr, "XML file %s broken (seek error)\n", filename); - fclose( fp); - return NULL; - } - - data = (char *)malloc( (size_t)*fsize); - - if( fread( data, (size_t)*fsize, 1, fp) != 1){ - fprintf( stderr, "XML file %s broken (read error)\n", filename); - free( data); - fclose(fp); - return NULL; - } + FILE *fp; + char *data; + + /* fprintf( stderr, "open %s\n", filename);*/ + if (!(fp = fopen(filename, "r"))) { + fprintf(stderr, "XML file %s not found\n", filename); + return NULL; + } + + if (fseek(fp, 0, SEEK_END) == -1) { + fprintf(stderr, "XML file %s broken (seek error)\n", filename); + fclose(fp); + return NULL; + } + + if ((*fsize = ftell(fp)) == -1) { + fprintf(stderr, "XML file %s broken (seek error)\n", filename); + fclose(fp); + return NULL; + } + assert(*fsize >= 0); + + if (fseek(fp, 0, SEEK_SET) == -1) { + fprintf(stderr, "XML file %s broken (seek error)\n", filename); + fclose(fp); + return NULL; + } + + data = (char *)malloc((size_t) * fsize); + + if (fread(data, (size_t)*fsize, 1, fp) != 1) { + fprintf(stderr, "XML file %s broken (read error)\n", filename); + free(data); + fclose(fp); + return NULL; + } - fclose( fp); + fclose(fp); - return data; + return data; } diff --git a/src/bin/jpip/opj_jpip_test.c b/src/bin/jpip/opj_jpip_test.c index 1b4fc1c6..f86ec4a6 100644 --- a/src/bin/jpip/opj_jpip_test.c +++ b/src/bin/jpip/opj_jpip_test.c @@ -51,23 +51,25 @@ int main(int argc, char *argv[]) { - int fd; - index_t *jp2idx; - if( argc < 2 ) return 1; - - if( (fd = open( argv[1], O_RDONLY)) == -1){ - fprintf( stderr, "Error: Target %s not found\n", argv[1]); - return -1; - } + int fd; + index_t *jp2idx; + if (argc < 2) { + return 1; + } - if( !(jp2idx = get_index_from_JP2file( fd))){ - fprintf( stderr, "JP2 file broken\n"); - return -1; - } - - output_index( jp2idx); - destroy_index( &jp2idx); - close(fd); + if ((fd = open(argv[1], O_RDONLY)) == -1) { + fprintf(stderr, "Error: Target %s not found\n", argv[1]); + return -1; + } - return 0; + if (!(jp2idx = get_index_from_JP2file(fd))) { + fprintf(stderr, "JP2 file broken\n"); + return -1; + } + + output_index(jp2idx); + destroy_index(&jp2idx); + close(fd); + + return 0; } /* main */ diff --git a/src/bin/jpip/opj_jpip_transcode.c b/src/bin/jpip/opj_jpip_transcode.c index 19570af5..6cd2604d 100644 --- a/src/bin/jpip/opj_jpip_transcode.c +++ b/src/bin/jpip/opj_jpip_transcode.c @@ -44,23 +44,25 @@ */ static int jpip_to_jp2(char *argv[]) { - jpip_dec_param_t *dec; - - dec = init_jpipdecoder( OPJ_TRUE); - - if(!( fread_jpip( argv[1], dec))) - return 1; - - decode_jpip( dec); - - if(!(fwrite_jp2k( argv[2], dec))) - return 1; + jpip_dec_param_t *dec; + + dec = init_jpipdecoder(OPJ_TRUE); - /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */ + if (!(fread_jpip(argv[1], dec))) { + return 1; + } + + decode_jpip(dec); - destroy_jpipdecoder( &dec); + if (!(fwrite_jp2k(argv[2], dec))) { + return 1; + } - return 0; + /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */ + + destroy_jpipdecoder(&dec); + + return 0; } /*! \file @@ -76,49 +78,48 @@ static int jpip_to_jp2(char *argv[]) */ static int jpip_to_j2k(char *argv[]) { - jpip_dec_param_t *dec; - - dec = init_jpipdecoder( OPJ_FALSE); - - if(!( fread_jpip( argv[1], dec))) - return 1; - - decode_jpip( dec); - - if(!(fwrite_jp2k( argv[2], dec))) - return 1; - - /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */ - - destroy_jpipdecoder( &dec); + jpip_dec_param_t *dec; + + dec = init_jpipdecoder(OPJ_FALSE); - return 0; + if (!(fread_jpip(argv[1], dec))) { + return 1; + } + + decode_jpip(dec); + + if (!(fwrite_jp2k(argv[2], dec))) { + return 1; + } + + /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */ + + destroy_jpipdecoder(&dec); + + return 0; } -int main(int argc,char *argv[]) +int main(int argc, char *argv[]) { - char *ext; - if( argc < 3){ - fprintf( stderr, "Too few arguments:\n"); - fprintf( stderr, " - input jpt or jpp file\n"); - fprintf( stderr, " - output j2k file\n"); - return 1; - } - - ext = strrchr( argv[2], '.' ); - if( ext ) - { - /* strcasecmp ? */ - if( strcmp(ext, ".jp2" ) == 0 ) - { - return jpip_to_jp2(argv); - } - if( strcmp(ext, ".j2k" ) == 0 ) - { - return jpip_to_j2k(argv); - } + char *ext; + if (argc < 3) { + fprintf(stderr, "Too few arguments:\n"); + fprintf(stderr, " - input jpt or jpp file\n"); + fprintf(stderr, " - output j2k file\n"); + return 1; } - fprintf( stderr, "Invalid file extension for output file: %s\n", argv[2]); - return 1; + ext = strrchr(argv[2], '.'); + if (ext) { + /* strcasecmp ? */ + if (strcmp(ext, ".jp2") == 0) { + return jpip_to_jp2(argv); + } + if (strcmp(ext, ".j2k") == 0) { + return jpip_to_j2k(argv); + } + } + + fprintf(stderr, "Invalid file extension for output file: %s\n", argv[2]); + return 1; } diff --git a/src/bin/jpip/opj_server.c b/src/bin/jpip/opj_server.c index ec91e9c2..ad0b16a9 100644 --- a/src/bin/jpip/opj_server.c +++ b/src/bin/jpip/opj_server.c @@ -3,7 +3,7 @@ * * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Professor Benoit Macq - * Copyright (c) 2010-2011, Kaori Hagihara + * Copyright (c) 2010-2011, Kaori Hagihara * Copyright (c) 2011, Lucian Corlaciu, GSoC * All rights reserved. * @@ -41,7 +41,7 @@ * * Note: JP2 files are stored in the working directory of opj_server\n * Check README for the JP2 Encoding\n - * + * * We tested this software with a virtual server running on the same Linux machine as the clients. */ @@ -60,69 +60,72 @@ WSADATA initialisation_win32; #endif /*_WIN32*/ int main(void) -{ - server_record_t *server_record; +{ + server_record_t *server_record; #ifdef SERVER - char *query_string; + char *query_string; #endif #ifdef _WIN32 - int erreur = WSAStartup(MAKEWORD(2,2),&initialisation_win32); - if( erreur!=0) - fprintf( stderr, "Erreur initialisation Winsock error : %d %d\n",erreur,WSAGetLastError()); - else - fprintf( stderr, "Initialisation Winsock\n"); + int erreur = WSAStartup(MAKEWORD(2, 2), &initialisation_win32); + if (erreur != 0) { + fprintf(stderr, "Erreur initialisation Winsock error : %d %d\n", erreur, + WSAGetLastError()); + } else { + fprintf(stderr, "Initialisation Winsock\n"); + } #endif /*_WIN32*/ - server_record = init_JPIPserver( 60000, 0); + server_record = init_JPIPserver(60000, 0); #ifdef SERVER - while(FCGI_Accept() >= 0) + while (FCGI_Accept() >= 0) #else - char query_string[128]; - while( fgets( query_string, 128, stdin) && query_string[0]!='\n') + char query_string[128]; + while (fgets(query_string, 128, stdin) && query_string[0] != '\n') #endif { - QR_t *qr; - OPJ_BOOL parse_status; + QR_t *qr; + OPJ_BOOL parse_status; -#ifdef SERVER - query_string = getenv("QUERY_STRING"); +#ifdef SERVER + query_string = getenv("QUERY_STRING"); #endif /*SERVER*/ - if( strcmp( query_string, QUIT_SIGNAL) == 0) - break; - - qr = parse_querystring( query_string); - - parse_status = process_JPIPrequest( server_record, qr); - + if (strcmp(query_string, QUIT_SIGNAL) == 0) { + break; + } + + qr = parse_querystring(query_string); + + parse_status = process_JPIPrequest(server_record, qr); + #ifndef SERVER - local_log( OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record); + local_log(OPJ_TRUE, OPJ_TRUE, parse_status, OPJ_FALSE, qr, server_record); #endif - - if( parse_status) - send_responsedata( server_record, qr); - else{ - fprintf( FCGI_stderr, "Error: JPIP request failed\n"); - fprintf( FCGI_stdout, "\r\n"); - } - - end_QRprocess( server_record, &qr); + + if (parse_status) { + send_responsedata(server_record, qr); + } else { + fprintf(FCGI_stderr, "Error: JPIP request failed\n"); + fprintf(FCGI_stdout, "\r\n"); + } + + end_QRprocess(server_record, &qr); } - - fprintf( FCGI_stderr, "JPIP server terminated by a client request\n"); - terminate_JPIPserver( &server_record); + fprintf(FCGI_stderr, "JPIP server terminated by a client request\n"); + + terminate_JPIPserver(&server_record); #ifdef _WIN32 - if( WSACleanup() != 0){ - fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError()); - }else{ - fprintf( stderr, "\nWSACleanup OK\n"); - } + if (WSACleanup() != 0) { + fprintf(stderr, "\nError in WSACleanup : %d %d", erreur, WSAGetLastError()); + } else { + fprintf(stderr, "\nWSACleanup OK\n"); + } #endif - return 0; + return 0; } |
