From a0052fac052c527e67f07a978a9413804427a736 Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Mon, 25 Apr 2016 22:56:58 -0400
Subject: DRTVWR-418: Fix indra/llkdu wrapper for changes in KDU 7.8 API.

KDU 7.8 introduces a number of changes to its API, most notably by moving
public symbols into a variety of kdu_something namespaces. While this is
laudable in a general sense, it does require quite a bit of diagnostic
building and patching to update legacy code.

Since llimagej2ckdu_test.cpp lamentably stubs out pretty much the entire KDU
API, we must also fix those stubs for signature changes even to functions we
don't otherwise reference.

NOTE: This commit still leaves four symbols undefined. Below I have taken the
liberty of juxtaposing the error line with the output from dumpbin /exports
build-vc120/packages/lib/release/kdu.lib. I see no differences.

unresolved symbol (?kdu_convert_ycc_to_rgb_rev16@kdu_core@@3P6AXPAF00H@ZA)   "void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_rev16)(short *,short *,short *,int)"
                   ?kdu_convert_ycc_to_rgb_rev16@kdu_core@@3P6AXPAF00H@ZA    (void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_rev16)(short *,short *,short *,int))
unresolved symbol (?kdu_convert_ycc_to_rgb_irrev16@kdu_core@@3P6AXPAF00H@ZA) "void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_irrev16)(short *,short *,short *,int)"
                   ?kdu_convert_ycc_to_rgb_irrev16@kdu_core@@3P6AXPAF00H@ZA  (void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_irrev16)(short *,short *,short *,int))
unresolved symbol (?kdu_convert_ycc_to_rgb_rev32@kdu_core@@3P6AXPAH00H@ZA)   "void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_rev32)(int *,int *,int *,int)"
                   ?kdu_convert_ycc_to_rgb_rev32@kdu_core@@3P6AXPAH00H@ZA    (void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_rev32)(int *,int *,int *,int))
unresolved symbol (?kdu_convert_ycc_to_rgb_irrev32@kdu_core@@3P6AXPAM00H@ZA) "void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_irrev32)(float *,float *,float *,int)"
                   ?kdu_convert_ycc_to_rgb_irrev32@kdu_core@@3P6AXPAM00H@ZA  (void (__cdecl* kdu_core::kdu_convert_ycc_to_rgb_irrev32)(float *,float *,float *,int))
24>C:\Users\Nat\linden\viewer64\build-vc120\newview\RelWithDebInfo\secondlife-bin.exe : fatal error LNK1120: 4 unresolved externals
---
 indra/llkdu/include_kdu_xxxx.h           | 40 ++++++++++++++++++++++++++++++++
 indra/llkdu/llimagej2ckdu.cpp            | 22 +++++++++++-------
 indra/llkdu/llimagej2ckdu.h              | 17 ++++----------
 indra/llkdu/llkdumem.cpp                 |  3 +++
 indra/llkdu/llkdumem.h                   | 36 +++++++++++++---------------
 indra/llkdu/tests/llimagej2ckdu_test.cpp | 33 +++++++++++++-------------
 6 files changed, 95 insertions(+), 56 deletions(-)
 create mode 100644 indra/llkdu/include_kdu_xxxx.h

(limited to 'indra/llkdu')

diff --git a/indra/llkdu/include_kdu_xxxx.h b/indra/llkdu/include_kdu_xxxx.h
new file mode 100644
index 0000000000..5e86944994
--- /dev/null
+++ b/indra/llkdu/include_kdu_xxxx.h
@@ -0,0 +1,40 @@
+/**
+ * @file   include_kdu_xxxx.h
+ * @author Nat Goodspeed
+ * @date   2016-04-25
+ * @brief  
+ * 
+ * $LicenseInfo:firstyear=2016&license=viewerlgpl$
+ * Copyright (c) 2016, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+// This file specifically omits #include guards of its own: it's sort of an
+// #include macro used to wrap KDU #includes with proper incantations. Usage:
+
+// #define kdu_xxxx "kdu_compressed.h" // or whichever KDU header
+// #include "include_kdu_xxxx.h"
+// // kdu_xxxx #undef'ed by include_kdu_xxxx.h
+
+#if LL_DARWIN
+// don't *really* want to rebuild KDU so turn off specific warnings for this header
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wself-assign-field"
+#pragma clang diagnostic ignored "-Wunused-private-field"
+#include kdu_xxxx
+#pragma clang diagnostic pop
+#elif LL_WINDOWS
+// With warnings-as-errors in effect, strange relationship between
+// jp2_output_box and its subclass jp2_target in kdu_compressed.h
+// causes build failures. Specifically:
+// warning C4263: 'void kdu_supp::jp2_target::open(kdu_supp::jp2_family_tgt *)' : member function does not override any base class virtual member function
+// warning C4264: 'void kdu_supp::jp2_output_box::open(kdu_core::kdu_uint32)' : no override available for virtual member function from base 'kdu_supp::jp2_output_box'; function is hidden
+#pragma warning(push)
+#pragma warning(disable : 4263 4264)
+#include kdu_xxxx
+#pragma warning(pop)
+#else // some other platform
+#include kdu_xxxx
+#endif
+
+#undef kdu_xxxx
diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp
index 6a8959517d..f48e544813 100755
--- a/indra/llkdu/llimagej2ckdu.cpp
+++ b/indra/llkdu/llimagej2ckdu.cpp
@@ -32,12 +32,16 @@
 #include "llmath.h"
 #include "llkdumem.h"
 
-#include "kdu_block_coding.h"
+#define kdu_xxxx "kdu_block_coding.h"
+#include "include_kdu_xxxx.h"
+
+// Avoid ubiquitous necessity of kdu_core:: qualification
+using namespace kdu_core;
 
 class kdc_flow_control {
 	
 public:
-	kdc_flow_control(kdu_image_in_base *img_in, kdu_codestream codestream);
+	kdc_flow_control(kdu_supp::kdu_image_in_base *img_in, kdu_codestream codestream);
 	~kdc_flow_control();
 	bool advance_components();
 	void process_components();
@@ -46,7 +50,7 @@ private:
 	
 	struct kdc_component_flow_control {
 	public:
-		kdu_image_in_base *reader;
+		kdu_supp::kdu_image_in_base *reader;
 		int vert_subsampling;
 		int ratio_counter;  /*  Initialized to 0, decremented by `count_delta';
                                 when < 0, a new line must be processed, after
@@ -108,7 +112,8 @@ const char* fallbackEngineInfoLLImageJ2CImpl()
 class LLKDUDecodeState
 {
 public:
-	LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap);
+	LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap,
+					 kdu_codestream* codestreamp);
 	~LLKDUDecodeState();
 	BOOL processTileDecode(F32 decode_time, BOOL limit_time = TRUE);
 
@@ -495,7 +500,7 @@ BOOL LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco
 					kdu_coords offset = tile_dims.pos - dims.pos;
 					int row_gap = channels*dims.size.x; // inter-row separation
 					kdu_byte *buf = buffer + offset.y*row_gap + offset.x*channels;
-					mDecodeState = new LLKDUDecodeState(tile, buf, row_gap);
+					mDecodeState = new LLKDUDecodeState(tile, buf, row_gap, mCodeStreamp);
 				}
 				// Do the actual processing
 				F32 remaining_time = decode_time - decode_timer.getElapsedTimeF32();
@@ -1143,7 +1148,8 @@ all necessary level shifting, type conversion, rounding and truncation. */
 	}
 }
 
-LLKDUDecodeState::LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap)
+LLKDUDecodeState::LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap,
+								   kdu_codestream* codestreamp)
 {
 	S32 c;
 
@@ -1189,7 +1195,7 @@ LLKDUDecodeState::LLKDUDecodeState(kdu_tile tile, kdu_byte *buf, S32 row_gap)
 			mEngines[c] = kdu_synthesis(res,&mAllocator,use_shorts);
 		}
 	}
-	mAllocator.finalize(); // Actually creates buffering resources
+	mAllocator.finalize(*codestreamp); // Actually creates buffering resources
 	for (c = 0; c < mNumComponents; c++)
 	{
 		mLines[c].create(); // Grabs resources from the allocator.
@@ -1247,7 +1253,7 @@ separation between consecutive rows in the real buffer. */
 
 // kdc_flow_control 
 
-kdc_flow_control::kdc_flow_control (kdu_image_in_base *img_in, kdu_codestream codestream)
+kdc_flow_control::kdc_flow_control (kdu_supp::kdu_image_in_base *img_in, kdu_codestream codestream)
 {
 	int n;
 	
diff --git a/indra/llkdu/llimagej2ckdu.h b/indra/llkdu/llimagej2ckdu.h
index 02281152bf..8d66add38f 100755
--- a/indra/llkdu/llimagej2ckdu.h
+++ b/indra/llkdu/llimagej2ckdu.h
@@ -37,15 +37,8 @@
 #include "kdu_messaging.h"
 #include "kdu_params.h"
 
-// don't *really* want to rebuild KDU so turn off specific warnings for this header
-#if LL_DARWIN
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-private-field"
-#include "kdu_compressed.h"
-#pragma clang diagnostic pop
-#else
-#include "kdu_compressed.h"
-#endif
+#define kdu_xxxx "kdu_compressed.h"
+#include "include_kdu_xxxx.h"
 
 #include "kdu_sample_processing.h"
 
@@ -80,9 +73,9 @@ private:
 
 	// Encode variable
 	LLKDUMemSource *mInputp;
-	kdu_codestream *mCodeStreamp;
-	kdu_coords *mTPosp; // tile position
-	kdu_dims *mTileIndicesp;
+	kdu_core::kdu_codestream *mCodeStreamp;
+	kdu_core::kdu_coords *mTPosp; // tile position
+	kdu_core::kdu_dims *mTileIndicesp;
 	int mBlocksSize;
 	int mPrecinctsSize;
 	int mLevels;
diff --git a/indra/llkdu/llkdumem.cpp b/indra/llkdu/llkdumem.cpp
index 0347475559..96e9da25d8 100755
--- a/indra/llkdu/llkdumem.cpp
+++ b/indra/llkdu/llkdumem.cpp
@@ -28,6 +28,9 @@
 #include "llkdumem.h"
 #include "llerror.h"
 
+using namespace kdu_core;
+using kd_supp_image_local::image_line_buf;
+
 #if defined(LL_WINDOWS)
 # pragma warning(disable: 4702) // unreachable code
 #endif
diff --git a/indra/llkdu/llkdumem.h b/indra/llkdu/llkdumem.h
index fab913d93b..09d81f38de 100755
--- a/indra/llkdu/llkdumem.h
+++ b/indra/llkdu/llkdumem.h
@@ -29,26 +29,22 @@
 
 // Support classes for reading and writing from memory buffers in KDU
 #define KDU_NO_THREADS
-// don't *really* want to rebuild KDU so turn off specific warnings for this header
-#if LL_DARWIN
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wself-assign-field"
-#pragma clang diagnostic ignored "-Wunused-private-field"
-#include "kdu_image.h"
-#pragma clang diagnostic pop
-#else
-#include "kdu_image.h"
-#endif
+
+#define kdu_xxxx "kdu_image.h"
+#include "include_kdu_xxxx.h"
 
 #include "kdu_elementary.h"
 #include "kdu_messaging.h"
 #include "kdu_params.h"
-#include "kdu_compressed.h"
+
+#define kdu_xxxx "kdu_compressed.h"
+#include "include_kdu_xxxx.h"
+
 #include "kdu_sample_processing.h"
 #include "image_local.h"
 #include "stdtypes.h"
 
-class LLKDUMemSource: public kdu_compressed_source
+class LLKDUMemSource: public kdu_core::kdu_compressed_source
 {
 public:
 	LLKDUMemSource(U8 *input_buffer, U32 size)
@@ -62,7 +58,7 @@ public:
 	{
 	}
 
-	int read(kdu_byte *buf, int num_bytes)
+	int read(kdu_core::kdu_byte *buf, int num_bytes)
 	{
 		U32 num_out;
 		num_out = num_bytes;
@@ -87,7 +83,7 @@ private:
 	U32 mCurPos;
 };
 
-class LLKDUMemTarget: public kdu_compressed_target
+class LLKDUMemTarget: public kdu_core::kdu_compressed_target
 {
 public:
 	LLKDUMemTarget(U8 *output_buffer, U32 &output_size, const U32 buffer_size)
@@ -102,7 +98,7 @@ public:
 	{
 	}
 
-	bool write(const kdu_byte *buf, int num_bytes)
+	bool write(const kdu_core::kdu_byte *buf, int num_bytes)
 	{
 		U32 num_out;
 		num_out = num_bytes;
@@ -126,7 +122,7 @@ private:
 	U32 *mOutputSize;
 };
 
-class LLKDUMemIn : public kdu_image_in_base
+class LLKDUMemIn : public kdu_supp::kdu_image_in_base
 {
 public:
 	LLKDUMemIn(const U8 *data,
@@ -134,10 +130,10 @@ public:
 				const U16 rows,
 				const U16 cols,
 				U8 in_num_components,
-				siz_params *siz);
+				kdu_core::siz_params *siz);
 	~LLKDUMemIn();
 
-	bool get(int comp_idx, kdu_line_buf &line, int x_tnum);
+	bool get(int comp_idx, kdu_core::kdu_line_buf &line, int x_tnum);
 
 private:
 	const U8 *mData;
@@ -146,8 +142,8 @@ private:
 	int rows, cols;
 	int alignment_bytes; // Number of 0's at end of each line.
 	int precision[3];
-	image_line_buf *incomplete_lines; // Each "sample" represents a full pixel
-	image_line_buf *free_lines;
+	kd_supp_image_local::image_line_buf *incomplete_lines; // Each "sample" represents a full pixel
+	kd_supp_image_local::image_line_buf *free_lines;
 	int num_unread_rows;
 
 	U32 mCurPos;
diff --git a/indra/llkdu/tests/llimagej2ckdu_test.cpp b/indra/llkdu/tests/llimagej2ckdu_test.cpp
index 0605fad068..056c55933a 100755
--- a/indra/llkdu/tests/llimagej2ckdu_test.cpp
+++ b/indra/llkdu/tests/llimagej2ckdu_test.cpp
@@ -29,15 +29,7 @@
 // Class to test 
 #include "llimagej2ckdu.h"
 
-#if LL_DARWIN
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-private-field"
 #include "llkdumem.h"
-#pragma clang diagnostic pop
-#else
-#include "llkdumem.h"
-#endif
-
 #include "kdu_block_coding.h"
 // Tut header
 #include "lltut.h"
@@ -113,17 +105,19 @@ void LLImageJ2C::setLastError(const std::string&, const std::string&) { }
 BOOL LLImageJ2C::updateData() { return FALSE; }
 void LLImageJ2C::updateRawDiscardLevel() { }
 
-LLKDUMemIn::LLKDUMemIn(const U8*, const U32, const U16, const U16, const U8, siz_params*) { }
+LLKDUMemIn::LLKDUMemIn(const U8*, const U32, const U16, const U16, const U8, kdu_core::siz_params*) { }
 LLKDUMemIn::~LLKDUMemIn() { }
-bool LLKDUMemIn::get(int, kdu_line_buf&, int) { return false; }
+bool LLKDUMemIn::get(int, kdu_core::kdu_line_buf&, int) { return false; }
 
 // Stub Kakadu Library calls
+// they're all namespaced now
+namespace kdu_core {
 kdu_tile_comp kdu_tile::access_component(int ) { kdu_tile_comp a; return a; }
 kdu_block_encoder::kdu_block_encoder() { }
 kdu_block_decoder::kdu_block_decoder() { }
 void kdu_block::set_max_passes(int , bool ) { }
 void kdu_block::set_max_bytes(int , bool ) { }
-void kdu_tile::close(kdu_thread_env* ) { }
+void kdu_tile::close(kdu_thread_env *, bool) {}
 int kdu_tile::get_num_components() { return 0; }
 bool kdu_tile::get_ycc() { return false; }
 void kdu_tile::set_components_of_interest(int , const int* ) { }
@@ -156,14 +150,14 @@ void kdu_codestream::set_fussy() { }
 void kdu_codestream::get_dims(int, kdu_dims&, bool ) { }
 int kdu_codestream::get_min_dwt_levels() { return 5; }
 int kdu_codestream::get_max_tile_layers() { return 1; }
-void kdu_codestream::change_appearance(bool, bool, bool) { }
+void kdu_codestream::change_appearance(bool, bool, bool, kdu_thread_env *) {}
 void kdu_codestream::get_tile_dims(kdu_coords, int, kdu_dims&, bool ) { }
 void kdu_codestream::destroy() { }
 void kdu_codestream::collect_timing_stats(int ) { }
 void kdu_codestream::set_max_bytes(kdu_long, bool, bool ) { }
 void kdu_codestream::get_valid_tiles(kdu_dims& ) { }
 void kdu_codestream::create(kdu_compressed_source*, kdu_thread_env*) { }
-void kdu_codestream::apply_input_restrictions( int, int, int, int, kdu_dims*, kdu_component_access_mode ) { }
+void kdu_codestream::apply_input_restrictions(int, int, int, int, kdu_dims const *, kdu_component_access_mode, kdu_thread_env *, kdu_quality_limiter const *) {}
 void kdu_codestream::get_subsampling(int , kdu_coords&, bool ) { }
 void kdu_codestream::flush(kdu_long *, int, kdu_uint16 *, bool, bool, double, kdu_thread_env*, int) { }
 void kdu_codestream::set_resilient(bool ) { }
@@ -178,13 +172,15 @@ siz_params* kdu_codestream::access_siz() { return NULL; }
 kdu_tile kdu_codestream::open_tile(kdu_coords , kdu_thread_env* ) { kdu_tile a; return a; }
 kdu_codestream_comment kdu_codestream::add_comment() { kdu_codestream_comment a; return a; }
 void kdu_subband::close_block(kdu_block*, kdu_thread_env*) { }
-void kdu_subband::get_valid_blocks(kdu_dims &indices) { }
-kdu_block* kdu_subband::open_block(kdu_coords, int*, kdu_thread_env*) { return NULL; }
+void kdu_subband::get_valid_blocks(kdu_dims &indices) const { }
+kdu_block * kdu_subband::open_block(kdu_coords, int *, kdu_thread_env *, int, bool) { return NULL; }
 bool kdu_codestream_comment::put_text(const char*) { return false; }
 void kdu_customize_warnings(kdu_message*) { }
 void kdu_customize_errors(kdu_message*) { }
-kdu_long kdu_multi_analysis::create(kdu_codestream, kdu_tile, kdu_thread_env*, kdu_thread_queue*, int, kdu_roi_image*, int) { kdu_long a = 0; return a; }
+kdu_long kdu_multi_analysis::create(kdu_codestream, kdu_tile, kdu_thread_env *,kdu_thread_queue *, int, kdu_roi_image *, int, kdu_sample_allocator *, kdu_push_pull_params const *) { return kdu_long(0); }
+void kdu_multi_analysis::destroy(kdu_thread_env *) {}
 siz_params::siz_params() : kdu_params(NULL, false, false, false, false, false) { }
+siz_params::~siz_params() {}
 void siz_params::finalize(bool ) { }
 void siz_params::copy_with_xforms(kdu_params*, int, int, bool, bool, bool) { }
 int siz_params::write_marker_segment(kdu_output*, kdu_params*, int) { return 0; }
@@ -193,10 +189,15 @@ bool siz_params::read_marker_segment(kdu_uint16, int, kdu_byte a[], int) { retur
 
 kdu_decoder::kdu_decoder(kdu_subband , kdu_sample_allocator*, bool , float, int, kdu_thread_env*, kdu_thread_queue*, int) { }
 void kdu_codestream::create(siz_params*, kdu_compressed_target*, kdu_dims*, int, kdu_long, kdu_thread_env* ) { }
+kdu_sample_allocator::~kdu_sample_allocator() {}
+void kdu_sample_allocator::do_finalize(kdu_codestream) {}
 void (*kdu_convert_ycc_to_rgb_rev16)(kdu_int16*,kdu_int16*,kdu_int16*,int);
 void (*kdu_convert_ycc_to_rgb_irrev16)(kdu_int16*,kdu_int16*,kdu_int16*,int);
 void (*kdu_convert_ycc_to_rgb_rev32)(kdu_int32*,kdu_int32*,kdu_int32*,int);
 void (*kdu_convert_ycc_to_rgb_irrev32)(float*,float*,float*,int);
+bool kdu_core_sample_alignment_checker(int, int, int, int, bool, bool) { return false; }
+void kdu_pull_ifc::destroy() {}
+} // namespace kdu_core
 
 // -------------------------------------------------------------------------------------------
 // TUT
-- 
cgit v1.2.3


From 811a0b5726ed965f9f21ace2d3ec97bb95a91311 Mon Sep 17 00:00:00 2001
From: callum_linden <none@none>
Date: Tue, 26 Apr 2016 12:14:29 -0700
Subject: DRTVWR-418: add preprocessor define to fix linker error introduced in
 v7.8

---
 indra/llkdu/llimagej2ckdu.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'indra/llkdu')

diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp
index f48e544813..4f93d85529 100755
--- a/indra/llkdu/llimagej2ckdu.cpp
+++ b/indra/llkdu/llimagej2ckdu.cpp
@@ -25,6 +25,12 @@
  */
 
 #include "linden_common.h"
+
+// based on this KDU support group posting:
+// https://groups.yahoo.com/neo/groups/kakadu_jpeg2000/conversations/messages/6691
+// Defining this values seems to fix the linker error that appeared with the 7.8 release
+#define CORESYS_IMPORTS
+
 #include "llimagej2ckdu.h"
 
 #include "lltimer.h"
-- 
cgit v1.2.3


From ec0e3e9f08cc13025b216f1c4576f5c88622043c Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Tue, 26 Apr 2016 22:23:18 -0400
Subject: DRTVWR-418: Match KDU_X86_INTRINSICS macro set for KDU package build.

---
 indra/llkdu/CMakeLists.txt | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'indra/llkdu')

diff --git a/indra/llkdu/CMakeLists.txt b/indra/llkdu/CMakeLists.txt
index b8f8b420c3..cb0e204e91 100755
--- a/indra/llkdu/CMakeLists.txt
+++ b/indra/llkdu/CMakeLists.txt
@@ -40,6 +40,14 @@ set_source_files_properties(${llkdu_HEADER_FILES}
 
 list(APPEND llkdu_SOURCE_FILES ${llkdu_HEADER_FILES})
 
+# Our KDU package is built with KDU_X86_INTRINSICS in its .vcxproj file.
+# Unless that macro is also set for every consumer build, KDU freaks out,
+# spamming the viewer log with alignment FUD.
+set_source_files_properties(${llkdu_SOURCE_FILES}
+                            PROPERTIES
+                            COMPILE_DEFINITIONS
+                            "KDU_X86_INTRINSICS")
+
 if (USE_KDU)
   add_library (llkdu ${llkdu_SOURCE_FILES})
 
-- 
cgit v1.2.3


From 0413e40d82cc53c1e8180023db36108557b6f21c Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 3 Nov 2016 20:48:41 -0400
Subject: DRTVWR-418: Update KDU and llimagej2ckdu* with certain clang fixes.

---
 indra/llkdu/llimagej2ckdu.cpp            | 31 +++++++++++++++++--------------
 indra/llkdu/llimagej2ckdu.h              |  6 ++++--
 indra/llkdu/tests/llimagej2ckdu_test.cpp |  6 ++++++
 3 files changed, 27 insertions(+), 16 deletions(-)

(limited to 'indra/llkdu')

diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp
index b85e39b452..0540e55e07 100644
--- a/indra/llkdu/llimagej2ckdu.cpp
+++ b/indra/llkdu/llimagej2ckdu.cpp
@@ -37,7 +37,6 @@
 #include "llpointer.h"
 #include "llmath.h"
 #include "llkdumem.h"
-#include "stringize.h"
 
 #define kdu_xxxx "kdu_block_coding.h"
 #include "include_kdu_xxxx.h"
@@ -50,6 +49,18 @@ using namespace kdu_core;
 #include <sstream>
 #include <iomanip>
 
+// stream kdu_dims to std::ostream
+// Turns out this must NOT be in the anonymous namespace!
+// It must also precede #include "stringize.h".
+inline
+std::ostream& operator<<(std::ostream& out, const kdu_dims& dims)
+{
+	return out << "(" << dims.pos.x << "," << dims.pos.y << "),"
+				  "[" << dims.size.x << "x" << dims.size.y << "]";
+}
+
+#include "stringize.h"
+
 namespace {
 // Failure to load an image shouldn't crash the whole viewer.
 struct KDUError: public LLContinueError
@@ -92,15 +103,6 @@ std::string report_kdu_exception(kdu_exception mb)
 }
 } // anonymous namespace
 
-// stream kdu_dims to std::ostream
-// Turns out this must NOT be in the anonymous namespace!
-inline
-std::ostream& operator<<(std::ostream& out, const kdu_dims& dims)
-{
-	return out << "(" << dims.pos.x << "," << dims.pos.y << "),"
-				  "[" << dims.size.x << "x" << dims.size.y << "]";
-}
-
 class kdc_flow_control {
 	
 public:
@@ -356,9 +358,9 @@ void LLImageJ2CKDU::setupCodeStream(LLImageJ2C &base, bool keep_codestream, ECod
 			// This method is only called from methods that catch KDUError.
 			// We want to fail the image load, not crash the viewer.
 			LLTHROW(KDUError(STRINGIZE("Component " << idx << " dimensions "
-									 << other_dims
-									 << " do not match component 0 dimensions "
-									 << dims << "!")));
+									   << stringize(other_dims)
+									   << " do not match component 0 dimensions "
+									   << stringize(dims) << "!")));
 		}
 	}
 
@@ -570,7 +572,8 @@ bool LLImageJ2CKDU::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 deco
 					kdu_coords offset = tile_dims.pos - dims.pos;
 					int row_gap = channels*dims.size.x; // inter-row separation
 					kdu_byte *buf = buffer + offset.y*row_gap + offset.x*channels;
-					mDecodeState.reset(new LLKDUDecodeState(tile, buf, row_gap));
+					mDecodeState.reset(new LLKDUDecodeState(tile, buf, row_gap,
+															mCodeStreamp.get()));
 				}
 				// Do the actual processing
 				F32 remaining_time = decode_time - decode_timer.getElapsedTimeF32();
diff --git a/indra/llkdu/llimagej2ckdu.h b/indra/llkdu/llimagej2ckdu.h
index fd9a396722..b57e4cc40e 100644
--- a/indra/llkdu/llimagej2ckdu.h
+++ b/indra/llkdu/llimagej2ckdu.h
@@ -104,10 +104,12 @@ private:
 			}
 		}
 
-		kdu_codestream* operator->() { return &mCodeStream; }
+		// for those few times when you need a raw kdu_codestream*
+		kdu_core::kdu_codestream* get() { return &mCodeStream; }
+		kdu_core::kdu_codestream* operator->() { return &mCodeStream; }
 
 	private:
-		kdu_codestream mCodeStream;
+		kdu_core::kdu_codestream mCodeStream;
 	};
 
 	// Encode variable
diff --git a/indra/llkdu/tests/llimagej2ckdu_test.cpp b/indra/llkdu/tests/llimagej2ckdu_test.cpp
index 1407da3aa2..ae6138d4c6 100644
--- a/indra/llkdu/tests/llimagej2ckdu_test.cpp
+++ b/indra/llkdu/tests/llimagej2ckdu_test.cpp
@@ -29,7 +29,13 @@
 // Class to test 
 #include "llimagej2ckdu.h"
 
+#if LL_DARWIN
+// For this source, it's true that private fields in llkdumem.h are unused.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-private-field"
 #include "llkdumem.h"
+#pragma clang diagnostic pop
+#endif
 #include "kdu_block_coding.h"
 // Tut header
 #include "lltut.h"
-- 
cgit v1.2.3


From b1185eca82a1c0fff1a885fd5dfea09e5b9c0b3a Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 17 Nov 2016 08:59:01 -0500
Subject: DRTVWR-418: Fix Windows line endings in include_kdu_xxxx.h

---
 indra/llkdu/include_kdu_xxxx.h | 80 +++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 40 deletions(-)

(limited to 'indra/llkdu')

diff --git a/indra/llkdu/include_kdu_xxxx.h b/indra/llkdu/include_kdu_xxxx.h
index 5e86944994..a1dbced60b 100644
--- a/indra/llkdu/include_kdu_xxxx.h
+++ b/indra/llkdu/include_kdu_xxxx.h
@@ -1,40 +1,40 @@
-/**
- * @file   include_kdu_xxxx.h
- * @author Nat Goodspeed
- * @date   2016-04-25
- * @brief  
- * 
- * $LicenseInfo:firstyear=2016&license=viewerlgpl$
- * Copyright (c) 2016, Linden Research, Inc.
- * $/LicenseInfo$
- */
-
-// This file specifically omits #include guards of its own: it's sort of an
-// #include macro used to wrap KDU #includes with proper incantations. Usage:
-
-// #define kdu_xxxx "kdu_compressed.h" // or whichever KDU header
-// #include "include_kdu_xxxx.h"
-// // kdu_xxxx #undef'ed by include_kdu_xxxx.h
-
-#if LL_DARWIN
-// don't *really* want to rebuild KDU so turn off specific warnings for this header
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wself-assign-field"
-#pragma clang diagnostic ignored "-Wunused-private-field"
-#include kdu_xxxx
-#pragma clang diagnostic pop
-#elif LL_WINDOWS
-// With warnings-as-errors in effect, strange relationship between
-// jp2_output_box and its subclass jp2_target in kdu_compressed.h
-// causes build failures. Specifically:
-// warning C4263: 'void kdu_supp::jp2_target::open(kdu_supp::jp2_family_tgt *)' : member function does not override any base class virtual member function
-// warning C4264: 'void kdu_supp::jp2_output_box::open(kdu_core::kdu_uint32)' : no override available for virtual member function from base 'kdu_supp::jp2_output_box'; function is hidden
-#pragma warning(push)
-#pragma warning(disable : 4263 4264)
-#include kdu_xxxx
-#pragma warning(pop)
-#else // some other platform
-#include kdu_xxxx
-#endif
-
-#undef kdu_xxxx
+/**
+ * @file   include_kdu_xxxx.h
+ * @author Nat Goodspeed
+ * @date   2016-04-25
+ * @brief  
+ * 
+ * $LicenseInfo:firstyear=2016&license=viewerlgpl$
+ * Copyright (c) 2016, Linden Research, Inc.
+ * $/LicenseInfo$
+ */
+
+// This file specifically omits #include guards of its own: it's sort of an
+// #include macro used to wrap KDU #includes with proper incantations. Usage:
+
+// #define kdu_xxxx "kdu_compressed.h" // or whichever KDU header
+// #include "include_kdu_xxxx.h"
+// // kdu_xxxx #undef'ed by include_kdu_xxxx.h
+
+#if LL_DARWIN
+// don't *really* want to rebuild KDU so turn off specific warnings for this header
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wself-assign-field"
+#pragma clang diagnostic ignored "-Wunused-private-field"
+#include kdu_xxxx
+#pragma clang diagnostic pop
+#elif LL_WINDOWS
+// With warnings-as-errors in effect, strange relationship between
+// jp2_output_box and its subclass jp2_target in kdu_compressed.h
+// causes build failures. Specifically:
+// warning C4263: 'void kdu_supp::jp2_target::open(kdu_supp::jp2_family_tgt *)' : member function does not override any base class virtual member function
+// warning C4264: 'void kdu_supp::jp2_output_box::open(kdu_core::kdu_uint32)' : no override available for virtual member function from base 'kdu_supp::jp2_output_box'; function is hidden
+#pragma warning(push)
+#pragma warning(disable : 4263 4264)
+#include kdu_xxxx
+#pragma warning(pop)
+#else // some other platform
+#include kdu_xxxx
+#endif
+
+#undef kdu_xxxx
-- 
cgit v1.2.3


From b9cc216b9cbded6f4adbc67f58d0fbc464ee0c9f Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Wed, 23 Nov 2016 12:07:31 -0500
Subject: DRTVWR-418: Have to #include "llkdumem.h" even when not LL_DARWIN.

---
 indra/llkdu/tests/llimagej2ckdu_test.cpp | 2 ++
 1 file changed, 2 insertions(+)

(limited to 'indra/llkdu')

diff --git a/indra/llkdu/tests/llimagej2ckdu_test.cpp b/indra/llkdu/tests/llimagej2ckdu_test.cpp
index ae6138d4c6..e386a9f71b 100644
--- a/indra/llkdu/tests/llimagej2ckdu_test.cpp
+++ b/indra/llkdu/tests/llimagej2ckdu_test.cpp
@@ -35,6 +35,8 @@
 #pragma clang diagnostic ignored "-Wunused-private-field"
 #include "llkdumem.h"
 #pragma clang diagnostic pop
+#else
+#include "llkdumem.h"
 #endif
 #include "kdu_block_coding.h"
 // Tut header
-- 
cgit v1.2.3


From 7b2cf53f782ac9ffa2766d006c870f10c320c9a0 Mon Sep 17 00:00:00 2001
From: Callum Prentice <callum@gmail.com>
Date: Wed, 30 Nov 2016 12:21:05 -0800
Subject: Pull in new version of KDU third party package that is build
 (correctly) as a static library vs. a stub library/DLL

---
 indra/llkdu/llimagej2ckdu.cpp | 5 -----
 1 file changed, 5 deletions(-)

(limited to 'indra/llkdu')

diff --git a/indra/llkdu/llimagej2ckdu.cpp b/indra/llkdu/llimagej2ckdu.cpp
index 0540e55e07..cb29da8f5f 100644
--- a/indra/llkdu/llimagej2ckdu.cpp
+++ b/indra/llkdu/llimagej2ckdu.cpp
@@ -26,11 +26,6 @@
 
 #include "linden_common.h"
 
-// based on this KDU support group posting:
-// https://groups.yahoo.com/neo/groups/kakadu_jpeg2000/conversations/messages/6691
-// Defining this values seems to fix the linker error that appeared with the 7.8 release
-#define CORESYS_IMPORTS
-
 #include "llimagej2ckdu.h"
 
 #include "lltimer.h"
-- 
cgit v1.2.3