summaryrefslogtreecommitdiff
path: root/src/bin/mj2/opj_mj2_extract.c
diff options
context:
space:
mode:
authorAntonin Descampe <antonin@gmail.com>2016-01-25 23:22:06 +0100
committerAntonin Descampe <antonin@gmail.com>2016-01-25 23:22:06 +0100
commit0febbff19e05cb1a6c2613eee76ad46a669c96cd (patch)
treeb6442d01348e2ba6404d0fd6abcc4eb6d6cc1390 /src/bin/mj2/opj_mj2_extract.c
parentbede1568b197021bb576b935422af6c1d0a79e21 (diff)
processed all c/h files through astyle with opj_astyle.cfgcodingstyle
Diffstat (limited to 'src/bin/mj2/opj_mj2_extract.c')
-rw-r--r--src/bin/mj2/opj_mj2_extract.c191
1 files changed, 97 insertions, 94 deletions
diff --git a/src/bin/mj2/opj_mj2_extract.c b/src/bin/mj2/opj_mj2_extract.c
index 25e6b79b..cb95788f 100644
--- a/src/bin/mj2/opj_mj2_extract.c
+++ b/src/bin/mj2/opj_mj2_extract.c
@@ -1,12 +1,12 @@
/*
- * The copyright in this software is being made available under the 2-clauses
- * BSD License, included below. This software may be subject to other third
+ * The copyright in this software is being made available under the 2-clauses
+ * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights
* are granted under this license.
*
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq
- * Copyright (c) 2003-2007, Francois-Olivier Devaux
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -46,110 +46,113 @@
/**
sample error callback expecting a FILE* client object
*/
-void error_callback(const char *msg, void *client_data) {
- FILE *stream = (FILE*)client_data;
- fprintf(stream, "[ERROR] %s", msg);
+void error_callback(const char *msg, void *client_data)
+{
+ FILE *stream = (FILE*)client_data;
+ fprintf(stream, "[ERROR] %s", msg);
}
/**
sample warning callback expecting a FILE* client object
*/
-void warning_callback(const char *msg, void *client_data) {
- FILE *stream = (FILE*)client_data;
- fprintf(stream, "[WARNING] %s", msg);
+void warning_callback(const char *msg, void *client_data)
+{
+ FILE *stream = (FILE*)client_data;
+ fprintf(stream, "[WARNING] %s", msg);
}
/**
sample debug callback expecting a FILE* client object
*/
-void info_callback(const char *msg, void *client_data) {
- FILE *stream = (FILE*)client_data;
- fprintf(stream, "[INFO] %s", msg);
+void info_callback(const char *msg, void *client_data)
+{
+ FILE *stream = (FILE*)client_data;
+ fprintf(stream, "[INFO] %s", msg);
}
/* -------------------------------------------------------------------------- */
-int main(int argc, char *argv[]) {
- opj_dinfo_t* dinfo;
- opj_event_mgr_t event_mgr; /* event manager */
- int tnum;
- unsigned int snum;
- opj_mj2_t *movie;
- mj2_tk_t *track;
- mj2_sample_t *sample;
- unsigned char* frame_codestream;
- FILE *file, *outfile;
- char outfilename[50];
- mj2_dparameters_t parameters;
-
- if (argc != 3) {
- printf("Usage: %s mj2filename output_location\n",argv[0]);
- printf("Example: %s foreman.mj2 output/foreman\n",argv[0]);
- return 1;
- }
-
- file = fopen(argv[1], "rb");
-
- if (!file) {
- fprintf(stderr, "failed to open %s for reading\n", argv[1]);
- return 1;
- }
-
- /*
- configure the event callbacks (not required)
- setting of each callback is optionnal
- */
- memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
- event_mgr.error_handler = error_callback;
- event_mgr.warning_handler = warning_callback;
- event_mgr.info_handler = info_callback;
-
- /* get a MJ2 decompressor handle */
- dinfo = mj2_create_decompress();
-
- /* catch events using our callbacks and give a local context */
- opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
-
- /* setup the decoder decoding parameters using user parameters */
- memset(&parameters, 0, sizeof(mj2_dparameters_t));
- movie = (opj_mj2_t*) dinfo->mj2_handle;
- mj2_setup_decoder(movie, &parameters);
-
- if (mj2_read_struct(file, movie)) /* Creating the movie structure*/
- return 1;
-
- /* Decode first video track */
- tnum = 0;
- while (movie->tk[tnum].track_type != 0)
- tnum ++;
-
- track = &movie->tk[tnum];
-
- fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
-
- for (snum=0; snum < track->num_samples; snum++)
- {
- sample = &track->sample[snum];
- frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
- fseek(file,sample->offset+8,SEEK_SET);
- fread(frame_codestream,sample->sample_size-8,1, file); /* Assuming that jp and ftyp markers size do*/
-
- sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
- outfile = fopen(outfilename, "wb");
- if (!outfile) {
- fprintf(stderr, "failed to open %s for writing\n",outfilename);
- return 1;
+int main(int argc, char *argv[])
+{
+ opj_dinfo_t* dinfo;
+ opj_event_mgr_t event_mgr; /* event manager */
+ int tnum;
+ unsigned int snum;
+ opj_mj2_t *movie;
+ mj2_tk_t *track;
+ mj2_sample_t *sample;
+ unsigned char* frame_codestream;
+ FILE *file, *outfile;
+ char outfilename[50];
+ mj2_dparameters_t parameters;
+
+ if (argc != 3) {
+ printf("Usage: %s mj2filename output_location\n",argv[0]);
+ printf("Example: %s foreman.mj2 output/foreman\n",argv[0]);
+ return 1;
}
- fwrite(frame_codestream,sample->sample_size-8,1,outfile);
- fclose(outfile);
- free(frame_codestream);
+
+ file = fopen(argv[1], "rb");
+
+ if (!file) {
+ fprintf(stderr, "failed to open %s for reading\n", argv[1]);
+ return 1;
+ }
+
+ /*
+ configure the event callbacks (not required)
+ setting of each callback is optionnal
+ */
+ memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+ event_mgr.error_handler = error_callback;
+ event_mgr.warning_handler = warning_callback;
+ event_mgr.info_handler = info_callback;
+
+ /* get a MJ2 decompressor handle */
+ dinfo = mj2_create_decompress();
+
+ /* catch events using our callbacks and give a local context */
+ opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
+
+ /* setup the decoder decoding parameters using user parameters */
+ memset(&parameters, 0, sizeof(mj2_dparameters_t));
+ movie = (opj_mj2_t*) dinfo->mj2_handle;
+ mj2_setup_decoder(movie, &parameters);
+
+ if (mj2_read_struct(file, movie)) /* Creating the movie structure*/
+ return 1;
+
+ /* Decode first video track */
+ tnum = 0;
+ while (movie->tk[tnum].track_type != 0)
+ tnum ++;
+
+ track = &movie->tk[tnum];
+
+ fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
+
+ for (snum=0; snum < track->num_samples; snum++) {
+ sample = &track->sample[snum];
+ frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
+ fseek(file,sample->offset+8,SEEK_SET);
+ fread(frame_codestream,sample->sample_size-8,1, file); /* Assuming that jp and ftyp markers size do*/
+
+ sprintf(outfilename,"%s_%05d.j2k",argv[2],snum);
+ outfile = fopen(outfilename, "wb");
+ if (!outfile) {
+ fprintf(stderr, "failed to open %s for writing\n",outfilename);
+ return 1;
+ }
+ fwrite(frame_codestream,sample->sample_size-8,1,outfile);
+ fclose(outfile);
+ free(frame_codestream);
}
- fclose(file);
- fprintf(stdout, "%d frames correctly extracted\n", snum);
-
- /* free remaining structures */
- if(dinfo) {
- mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
- }
-
- return 0;
+ fclose(file);
+ fprintf(stdout, "%d frames correctly extracted\n", snum);
+
+ /* free remaining structures */
+ if(dinfo) {
+ mj2_destroy_decompress((opj_mj2_t*)dinfo->mj2_handle);
+ }
+
+ return 0;
}