#include <string.h>
#include "openjpeg.h"
-#include "j2k.h"
-#include "jp2.h"
-#include "cio.h"
+#include "../libopenjpeg/j2k.h"
+#include "../libopenjpeg/jp2.h"
+#include "../libopenjpeg/cio.h"
#include "mj2.h"
static int int_ceildiv(int a, int b) {
{
int len,i;
char buf, buf2[2];
- char *siz_buffer;
+ unsigned char *siz_buffer;
opj_cio_t *cio;
fseek(file, 0, SEEK_SET);
fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1];
- siz_buffer = (char*) malloc(len * sizeof(char));
+ siz_buffer = (unsigned char*) malloc(len * sizeof(unsigned char));
fread(siz_buffer,len, 1, file);
cio = opj_cio_open(NULL, siz_buffer, len);
}
fseek(file, 0, SEEK_SET);
opj_cio_close(cio);
+ free(siz_buffer);
}
static void setparams(opj_mj2_t *movie, opj_image_t *image) {
movie->tk[0].depth = image->comps[0].prec;
if (image->numcomps==3) {
- if ((image->comps[0].dx == 1) && (image->comps[1].dx == 1) && (image->comps[1].dx == 1))
+ if ((image->comps[0].dx == 1)
+ && (image->comps[1].dx == 1)
+ && (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1;
- else if ((image->comps[0].dx == 1) && (image->comps[1].dx == 2) && (image->comps[1].dx == 2))
+ else
+ if ((image->comps[0].dx == 1)
+ && (image->comps[1].dx == 2)
+ && (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
- if ((image->comps[0].dy == 1) && (image->comps[1].dy == 1) && (image->comps[1].dy == 1))
+ if ((image->comps[0].dy == 1)
+ && (image->comps[1].dy == 1)
+ && (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1;
- else if ((image->comps[0].dy == 1) && (image->comps[1].dy == 2) && (image->comps[1].dy == 2))
+ else
+ if ((image->comps[0].dy == 1)
+ && (image->comps[1].dy == 2)
+ && (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2;
else
fprintf(stderr,"Image component sizes are incoherent\n");
else
movie->tk[0].jp2_struct.meth = 2;
- if (image->numcomps == 1)
- movie->tk[0].jp2_struct.enumcs = 17; // Grayscale
+ if (image->numcomps == 1)
+ movie->tk[0].jp2_struct.enumcs = 17; // Grayscale
- else if ((image->comps[0].dx == 1) && (image->comps[1].dx == 1) && (image->comps[1].dx == 1) &&
- (image->comps[0].dy == 1) && (image->comps[1].dy == 1) && (image->comps[1].dy == 1))
- movie->tk[0].jp2_struct.enumcs = 16; // RGB
+ else
+ if ((image->comps[0].dx == 1)
+ && (image->comps[1].dx == 1)
+ && (image->comps[2].dx == 1)
+ && (image->comps[0].dy == 1)
+ && (image->comps[1].dy == 1)
+ && (image->comps[2].dy == 1))
+ movie->tk[0].jp2_struct.enumcs = 16; // RGB
- else if ((image->comps[0].dx == 1) && (image->comps[1].dx == 2) && (image->comps[1].dx == 2) &&
- (image->comps[0].dy == 1) && (image->comps[1].dy == 2) && (image->comps[1].dy == 2))
- movie->tk[0].jp2_struct.enumcs = 18; // YUV
+ else
+ if ((image->comps[0].dx == 1)
+ && (image->comps[1].dx == 2)
+ && (image->comps[2].dx == 2)
+ && (image->comps[0].dy == 1)
+ && (image->comps[1].dy == 2)
+ && (image->comps[2].dy == 2))
+ movie->tk[0].jp2_struct.enumcs = 18; // YUV
else
movie->tk[0].jp2_struct.enumcs = 0; // Unkown profile */
unsigned char* frame_codestream;
FILE *mj2file, *j2kfile;
char j2kfilename[50];
- char *buf;
+ unsigned char *buf;
int offset, mdat_initpos;
opj_image_t img;
opj_cio_t *cio;
mj2_cparameters_t parameters;
if (argc != 3) {
- printf("Bad syntax: Usage: MJ2_Wrapper source_location mj2_filename\n");
- printf("Example: MJ2_Wrapper input/input output.mj2\n");
+ printf("Usage: %s source_location mj2_filename\n",argv[0]);
+ printf("Example: %s input/input output.mj2\n",argv[0]);
return 1;
}
/* setup the decoder encoding parameters using user parameters */
movie = (opj_mj2_t*) cinfo->mj2_handle;
- mj2_setup_encoder(cinfo->mj2_handle, ¶meters);
+ mj2_setup_encoder((opj_mj2_t*)cinfo->mj2_handle, ¶meters);
/* Writing JP, FTYP and MDAT boxes
Assuming that the JP and FTYP boxes won't be longer than 300 bytes */
- buf = (char*) malloc (300 * sizeof(char));
+ buf = (unsigned char*) malloc (300 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 300);
mj2_write_jp(cio);
mj2_write_ftyp(movie, cio);
while(1)
{
sample = &movie->tk[0].sample[snum];
- sprintf(j2kfilename,"%05d.j2k",/*argv[1],*/snum + 7111);
+ sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
j2kfile = fopen(j2kfilename, "rb");
if (!j2kfile) {
if (snum==0) { // Could not open a single codestream
// Ending loop
fclose(j2kfile);
snum++;
- movie->tk[0].sample = realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
- movie->tk[0].chunk = realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
+ movie->tk[0].sample = (mj2_sample_t*)
+ realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
+ movie->tk[0].chunk = (mj2_chunk_t*)
+ realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
free(frame_codestream);
}
// Writing the MDAT box length in header
offset += cio_tell(cio);
- buf = (char*) malloc (4 * sizeof(char));
+ buf = (unsigned char*) malloc (4 * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, 4);
cio_write(cio,offset-mdat_initpos,4);
fseek(mj2file,(long)mdat_initpos,SEEK_SET);
setparams(movie, &img);
// Writing MOOV box
- buf = (char*) malloc ((TEMP_BUF+snum*20) * sizeof(char));
+ buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20));
mj2_write_moov(movie, cio);
fwrite(buf,cio_tell(cio),1,mj2file);