Upgrade OpenJPEG to 2.4.0

Upgrade OpenJPEG by copying the files from 2.4.0 and then applying
patches. Patch files that are no longer relevant are deleted.

Some parts of patch 3 are no longer applicable.

The bug from patch 36 was fixed by upstream commit
024b8407392cb0b82b04b58ed256094ed5799e04.

Add a new patch 39 to remove the unused opj_mqc_renorme() function.

Fixed: pdfium:1634
Change-Id: Iaf5e208ea1f32a84aedb09744e0df084621f73dd
Bug: pdfium:1634
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/78050
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
diff --git a/third_party/libopenjpeg20/dwt.h b/third_party/libopenjpeg20/dwt.h
index 4f63e52..215061e 100644
--- a/third_party/libopenjpeg20/dwt.h
+++ b/third_party/libopenjpeg20/dwt.h
@@ -56,9 +56,11 @@
 /**
 Forward 5-3 wavelet transform in 2-D.
 Apply a reversible DWT transform to a component of an image.
+@param p_tcd TCD handle
 @param tilec Tile component information (current tile)
 */
-OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec);
+OPJ_BOOL opj_dwt_encode(opj_tcd_t *p_tcd,
+                        opj_tcd_tilecomp_t * tilec);
 
 /**
 Inverse 5-3 wavelet transform in 2-D.
@@ -72,12 +74,6 @@
                         OPJ_UINT32 numres);
 
 /**
-Get the gain of a subband for the reversible 5-3 DWT.
-@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
-@return Returns 0 if orient = 0, returns 1 if orient = 1 or 2, returns 2 otherwise
-*/
-OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) ;
-/**
 Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT.
 @param level Level of the wavelet function
 @param orient Band of the wavelet function
@@ -87,9 +83,11 @@
 /**
 Forward 9-7 wavelet transform in 2-D.
 Apply an irreversible DWT transform to a component of an image.
+@param p_tcd TCD handle
 @param tilec Tile component information (current tile)
 */
-OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec);
+OPJ_BOOL opj_dwt_encode_real(opj_tcd_t *p_tcd,
+                             opj_tcd_tilecomp_t * tilec);
 /**
 Inverse 9-7 wavelet transform in 2-D.
 Apply an irreversible inverse DWT transform to a component of an image.
@@ -102,12 +100,6 @@
                              OPJ_UINT32 numres);
 
 /**
-Get the gain of a subband for the irreversible 9-7 DWT.
-@param orient Number that identifies the subband (0->LL, 1->HL, 2->LH, 3->HH)
-@return Returns the gain of the 9-7 wavelet transform
-*/
-OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient);
-/**
 Get the norm of a wavelet function of a subband at a specified level for the irreversible 9-7 DWT
 @param level Level of the wavelet function
 @param orient Band of the wavelet function