* POSSIBILITY OF SUCH DAMAGE.
*/
-#include "opj_includes.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "openjpeg.h"
+#include "../libopenjpeg/j2k_lib.h"
+#include "../libopenjpeg/j2k.h"
+#include "../libopenjpeg/jp2.h"
+#include "../libopenjpeg/cio.h"
#include "mj2.h"
#include "mj2_convert.h"
-#include "compat/getopt.h"
+#include "getopt.h"
/**
Size of memory first allocated for MOOV box
void help_display()
{
- fprintf(stdout,"HELP\n----\n\n");
+ fprintf(stdout,"HELP for frames_to_mj2\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n");
fprintf
(stdout,"COD and QCD never appear in the tile_header.\n");
fprintf(stdout,"\n");
- fprintf
- (stdout,"- This coder can encode a mega image, a test was made on a 24000x24000 pixels \n");
- fprintf
- (stdout,"color image. You need enough disk space memory (twice the original) to encode \n");
- fprintf
- (stdout,"the image,i.e. for a 1.5 GB image you need a minimum of 3GB of disk memory)\n");
- fprintf(stdout,"\n");
fprintf(stdout,"By default:\n");
fprintf(stdout,"------------\n");
fprintf(stdout,"\n");
(stdout," Indicate multiple modes by adding their values. \n");
fprintf
(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
- fprintf
- (stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
fprintf
(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n");
fprintf
opj_cparameters_t *j2k_parameters; /* J2K compression parameters */
opj_event_mgr_t event_mgr; /* event manager */
opj_cio_t *cio;
- char value;
+ int value;
opj_mj2_t *movie;
opj_image_t *img;
int i, j;
char *s, S1, S2, S3;
- char *buf;
+ unsigned char *buf;
int x1, y1, len;
long mdat_initpos, offset;
FILE *mj2file;
opj_cinfo_t* cinfo;
bool bSuccess;
int numframes;
- double total_time = 0;
+ double total_time = 0;
/* default value */
/* ------------- */
mj2_parameters.h = 288; // CIF default value
mj2_parameters.CbCr_subsampling_dx = 2; // CIF default value
mj2_parameters.CbCr_subsampling_dy = 2; // CIF default value
- mj2_parameters.frame_rate = 25;
-
+ mj2_parameters.frame_rate = 25;
/*
configure the event callbacks (not required)
setting of each callback is optionnal
sprintf(j2k_parameters->cp_comment,"%s%s", comment, version);
}
+ mj2_parameters.decod_format = 0;
+ mj2_parameters.cod_format = 0;
while (1) {
int c = getopt(argc, argv,
- "i:o:r:q:f:t:n:c:b:x:p:s:d:h P:S:E:M:R:T:C:I:W:F:");
+ "i:o:r:q:f:t:n:c:b:p:s:d:P:S:E:M:R:T:C:I:W:F:h");
if (c == -1)
break;
switch (c) {
}
break;
/* ----------------------------------------------------- */
- case 'x': /* creation of index file */
- {
- char *index = optarg;
- strncpy(j2k_parameters->index, index, sizeof(j2k_parameters->index)-1);
- j2k_parameters->index_on = 1;
- }
- break;
- /* ----------------------------------------------------- */
case 'p': /* progression order */
{
char progression[4];
while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile,
&POC[numpocs].resno0, &POC[numpocs].compno0,
&POC[numpocs].layno1, &POC[numpocs].resno1,
- &POC[numpocs].compno1, &POC[numpocs].progorder) == 7) {
+ &POC[numpocs].compno1, POC[numpocs].progorder) == 7) {
POC[numpocs].prg1 = give_progression(POC[numpocs].progorder);
numpocs++;
while (*s && *s != '/') {
/* Error messages */
/* -------------- */
- if (!mj2_parameters.infile || !mj2_parameters.outfile) {
+ if (!mj2_parameters.cod_format || !mj2_parameters.decod_format) {
fprintf(stderr,
- "Correct usage: mj2_encoder -i yuv-file -o mj2-file (+ options)\n");
+ "Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]);
return 1;
}
/* get a MJ2 decompressor handle */
cinfo = mj2_create_compress();
- movie = cinfo->mj2_handle;
+ movie = (opj_mj2_t*)cinfo->mj2_handle;
/* catch events using our callbacks and give a local context */
opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
mj2_setup_encoder(movie, &mj2_parameters);
movie->tk[0].num_samples = yuv_num_frames(&movie->tk[0],mj2_parameters.infile);
- if (!movie->tk[0].num_samples) {
- fprintf(stderr,"Unable to count the number of frames in YUV input file\n");
+ if (movie->tk[0].num_samples == -1) {
+ return 1;
}
// One sample per chunk
};
// Writing JP, FTYP and MDAT boxes
- buf = (char*) malloc (300 * sizeof(char)); // Assuming that the JP and FTYP
+ buf = (unsigned char*) malloc (300 * sizeof(unsigned char)); // Assuming that the JP and FTYP
// boxes won't be longer than 300 bytes
cio = opj_cio_open((opj_common_ptr)movie->cinfo, buf, 300);
mj2_write_jp(cio);
cio_write(cio, MJ2_MDAT, 4);
fwrite(buf,cio_tell(cio),1,mj2file);
offset = cio_tell(cio);
- opj_free(buf);
-
+ opj_cio_close(cio);
+ free(buf);
+
for (i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++) {
if (movie->tk[i].track_type != 0) {
fprintf(stderr, "Unable to write sound or hint tracks\n");
img = mj2_image_create(tk, j2k_parameters);
buflen = 2 * (tk->w * tk->h * 8);
- buf = (char *) malloc(buflen*sizeof(char));
+ buf = (unsigned char *) malloc(buflen*sizeof(unsigned char));
for (sampleno = 0; sampleno < numframes; sampleno++) {
double init_time = opj_clock();
double elapsed_time;
- if (!yuvtoimage(tk, img, sampleno, j2k_parameters, mj2_parameters.infile)) {
+ if (yuvtoimage(tk, img, sampleno, j2k_parameters, mj2_parameters.infile)) {
fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno);
return 1;
}
cio_write(cio, JP2_JP2C, 4); // JP2C
/* encode the image */
- bSuccess = opj_encode(cinfo, cio, img, j2k_parameters->index);
+ bSuccess = opj_encode(cinfo, cio, img, NULL);
if (!bSuccess) {
opj_cio_close(cio);
fprintf(stderr, "failed to encode image\n");
len = cio_tell(cio) - 8;
cio_seek(cio, 0);
cio_write(cio, len+8,4);
+ opj_cio_close(cio);
tk->sample[sampleno].sample_size = len+8;
tk->sample[sampleno].offset = offset;
tk->chunk[sampleno].offset = offset; // There is one sample per chunk
}
/* free buffer data */
- opj_free(buf);
+ free(buf);
/* free image data */
opj_image_destroy(img);
}
fseek(mj2file, mdat_initpos, SEEK_SET);
- buf = (char*) malloc(4*sizeof(char));
+ buf = (unsigned char*) malloc(4*sizeof(unsigned char));
// Init a cio to write box length variable in a little endian way
cio = opj_cio_open(NULL, buf, 4);
cio_write(cio, offset - mdat_initpos, 4);
fwrite(buf, 4, 1, mj2file);
fseek(mj2file,0,SEEK_END);
- opj_free(buf);
-
+ free(buf);
+
// Writing MOOV box
- buf = (char*) malloc ((TEMP_BUF+numframes*20) * sizeof(char));
+ buf = (unsigned char*) malloc ((TEMP_BUF+numframes*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+numframes*20));
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);
+ free(buf);
fprintf(stdout,"Total encoding time: %.2f s for %d frames (%.1f fps)\n", total_time, numframes, (float)numframes/total_time);