rename jp2_write_jp_v2 to opj_jp2_write_jp
[openjpeg.git] / libopenjpeg / jp2.c
index b73b7578e206bcf33dc235a77307373ef0757834..2c3faf614a35b6e711c25064d1940abeca854817 100644 (file)
@@ -98,8 +98,6 @@ static opj_bool opj_jp2_read_cdef(    opj_jp2_v2_t * jp2,
                                     OPJ_BYTE * p_cdef_header_data,
                                                                        OPJ_UINT32 p_cdef_header_size,
                                                                        opj_event_mgr_t * p_manager );
-
-static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio);
 /**
  * Writes the Colour Specification box.
  *
@@ -108,16 +106,8 @@ static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio);
  * 
  * @return     the data being copied.
 */
-static unsigned char *jp2_write_colr_v2(opj_jp2_v2_t *jp2, 
-                                                                               unsigned int * p_nb_bytes_written );
-
-/**
-Write the FTYP box - File type box
-@param jp2 JP2 handle
-@param cio Output buffer stream
-*/
-static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
-
+static OPJ_BYTE * opj_jp2_write_colr(   opj_jp2_v2_t *jp2, 
+                                                                           OPJ_UINT32 * p_nb_bytes_written );
 
 /**
  * Writes a FTYP box - File type box
@@ -128,9 +118,9 @@ static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio);
  * 
  * @return     true if writting was successful.
  */
-static opj_bool jp2_write_ftyp_v2(     opj_jp2_v2_t *jp2,
-                                                                       struct opj_stream_private *cio,
-                                                                       struct opj_event_mgr * p_manager );
+static opj_bool opj_jp2_write_ftyp(    opj_jp2_v2_t *jp2,
+                                                                       opj_stream_private_t *cio,
+                                                                       opj_event_mgr_t * p_manager );
 
 /**
  * Reads a a FTYP box - File type box
@@ -156,9 +146,9 @@ static opj_bool opj_jp2_read_ftyp(  opj_jp2_v2_t *jp2,
  *
  * @return true if writting was successful.
 */
-opj_bool jp2_skip_jp2c(        opj_jp2_v2_t *jp2,
-                                               struct opj_stream_private *cio,
-                                               struct opj_event_mgr * p_manager );
+opj_bool opj_jp2_skip_jp2c(    opj_jp2_v2_t *jp2,
+                                                   opj_stream_private_t *cio,
+                                                   opj_event_mgr_t * p_manager );
 
 /**
  * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box).
@@ -175,9 +165,6 @@ static opj_bool opj_jp2_read_jp2h(  opj_jp2_v2_t *jp2,
                                     OPJ_UINT32 p_header_size,
                                     opj_event_mgr_t * p_manager );
 
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info);
-
-
 /**
  * Writes the Jpeg2000 codestream Header box - JP2C Header box. This function must be called AFTER the coding has been done.
  *
@@ -187,11 +174,9 @@ static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, op
  *
  * @return true if writting was successful.
 */
-static opj_bool jp2_write_jp2c_v2(     opj_jp2_v2_t *jp2,
-                                                               struct opj_stream_private *cio,
-                                                               struct opj_event_mgr * p_manager );
-
-static void jp2_write_jp(opj_cio_t *cio);
+static opj_bool opj_jp2_write_jp2c(    opj_jp2_v2_t *jp2,
+                                                                   opj_stream_private_t *cio,
+                                                                   opj_event_mgr_t * p_manager );
 
 /**
  * Reads a jpeg2000 file signature box.
@@ -208,6 +193,19 @@ static opj_bool opj_jp2_read_jp(opj_jp2_v2_t *jp2,
                                 OPJ_UINT32 p_header_size,
                                 opj_event_mgr_t * p_manager);
 
+/**
+ * Writes a jpeg2000 file signature box.
+ *
+ * @param cio the stream to write data to.
+ * @param      jp2                     the jpeg2000 file codec.
+ * @param p_manager the user event manager.
+ * 
+ * @return true if writting was successful.
+ */
+static opj_bool opj_jp2_write_jp(      opj_jp2_v2_t *jp2,
+                                                   opj_stream_private_t *cio,
+                                                       opj_event_mgr_t * p_manager );
+
 /**
 Apply collected palette data
 @param color Collector for profile, cdef and pclr data
@@ -291,7 +289,7 @@ static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int le
  * Sets up the procedures to do on writting header after the codestream.
  * Developpers wanting to extend the library can add their own writting procedures.
  */
-static void jp2_setup_end_header_writting (opj_jp2_v2_t *jp2);
+static void opj_jp2_setup_end_header_writting (opj_jp2_v2_t *jp2);
 
 
 /**
@@ -347,13 +345,13 @@ static opj_bool opj_jp2_read_boxhdr(opj_jp2_box_t *box,
  * Sets up the validation ,i.e. adds the procedures to lauch to make sure the codec parameters
  * are valid. Developpers wanting to extend the library can add their own validation procedures.
  */
-static void jp2_setup_encoding_validation (opj_jp2_v2_t *jp2);
+static void opj_jp2_setup_encoding_validation (opj_jp2_v2_t *jp2);
 
 
 /**
  * Sets up the procedures to do on writting header. Developpers wanting to extend the library can add their own writting procedures.
  */
-static void jp2_setup_header_writting (opj_jp2_v2_t *jp2);
+static void opj_jp2_setup_header_writting (opj_jp2_v2_t *jp2);
 
 /**
  * The default validation procedure without any extension.
@@ -651,7 +649,8 @@ OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_v2_t *jp2,
  * @return     the data being copied.
 */
 OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_v2_t *jp2, 
-                                                       OPJ_UINT32 * p_nb_bytes_written );
+                                                       OPJ_UINT32 * p_nb_bytes_written 
+                                )
 {
        unsigned int i;
        /* room for 8 bytes for box and 1 byte for each component */
@@ -730,28 +729,6 @@ opj_bool opj_jp2_read_bpcc( opj_jp2_v2_t *jp2,
        return OPJ_TRUE;
 }
 
-static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
-       opj_jp2_box_t box;
-
-       box.init_pos = cio_tell(cio);
-       cio_skip(cio, 4);
-       cio_write(cio, JP2_COLR, 4);            /* COLR */
-
-       cio_write(cio, jp2->meth, 1);           /* METH */
-       cio_write(cio, jp2->precedence, 1);     /* PRECEDENCE */
-       cio_write(cio, jp2->approx, 1);         /* APPROX */
-
-       if(jp2->meth == 2)
-        jp2->enumcs = 0;
-
-       cio_write(cio, jp2->enumcs, 4); /* EnumCS */
-
-       box.length = cio_tell(cio) - box.init_pos;
-       cio_seek(cio, box.init_pos);
-       cio_write(cio, box.length, 4);  /* L */
-       cio_seek(cio, box.init_pos + box.length);
-}
-
 /**
  * Writes the Colour Specification box.
  *
@@ -760,8 +737,9 @@ static void jp2_write_colr(opj_jp2_t *jp2, opj_cio_t *cio) {
  * 
  * @return     the data being copied.
 */
-unsigned char *jp2_write_colr_v2(      opj_jp2_v2_t *jp2, 
-                                                                       unsigned int * p_nb_bytes_written )
+OPJ_BYTE * opj_jp2_write_colr(  opj_jp2_v2_t *jp2, 
+                                                           OPJ_UINT32 * p_nb_bytes_written 
+                                )
 {
        /* room for 8 bytes for box 3 for common data and variable upon profile*/
        unsigned int l_colr_size = 11;
@@ -1319,12 +1297,12 @@ opj_bool opj_jp2_write_jp2h(opj_jp2_v2_t *jp2,
                l_nb_pass = 3;
                l_writers[0].handler = opj_jp2_write_ihdr;
                l_writers[1].handler = opj_jp2_write_bpcc;
-               l_writers[2].handler = jp2_write_colr_v2;
+               l_writers[2].handler = opj_jp2_write_colr;
        }
        else {
                l_nb_pass = 2;
                l_writers[0].handler = opj_jp2_write_ihdr;
-               l_writers[1].handler = jp2_write_colr_v2;
+               l_writers[1].handler = opj_jp2_write_colr;
        }
        
        /* write box header */
@@ -1390,27 +1368,6 @@ opj_bool opj_jp2_write_jp2h(opj_jp2_v2_t *jp2,
        return l_result;
 }
 
-static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
-       unsigned int i;
-       opj_jp2_box_t box;
-
-       box.init_pos = cio_tell(cio);
-       cio_skip(cio, 4);
-       cio_write(cio, JP2_FTYP, 4);            /* FTYP */
-
-       cio_write(cio, jp2->brand, 4);          /* BR */
-       cio_write(cio, jp2->minversion, 4);     /* MinV */
-
-       for (i = 0; i < jp2->numcl; i++) {
-               cio_write(cio, jp2->cl[i], 4);  /* CL */
-       }
-
-       box.length = cio_tell(cio) - box.init_pos;
-       cio_seek(cio, box.init_pos);
-       cio_write(cio, box.length, 4);  /* L */
-       cio_seek(cio, box.init_pos + box.length);
-}
-
 /**
  * Writes a FTYP box - File type box
  *
@@ -1420,7 +1377,7 @@ static void jp2_write_ftyp(opj_jp2_t *jp2, opj_cio_t *cio) {
  * 
  * @return     true if writting was successful.
  */
-opj_bool jp2_write_ftyp_v2(    opj_jp2_v2_t *jp2,
+opj_bool opj_jp2_write_ftyp(opj_jp2_v2_t *jp2,
                                                        opj_stream_private_t *cio,
                                                        opj_event_mgr_t * p_manager )
 {
@@ -1472,35 +1429,6 @@ opj_bool jp2_write_ftyp_v2(      opj_jp2_v2_t *jp2,
        return l_result;
 }
 
-static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t *cstr_info) {
-       unsigned int j2k_codestream_offset, j2k_codestream_length;
-       opj_jp2_box_t box;
-
-       opj_j2k_t *j2k = jp2->j2k;
-
-       box.init_pos = cio_tell(cio);
-       cio_skip(cio, 4);
-       cio_write(cio, JP2_JP2C, 4);    /* JP2C */
-
-       /* J2K encoding */
-       j2k_codestream_offset = cio_tell(cio);
-       if(!j2k_encode(j2k, cio, image, cstr_info)) {
-               opj_event_msg(j2k->cinfo, EVT_ERROR, "Failed to encode image\n");
-               return 0;
-       }
-       j2k_codestream_length = cio_tell(cio) - j2k_codestream_offset;
-
-       jp2->j2k_codestream_offset = j2k_codestream_offset;
-       jp2->j2k_codestream_length = j2k_codestream_length;
-
-       box.length = 8 + jp2->j2k_codestream_length;
-       cio_seek(cio, box.init_pos);
-       cio_write(cio, box.length, 4);  /* L */
-       cio_seek(cio, box.init_pos + box.length);
-
-       return box.length;
-}
-
 /**
  * Writes the Jpeg2000 codestream Header box - JP2C Header box.
  *
@@ -1510,7 +1438,7 @@ static int jp2_write_jp2c(opj_jp2_t *jp2, opj_cio_t *cio, opj_image_t *image, op
  *
  * @return true if writting was successful.
 */
-opj_bool jp2_write_jp2c_v2(    opj_jp2_v2_t *jp2,
+opj_bool opj_jp2_write_jp2c(opj_jp2_v2_t *jp2,
                                                        opj_stream_private_t *cio,
                                                        opj_event_mgr_t * p_manager ) 
 {
@@ -1547,20 +1475,6 @@ opj_bool jp2_write_jp2c_v2(      opj_jp2_v2_t *jp2,
        return OPJ_TRUE;
 }
 
-static void jp2_write_jp(opj_cio_t *cio) {
-       opj_jp2_box_t box;
-
-       box.init_pos = cio_tell(cio);
-       cio_skip(cio, 4);
-       cio_write(cio, JP2_JP, 4);              /* JP2 signature */
-       cio_write(cio, 0x0d0a870a, 4);
-
-       box.length = cio_tell(cio) - box.init_pos;
-       cio_seek(cio, box.init_pos);
-       cio_write(cio, box.length, 4);  /* L */
-       cio_seek(cio, box.init_pos + box.length);
-}
-
 /**
  * Writes a jpeg2000 file signature box.
  *
@@ -1570,9 +1484,9 @@ static void jp2_write_jp(opj_cio_t *cio) {
  * 
  * @return true if writting was successful.
  */
-opj_bool jp2_write_jp_v2(      opj_jp2_v2_t *jp2,
-                                                       opj_stream_private_t *cio,
-                                                       opj_event_mgr_t * p_manager ) 
+opj_bool opj_jp2_write_jp(     opj_jp2_v2_t *jp2,
+                                           opj_stream_private_t *cio,
+                                               opj_event_mgr_t * p_manager ) 
 {
        /* 12 bytes will be read */
        unsigned char l_signature_data [12];
@@ -1805,7 +1719,7 @@ opj_bool opj_jp2_end_compress(    opj_jp2_v2_t *jp2,
        assert(p_manager != 00);
 
        /* customization of the end encoding */
-       jp2_setup_end_header_writting(jp2);
+       opj_jp2_setup_end_header_writting(jp2);
 
        if (! j2k_end_compress(jp2->j2k,cio,p_manager)) {
                return OPJ_FALSE;
@@ -1820,12 +1734,12 @@ opj_bool opj_jp2_end_compress(  opj_jp2_v2_t *jp2,
  * Sets up the procedures to do on writing header after the codestream.
  * Developers wanting to extend the library can add their own writing procedures.
  */
-void jp2_setup_end_header_writting (opj_jp2_v2_t *jp2)
+void opj_jp2_setup_end_header_writting (opj_jp2_v2_t *jp2)
 {
        /* preconditions */
        assert(jp2 != 00);
 
-       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)jp2_write_jp2c_v2 );
+       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp2c );
        /* DEVELOPER CORNER, add your custom procedures */
 }
 
@@ -2058,7 +1972,7 @@ opj_bool opj_jp2_start_compress(opj_jp2_v2_t *jp2,
        assert(p_manager != 00);
 
        /* customization of the validation */
-       jp2_setup_encoding_validation (jp2);
+       opj_jp2_setup_encoding_validation (jp2);
 
        /* validation of the parameters codec */
        if (! opj_jp2_exec(jp2,jp2->m_validation_list,stream,p_manager)) {
@@ -2066,7 +1980,7 @@ opj_bool opj_jp2_start_compress(opj_jp2_v2_t *jp2,
        }
 
        /* customization of the encoding */
-       jp2_setup_header_writting(jp2);
+       opj_jp2_setup_header_writting(jp2);
 
        /* write header */
        if (! opj_jp2_exec (jp2,jp2->m_procedure_list,stream,p_manager)) {
@@ -2243,9 +2157,9 @@ static opj_bool opj_jp2_read_ftyp(        opj_jp2_v2_t *jp2,
  *
  * @return true if writting was successful.
 */
-opj_bool jp2_skip_jp2c(        opj_jp2_v2_t *jp2,
-                                               struct opj_stream_private *stream,
-                                               struct opj_event_mgr * p_manager )
+opj_bool opj_jp2_skip_jp2c(    opj_jp2_v2_t *jp2,
+                                               opj_stream_private_t *stream,
+                                               opj_event_mgr_t * p_manager )
 {
        /* preconditions */
        assert(jp2 != 00);
@@ -2453,7 +2367,7 @@ opj_bool opj_jp2_read_header(     opj_stream_private_t *p_stream,
  * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters
  * are valid. Developers wanting to extend the library can add their own validation procedures.
  */
-void jp2_setup_encoding_validation (opj_jp2_v2_t *jp2)
+void opj_jp2_setup_encoding_validation (opj_jp2_v2_t *jp2)
 {
        /* preconditions */
        assert(jp2 != 00);
@@ -2477,15 +2391,15 @@ void opj_jp2_setup_decoding_validation (opj_jp2_v2_t *jp2)
  * Sets up the procedures to do on writting header.
  * Developers wanting to extend the library can add their own writing procedures.
  */
-void jp2_setup_header_writting (opj_jp2_v2_t *jp2)
+void opj_jp2_setup_header_writting (opj_jp2_v2_t *jp2)
 {
        /* preconditions */
        assert(jp2 != 00);
 
-       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)jp2_write_jp_v2 );
-       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)jp2_write_ftyp_v2 );
+       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp );
+       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_ftyp );
        opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_write_jp2h );
-       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)jp2_skip_jp2c );
+       opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp2_skip_jp2c );
 
        /* DEVELOPER CORNER, insert your custom procedures */