Remove OpenJPEG2 support for now - LL is updating to OpenJPEG2 in the texture cache overhaul viewer

Fri, 13 Apr 2018 23:04:06 +0200

author
Ansariel
date
Fri, 13 Apr 2018 23:04:06 +0200
changeset 55098
8c37968a0fb4
parent 55097
5b383f623170
child 55099
b96093ca12fb

Remove OpenJPEG2 support for now - LL is updating to OpenJPEG2 in the texture cache overhaul viewer

autobuild.xml file | annotate | diff | revisions
indra/cmake/Copy3rdPartyLibs.cmake file | annotate | diff | revisions
indra/cmake/OpenJPEG.cmake file | annotate | diff | revisions
indra/cmake/OpenJPEG2.cmake file | annotate | diff | revisions
indra/llimagej2coj/CMakeLists.txt file | annotate | diff | revisions
indra/llimagej2coj/llimagej2coj2.cpp file | annotate | diff | revisions
indra/newview/viewer_manifest.py file | annotate | diff | revisions
     1.1 --- a/autobuild.xml	Thu Apr 12 21:09:38 2018 +0200
     1.2 +++ b/autobuild.xml	Fri Apr 13 23:04:06 2018 +0200
     1.3 @@ -137,72 +137,6 @@
     1.4            </map>
     1.5          </map>
     1.6        </map>
     1.7 -      <key>openjpeg2</key>
     1.8 -      <map>
     1.9 -        <key>copyright</key>
    1.10 -        <string>Copyright (c) 2002-2016, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium, Copyright (c) 2002-2007, Professor Benoit Macq, Copyright (c) 2001-2003, David Janssens, Copyright (c) 2002-2003, Yannick Verschueren, Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe, Copyright (c) 2005, Herve Drolon, FreeImage Team</string>
    1.11 -        <key>description</key>
    1.12 -        <string>The OpenJPEG library is an open-source JPEG 2000 codec written in C language.</string>
    1.13 -        <key>license</key>
    1.14 -        <string>BSD</string>
    1.15 -        <key>license_file</key>
    1.16 -        <string>LICENSES/openjpeg.txt</string>
    1.17 -        <key>name</key>
    1.18 -        <string>openjpeg2</string>
    1.19 -        <key>platforms</key>
    1.20 -        <map>
    1.21 -          <key>linux</key>
    1.22 -          <map>
    1.23 -            <key>archive</key>
    1.24 -            <map>
    1.25 -              <key>hash</key>
    1.26 -              <string>3925c90f0d3f5523acdad063620d01d6</string>
    1.27 -              <key>url</key>
    1.28 -              <string>http://downloads.phoenixviewer.com/openjpeg2-2.1.201601141918-r32-linux-201601141918-r32.tar.bz2</string>
    1.29 -            </map>
    1.30 -            <key>name</key>
    1.31 -            <string>linux</string>
    1.32 -          </map>
    1.33 -          <key>linux64</key>
    1.34 -          <map>
    1.35 -            <key>archive</key>
    1.36 -            <map>
    1.37 -              <key>hash</key>
    1.38 -              <string>8f4188c9a281425e26d89af0676bb6b7</string>
    1.39 -              <key>url</key>
    1.40 -              <string>http://downloads.phoenixviewer.com/openjpeg2-2.1.201601141020-r32-linux-x64-201601141020-r32.tar.bz2</string>
    1.41 -            </map>
    1.42 -            <key>name</key>
    1.43 -            <string>linux64</string>
    1.44 -          </map>
    1.45 -          <key>windows</key>
    1.46 -          <map>
    1.47 -            <key>archive</key>
    1.48 -            <map>
    1.49 -              <key>hash</key>
    1.50 -              <string>bc784edaab1b786766b2f381a86b8710</string>
    1.51 -              <key>url</key>
    1.52 -              <string>http://downloads.phoenixviewer.com/openjpeg2-2.1.201601141919-r32-windows-201601141919-r32.tar.bz2</string>
    1.53 -            </map>
    1.54 -            <key>name</key>
    1.55 -            <string>windows</string>
    1.56 -          </map>
    1.57 -          <key>windows64</key>
    1.58 -          <map>
    1.59 -            <key>archive</key>
    1.60 -            <map>
    1.61 -              <key>hash</key>
    1.62 -              <string>0465f2221c22a7349e4ae49f751ae3d3</string>
    1.63 -              <key>url</key>
    1.64 -              <string>http://downloads.phoenixviewer.com/openjpeg2-2.1.201601141917-r32-windows-x64-201601141917-r32.tar.bz2</string>
    1.65 -            </map>
    1.66 -            <key>name</key>
    1.67 -            <string>windows64</string>
    1.68 -          </map>
    1.69 -        </map>
    1.70 -        <key>version</key>
    1.71 -        <string>2.1</string>
    1.72 -      </map>
    1.73        <key>SDL</key>
    1.74        <map>
    1.75          <key>copyright</key>
     2.1 --- a/indra/cmake/Copy3rdPartyLibs.cmake	Thu Apr 12 21:09:38 2018 +0200
     2.2 +++ b/indra/cmake/Copy3rdPartyLibs.cmake	Fri Apr 13 23:04:06 2018 +0200
     2.3 @@ -38,7 +38,7 @@
     2.4  
     2.5      set(release_src_dir "${ARCH_PREBUILT_DIRS_RELEASE}")
     2.6      set(release_files
     2.7 -        #openjpeg.dll
     2.8 +        openjpeg.dll
     2.9          libapr-1.dll
    2.10          libaprutil-1.dll
    2.11          libapriconv-1.dll
    2.12 @@ -49,12 +49,6 @@
    2.13          libhunspell.dll
    2.14          )
    2.15  
    2.16 -    if( NOT ND_USE_OPENJPEG2 )
    2.17 -      set(release_files ${release_files} openjpeg.dll )
    2.18 -    else()
    2.19 -      set(release_files ${release_files} openjp2.dll )
    2.20 -    endif( NOT ND_USE_OPENJPEG2 ) 
    2.21 -    
    2.22      set(release_files ${release_files} growl++.dll growl.dll )
    2.23      if (FMODSTUDIO)
    2.24        if(ADDRESS_SIZE EQUAL 32)
    2.25 @@ -250,7 +244,7 @@
    2.26          libgobject-2.0.so
    2.27          libhunspell-1.3.so.0.0.0
    2.28          libopenal.so
    2.29 -        #libopenjpeg.so
    2.30 +        libopenjpeg.so
    2.31          libuuid.so.16
    2.32          libuuid.so.16.0.22
    2.33          libfontconfig.so.1.8.0
     3.1 --- a/indra/cmake/OpenJPEG.cmake	Thu Apr 12 21:09:38 2018 +0200
     3.2 +++ b/indra/cmake/OpenJPEG.cmake	Fri Apr 13 23:04:06 2018 +0200
     3.3 @@ -1,12 +1,6 @@
     3.4  # -*- cmake -*-
     3.5  include(Prebuilt)
     3.6  
     3.7 -if( ND_USE_OPENJPEG2 )
     3.8 -  message( "Using OpenJPEG2" )
     3.9 -  include( OpenJPEG2 )
    3.10 -  return()
    3.11 -endif( ND_USE_OPENJPEG2 )
    3.12 -
    3.13  set(OPENJPEG_FIND_QUIETLY ON)
    3.14  set(OPENJPEG_FIND_REQUIRED ON)
    3.15  
     4.1 --- a/indra/cmake/OpenJPEG2.cmake	Thu Apr 12 21:09:38 2018 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,21 +0,0 @@
     4.4 -# -*- cmake -*-
     4.5 -include(Prebuilt)
     4.6 -
     4.7 -set(OPENJPEG_FIND_QUIETLY ON)
     4.8 -set(OPENJPEG_FIND_REQUIRED ON)
     4.9 -
    4.10 -if (USESYSTEMLIBS)
    4.11 -  include(FindOpenJPEG)
    4.12 -else (USESYSTEMLIBS)
    4.13 -  use_prebuilt_binary(openjpeg2)
    4.14 -  
    4.15 -  if(WINDOWS)
    4.16 -    set(OPENJPEG_LIBRARIES 
    4.17 -        debug openjp2
    4.18 -        optimized openjp2)
    4.19 -  else(WINDOWS)
    4.20 -    set(OPENJPEG_LIBRARIES openjp2)
    4.21 -  endif(WINDOWS)
    4.22 -  
    4.23 -  # set(OPENJPEG_INCLUDE_DIR ${LIBS_PREBUILT_DIR}/include/openjpeg)
    4.24 -endif (USESYSTEMLIBS)
     5.1 --- a/indra/llimagej2coj/CMakeLists.txt	Thu Apr 12 21:09:38 2018 +0200
     5.2 +++ b/indra/llimagej2coj/CMakeLists.txt	Fri Apr 13 23:04:06 2018 +0200
     5.3 @@ -13,18 +13,10 @@
     5.4      ${OPENJPEG_INCLUDE_DIR}
     5.5      )
     5.6  
     5.7 -if( NOT ND_USE_OPENJPEG2 )
     5.8 -
     5.9  set(llimagej2coj_SOURCE_FILES
    5.10      llimagej2coj.cpp
    5.11      )
    5.12  
    5.13 -else()
    5.14 -set(llimagej2coj_SOURCE_FILES
    5.15 -    llimagej2coj2.cpp
    5.16 -    )
    5.17 -endif()
    5.18 -
    5.19  set(llimagej2coj_HEADER_FILES
    5.20      CMakeLists.txt
    5.21  
     6.1 --- a/indra/llimagej2coj/llimagej2coj2.cpp	Thu Apr 12 21:09:38 2018 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,655 +0,0 @@
     6.4 -/** 
     6.5 - * @file llimagej2coj.cpp
     6.6 - * @brief This is an implementation of JPEG2000 encode/decode using OpenJPEG.
     6.7 - *
     6.8 - * $LicenseInfo:firstyear=2006&license=viewerlgpl$
     6.9 - * Second Life Viewer Source Code
    6.10 - * Copyright (C) 2010, Linden Research, Inc.
    6.11 - * 
    6.12 - * This library is free software; you can redistribute it and/or
    6.13 - * modify it under the terms of the GNU Lesser General Public
    6.14 - * License as published by the Free Software Foundation;
    6.15 - * version 2.1 of the License only.
    6.16 - * 
    6.17 - * This library is distributed in the hope that it will be useful,
    6.18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.20 - * Lesser General Public License for more details.
    6.21 - * 
    6.22 - * You should have received a copy of the GNU Lesser General Public
    6.23 - * License along with this library; if not, write to the Free Software
    6.24 - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    6.25 - * 
    6.26 - * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
    6.27 - * $/LicenseInfo$
    6.28 - */
    6.29 -
    6.30 -#include "linden_common.h"
    6.31 -#include "llimagej2coj.h"
    6.32 -
    6.33 -// this is defined so that we get static linking.
    6.34 -#include "openjpeg-2.1-fs/openjpeg.h"
    6.35 -
    6.36 -#include "lltimer.h"
    6.37 -//#include "llmemory.h"
    6.38 -
    6.39 -#define OPENJPEG_VERSION "2.1" // This actually needs to be in openjpeg.h
    6.40 -
    6.41 -struct ndUserdata
    6.42 -{
    6.43 -	ndUserdata( bool aInput )
    6.44 -	{
    6.45 -		mInputStream = aInput;
    6.46 -
    6.47 -		mOffset = mLength = 0;
    6.48 -		mInput = 0;
    6.49 -	}
    6.50 -
    6.51 -	bool mInputStream;
    6.52 -
    6.53 -	size_t mOffset;
    6.54 -	size_t mLength;
    6.55 -	std::vector< U8 > mOutput;
    6.56 -	LLImageJ2C *mInput;
    6.57 -};
    6.58 -
    6.59 -void freeUserdata( void *aData )
    6.60 -{
    6.61 -	if( aData )
    6.62 -		delete (ndUserdata*)aData;
    6.63 -}
    6.64 -
    6.65 -OPJ_SIZE_T nd_opj_stream_read_fn (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
    6.66 -{
    6.67 -	ndUserdata *pUserdata = reinterpret_cast< ndUserdata* >( p_user_data );
    6.68 -	llassert_always( pUserdata->mInputStream );
    6.69 -
    6.70 -	U8* pData = pUserdata->mInput->getData();
    6.71 -	size_t nImgsize =  pUserdata->mInput->getDataSize();
    6.72 -	size_t nByteLeft = (nImgsize - pUserdata->mOffset);
    6.73 -
    6.74 -	size_t nRead = p_nb_bytes;
    6.75 -
    6.76 -	if( nRead > nByteLeft )
    6.77 -		nRead = nByteLeft;
    6.78 -
    6.79 -	if( !pData || !p_buffer || !nRead || !nByteLeft )
    6.80 -		return (OPJ_SIZE_T)-1;
    6.81 -
    6.82 -	memcpy( p_buffer, pData+pUserdata->mOffset, nRead );
    6.83 -
    6.84 -	pUserdata->mOffset += nRead;
    6.85 -
    6.86 -	return nRead;
    6.87 -}
    6.88 -
    6.89 -OPJ_SIZE_T nd_opj_stream_write_fn(void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data)
    6.90 -{
    6.91 -	ndUserdata *pUserdata = reinterpret_cast< ndUserdata* >( p_user_data );
    6.92 -	llassert_always( !pUserdata->mInputStream );
    6.93 -
    6.94 -	pUserdata->mOutput.reserve( pUserdata->mOutput.size() + p_nb_bytes );
    6.95 -	memcpy( &pUserdata->mOutput[ pUserdata->mOutput.size() ], p_buffer, p_nb_bytes );
    6.96 -
    6.97 -	return p_nb_bytes;
    6.98 -}
    6.99 -
   6.100 -OPJ_OFF_T nd_opj_stream_skip_fn(OPJ_OFF_T p_nb_bytes, void * p_user_data)
   6.101 -{
   6.102 -	ndUserdata *pUserdata = reinterpret_cast< ndUserdata* >( p_user_data );
   6.103 -	llassert_always( pUserdata->mInputStream );
   6.104 -
   6.105 -	size_t nImgsize =  pUserdata->mInput->getDataSize();
   6.106 -	size_t nByteLeft = (nImgsize - pUserdata->mOffset);
   6.107 -
   6.108 -	size_t nSkip = p_nb_bytes;
   6.109 -
   6.110 -	if( nSkip > nByteLeft )
   6.111 -		nSkip = nByteLeft;
   6.112 -	
   6.113 -	pUserdata->mOffset += nSkip;
   6.114 -
   6.115 -	return pUserdata->mOffset;
   6.116 -}
   6.117 -
   6.118 -OPJ_BOOL nd_opj_stream_seek_fn(OPJ_OFF_T p_nb_bytes, void * p_user_data)
   6.119 -{
   6.120 -	ndUserdata *pUserdata = reinterpret_cast< ndUserdata* >( p_user_data );
   6.121 -	llassert_always( pUserdata->mInputStream );
   6.122 -
   6.123 -	size_t nImgsize =  pUserdata->mInput->getDataSize();
   6.124 -	size_t nSeek = p_nb_bytes;
   6.125 -	
   6.126 -	if( nSeek > nImgsize )
   6.127 -		return OPJ_FALSE;
   6.128 -	
   6.129 -	pUserdata->mOffset = nSeek;
   6.130 -	return OPJ_TRUE;
   6.131 -}
   6.132 -
   6.133 -// Factory function: see declaration in llimagej2c.cpp
   6.134 -LLImageJ2CImpl* fallbackCreateLLImageJ2CImpl()
   6.135 -{
   6.136 -	return new LLImageJ2COJ();
   6.137 -}
   6.138 -
   6.139 -std::string LLImageJ2COJ::getEngineInfo() const
   6.140 -{
   6.141 -	return std::string("OpenJPEG: " OPENJPEG_VERSION ", Runtime: ")
   6.142 -		+ opj_version();
   6.143 -}
   6.144 -
   6.145 -// Return string from message, eliminating final \n if present
   6.146 -static std::string chomp(const char* msg)
   6.147 -{
   6.148 -	// stomp trailing \n
   6.149 -	std::string message = msg;
   6.150 -	if (!message.empty())
   6.151 -	{
   6.152 -		size_t last = message.size() - 1;
   6.153 -		if (message[last] == '\n')
   6.154 -		{
   6.155 -			message.resize( last );
   6.156 -		}
   6.157 -	}
   6.158 -	return message;
   6.159 -}
   6.160 -
   6.161 -/**
   6.162 -sample error callback expecting a LLFILE* client object
   6.163 -*/
   6.164 -void error_callback(const char* msg, void*)
   6.165 -{
   6.166 -	LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
   6.167 -}
   6.168 -/**
   6.169 -sample warning callback expecting a LLFILE* client object
   6.170 -*/
   6.171 -void warning_callback(const char* msg, void*)
   6.172 -{
   6.173 -	LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
   6.174 -}
   6.175 -/**
   6.176 -sample debug callback expecting no client object
   6.177 -*/
   6.178 -void info_callback(const char* msg, void*)
   6.179 -{
   6.180 -	LL_DEBUGS() << "LLImageJ2COJ: " << chomp(msg) << LL_ENDL;
   6.181 -}
   6.182 -
   6.183 -// Divide a by 2 to the power of b and round upwards
   6.184 -int ceildivpow2(int a, int b)
   6.185 -{
   6.186 -	return (a + (1 << b) - 1) >> b;
   6.187 -}
   6.188 -
   6.189 -
   6.190 -LLImageJ2COJ::LLImageJ2COJ()
   6.191 -	: LLImageJ2CImpl()
   6.192 -{
   6.193 -}
   6.194 -
   6.195 -
   6.196 -LLImageJ2COJ::~LLImageJ2COJ()
   6.197 -{
   6.198 -}
   6.199 -
   6.200 -bool LLImageJ2COJ::initDecode(LLImageJ2C &base, LLImageRaw &raw_image, int discard_level, int* region)
   6.201 -{
   6.202 -	// No specific implementation for this method in the OpenJpeg case
   6.203 -	return false;
   6.204 -}
   6.205 -
   6.206 -bool LLImageJ2COJ::initEncode(LLImageJ2C &base, LLImageRaw &raw_image, int blocks_size, int precincts_size, int levels)
   6.207 -{
   6.208 -	// No specific implementation for this method in the OpenJpeg case
   6.209 -	return false;
   6.210 -}
   6.211 -
   6.212 -bool LLImageJ2COJ::decodeImpl(LLImageJ2C &base, LLImageRaw &raw_image, F32 decode_time, S32 first_channel, S32 max_channel_count)
   6.213 -{
   6.214 -	// <FS:Techwolf Lupindo> texture comment metadata reader
   6.215 -	U8* c_data = base.getData();
   6.216 -	S32 c_size =  base.getDataSize();
   6.217 -	S32 position = 0;
   6.218 -
   6.219 -	while (position < 1024 && position < (c_size - 7)) // the comment field should be in the first 1024 bytes.
   6.220 -	{
   6.221 -		if (c_data[position] == 0xff && c_data[position + 1] == 0x64)
   6.222 -		{
   6.223 -			U8 high_byte = c_data[position + 2];
   6.224 -			U8 low_byte = c_data[position + 3];
   6.225 -			S32 c_length = (high_byte * 256) + low_byte; // This size also counts the markers, 00 01 and itself
   6.226 -			if (c_length > 200) // sanity check
   6.227 -			{
   6.228 -				// While comments can be very long, anything longer then 200 is suspect. 
   6.229 -				break;
   6.230 -			}
   6.231 -
   6.232 -			if (position + 2 + c_length > c_size)
   6.233 -			{
   6.234 -				// comment extends past end of data, corruption, or all data not retrived yet.
   6.235 -				break;
   6.236 -			}
   6.237 -
   6.238 -			// if the comment block does not end at the end of data, check to see if the next
   6.239 -			// block starts with 0xFF
   6.240 -			if (position + 2 + c_length < c_size && c_data[position + 2 + c_length] != 0xff)
   6.241 -			{
   6.242 -				// invalied comment block
   6.243 -				break;
   6.244 -			}
   6.245 -
   6.246 -			// extract the comment minus the markers, 00 01
   6.247 -			raw_image.mComment.assign((char*)(c_data + position + 6), c_length - 4);
   6.248 -			break;
   6.249 -		}
   6.250 -		position++;
   6.251 -	}
   6.252 -	// </FS:Techwolf Lupindo>
   6.253 -
   6.254 -	LLTimer decode_timer;
   6.255 -
   6.256 -	opj_dparameters_t parameters;	/* decompression parameters */
   6.257 -
   6.258 -	/* set decoding parameters to default values */
   6.259 -	opj_set_default_decoder_parameters(&parameters);
   6.260 -
   6.261 -	parameters.cp_reduce = base.getRawDiscardLevel();
   6.262 -
   6.263 -	opj_codec_t *pDecoder = opj_create_decompress( OPJ_CODEC_J2K );
   6.264 -
   6.265 -	opj_set_error_handler( pDecoder, error_callback, 0 );
   6.266 -	opj_set_warning_handler( pDecoder, warning_callback, 0 );
   6.267 -	opj_set_info_handler( pDecoder, info_callback, 0 );
   6.268 -
   6.269 -	opj_stream_t *pStream = opj_stream_default_create( OPJ_TRUE );
   6.270 -
   6.271 -	opj_stream_set_read_function( pStream, nd_opj_stream_read_fn );
   6.272 -	opj_stream_set_write_function( pStream, nd_opj_stream_write_fn );
   6.273 -	opj_stream_set_skip_function( pStream, nd_opj_stream_skip_fn );
   6.274 -	opj_stream_set_seek_function( pStream, nd_opj_stream_seek_fn );
   6.275 -	opj_stream_set_user_data_length( pStream, base.getDataSize() );
   6.276 -	
   6.277 -	ndUserdata *pStreamdata( new ndUserdata( true ) );
   6.278 -	pStreamdata->mInput = &base;
   6.279 -	opj_stream_set_user_data (pStream, pStreamdata, freeUserdata );
   6.280 -
   6.281 -	opj_setup_decoder( pDecoder, &parameters );
   6.282 -
   6.283 -	opj_image_t *image(0);
   6.284 -	opj_read_header( pStream, pDecoder, &image );
   6.285 -
   6.286 -	opj_decode( pDecoder, pStream, image);
   6.287 -
   6.288 -	opj_stream_destroy( pStream );
   6.289 -
   6.290 -	if( pDecoder )
   6.291 -		opj_destroy_codec( pDecoder );
   6.292 -
   6.293 -	// The image decode failed if the return was NULL or the component
   6.294 -	// count was zero.  The latter is just a sanity check before we
   6.295 -	// dereference the array.
   6.296 -	if(!image || !image->numcomps)
   6.297 -	{
   6.298 -		LL_DEBUGS("Texture") << "ERROR -> decodeImpl: failed to decode image!" << LL_ENDL;
   6.299 -		if (image)
   6.300 -		{
   6.301 -			opj_image_destroy(image);
   6.302 -		}
   6.303 -
   6.304 -		return true; // done
   6.305 -	}
   6.306 -
   6.307 -	// sometimes we get bad data out of the cache - check to see if the decode succeeded
   6.308 -	for (S32 i = 0; i < image->numcomps; i++)
   6.309 -	{
   6.310 -		if (image->comps[i].factor != base.getRawDiscardLevel())
   6.311 -		{
   6.312 -			// if we didn't get the discard level we're expecting, fail
   6.313 -			opj_image_destroy(image);
   6.314 -			base.mDecoding = false;
   6.315 -			return true;
   6.316 -		}
   6.317 -	}
   6.318 -	
   6.319 -	if(image->numcomps <= first_channel)
   6.320 -	{
   6.321 -		LL_WARNS() << "trying to decode more channels than are present in image: numcomps: " << image->numcomps << " first_channel: " << first_channel << LL_ENDL;
   6.322 -		if (image)
   6.323 -		{
   6.324 -			opj_image_destroy(image);
   6.325 -		}
   6.326 -			
   6.327 -		return true;
   6.328 -	}
   6.329 -
   6.330 -	// Copy image data into our raw image format (instead of the separate channel format
   6.331 -
   6.332 -	S32 img_components = image->numcomps;
   6.333 -	S32 channels = img_components - first_channel;
   6.334 -	if( channels > max_channel_count )
   6.335 -		channels = max_channel_count;
   6.336 -
   6.337 -	// Component buffers are allocated in an image width by height buffer.
   6.338 -	// The image placed in that buffer is ceil(width/2^factor) by
   6.339 -	// ceil(height/2^factor) and if the factor isn't zero it will be at the
   6.340 -	// top left of the buffer with black filled in the rest of the pixels.
   6.341 -	// It is integer math so the formula is written in ceildivpo2.
   6.342 -	// (Assuming all the components have the same width, height and
   6.343 -	// factor.)
   6.344 -	S32 comp_width = image->comps[0].w;
   6.345 -	S32 f=image->comps[0].factor;
   6.346 -	S32 width = ceildivpow2(image->x1 - image->x0, f);
   6.347 -	S32 height = ceildivpow2(image->y1 - image->y0, f);
   6.348 -	raw_image.resize(width, height, channels);
   6.349 -	U8 *rawp = raw_image.getData();
   6.350 -
   6.351 -	// <FS:Ansariel> Port fix for MAINT-4327/MAINT-6584 to OpenJPEG decoder
   6.352 -	if (!rawp)
   6.353 -	{
   6.354 -		base.setLastError("Memory error");
   6.355 -		base.decodeFailed();
   6.356 -		opj_image_destroy(image);
   6.357 -		return true; // done
   6.358 -	}
   6.359 -	// <FS:Ansariel>
   6.360 -
   6.361 -	// first_channel is what channel to start copying from
   6.362 -	// dest is what channel to copy to.  first_channel comes from the
   6.363 -	// argument, dest always starts writing at channel zero.
   6.364 -	for (S32 comp = first_channel, dest=0; comp < first_channel + channels;
   6.365 -		comp++, dest++)
   6.366 -	{
   6.367 -		if (image->comps[comp].data)
   6.368 -		{
   6.369 -			S32 offset = dest;
   6.370 -			for (S32 y = (height - 1); y >= 0; y--)
   6.371 -			{
   6.372 -				for (S32 x = 0; x < width; x++)
   6.373 -				{
   6.374 -					rawp[offset] = image->comps[comp].data[y*comp_width + x];
   6.375 -					offset += channels;
   6.376 -				}
   6.377 -			}
   6.378 -		}
   6.379 -		else // Some rare OpenJPEG versions have this bug.
   6.380 -		{
   6.381 -			LL_DEBUGS("Texture") << "ERROR -> decodeImpl: failed to decode image! (NULL comp data - OpenJPEG bug)" << LL_ENDL;
   6.382 -			opj_image_destroy(image);
   6.383 -
   6.384 -			return true; // done
   6.385 -		}
   6.386 -	}
   6.387 -
   6.388 -	/* free image data structure */
   6.389 -	opj_image_destroy(image);
   6.390 -
   6.391 -	return true; // done
   6.392 -}
   6.393 -
   6.394 -
   6.395 -bool LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, const char* comment_text, F32 encode_time, bool reversible)
   6.396 -{
   6.397 -	const S32 MAX_COMPS = 5;
   6.398 -	opj_cparameters_t parameters;	/* compression parameters */
   6.399 -
   6.400 -
   6.401 -	/* set encoding parameters to default values */
   6.402 -	opj_set_default_encoder_parameters(&parameters);
   6.403 -	parameters.cod_format = 0;
   6.404 -	parameters.cp_disto_alloc = 1;
   6.405 -
   6.406 -	if (reversible)
   6.407 -	{
   6.408 -		parameters.tcp_numlayers = 1;
   6.409 -		parameters.tcp_rates[0] = 0.0f;
   6.410 -	}
   6.411 -	else
   6.412 -	{
   6.413 -		parameters.tcp_numlayers = 5;
   6.414 -                parameters.tcp_rates[0] = 1920.0f;
   6.415 -                parameters.tcp_rates[1] = 480.0f;
   6.416 -                parameters.tcp_rates[2] = 120.0f;
   6.417 -                parameters.tcp_rates[3] = 30.0f;
   6.418 -		parameters.tcp_rates[4] = 10.0f;
   6.419 -		parameters.irreversible = 1;
   6.420 -		if (raw_image.getComponents() >= 3)
   6.421 -		{
   6.422 -			parameters.tcp_mct = 1;
   6.423 -		}
   6.424 -	}
   6.425 -
   6.426 -	if (!comment_text)
   6.427 -	{
   6.428 -		parameters.cp_comment = (char *) "";
   6.429 -	}
   6.430 -	else
   6.431 -	{
   6.432 -		// Awful hacky cast, too lazy to copy right now.
   6.433 -		parameters.cp_comment = (char *) comment_text;
   6.434 -	}
   6.435 -
   6.436 -	//
   6.437 -	// Fill in the source image from our raw image
   6.438 -	//
   6.439 -	OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_SRGB;
   6.440 -	opj_image_cmptparm_t cmptparm[MAX_COMPS];
   6.441 -	opj_image_t * image = NULL;
   6.442 -	S32 numcomps = raw_image.getComponents();
   6.443 -	S32 width = raw_image.getWidth();
   6.444 -	S32 height = raw_image.getHeight();
   6.445 -
   6.446 -	memset(&cmptparm[0], 0, MAX_COMPS * sizeof(opj_image_cmptparm_t));
   6.447 -	for(S32 c = 0; c < numcomps; c++) {
   6.448 -		cmptparm[c].prec = 8;
   6.449 -		cmptparm[c].bpp = 8;
   6.450 -		cmptparm[c].sgnd = 0;
   6.451 -		cmptparm[c].dx = parameters.subsampling_dx;
   6.452 -		cmptparm[c].dy = parameters.subsampling_dy;
   6.453 -		cmptparm[c].w = width;
   6.454 -		cmptparm[c].h = height;
   6.455 -	}
   6.456 -
   6.457 -	/* create the image */
   6.458 -	image = opj_image_create(numcomps, &cmptparm[0], color_space);
   6.459 -
   6.460 -	image->x1 = width;
   6.461 -	image->y1 = height;
   6.462 -
   6.463 -	S32 i = 0;
   6.464 -	const U8 *src_datap = raw_image.getData();
   6.465 -	for (S32 y = height - 1; y >= 0; y--)
   6.466 -	{
   6.467 -		for (S32 x = 0; x < width; x++)
   6.468 -		{
   6.469 -			const U8 *pixel = src_datap + (y*width + x) * numcomps;
   6.470 -			for (S32 c = 0; c < numcomps; c++)
   6.471 -			{
   6.472 -				image->comps[c].data[i] = *pixel;
   6.473 -				pixel++;
   6.474 -			}
   6.475 -			i++;
   6.476 -		}
   6.477 -	}
   6.478 -
   6.479 -	int codestream_length;
   6.480 -
   6.481 -	/* get a J2K compressor handle */
   6.482 -	opj_codec_t * pEncoder = opj_create_compress( OPJ_CODEC_J2K );
   6.483 -
   6.484 -	opj_set_error_handler( pEncoder, error_callback, 0 );
   6.485 -	opj_set_warning_handler( pEncoder, warning_callback, 0 );
   6.486 -	opj_set_info_handler( pEncoder, info_callback, 0 );
   6.487 -
   6.488 -	opj_setup_encoder(pEncoder, &parameters, image);
   6.489 -
   6.490 -	opj_stream_t *pStream = opj_stream_default_create( OPJ_FALSE );
   6.491 -
   6.492 -	opj_stream_set_read_function(pStream, nd_opj_stream_read_fn );
   6.493 -	opj_stream_set_write_function(pStream, nd_opj_stream_write_fn );
   6.494 -	opj_stream_set_skip_function(pStream, nd_opj_stream_skip_fn );
   6.495 -	opj_stream_set_seek_function(pStream, nd_opj_stream_seek_fn );
   6.496 -	opj_stream_set_user_data_length( pStream, raw_image.getDataSize() );
   6.497 -
   6.498 -	ndUserdata *pStreamdata( new ndUserdata( false ) );
   6.499 -	opj_stream_set_user_data (pStream, pStreamdata, freeUserdata );
   6.500 -
   6.501 -	bool bSuccess = opj_encode( pEncoder, pStream );
   6.502 -	if (!bSuccess)
   6.503 -	{
   6.504 -		LL_DEBUGS("Texture") << "Failed to encode image." << LL_ENDL;
   6.505 -		return false;
   6.506 -	}
   6.507 -
   6.508 -	codestream_length = pStreamdata->mOutput.size();
   6.509 -
   6.510 -	base.copyData( (U8*)&pStreamdata->mOutput[0], codestream_length);
   6.511 -	base.updateData(); // set width, height
   6.512 -
   6.513 -	opj_stream_destroy( pStream );
   6.514 -
   6.515 -	opj_destroy_codec( pEncoder );
   6.516 -
   6.517 -
   6.518 -	/* free user parameters structure */
   6.519 -	if(parameters.cp_matrice) free(parameters.cp_matrice);
   6.520 -
   6.521 -	/* free image data */
   6.522 -	opj_image_destroy(image);
   6.523 -	return true;
   6.524 -}
   6.525 -
   6.526 -inline S32 extractLong4( U8 const *aBuffer, int nOffset )
   6.527 -{
   6.528 -	S32 ret = aBuffer[ nOffset ] << 24;
   6.529 -	ret += aBuffer[ nOffset + 1 ] << 16;
   6.530 -	ret += aBuffer[ nOffset + 2 ] << 8;
   6.531 -	ret += aBuffer[ nOffset + 3 ];
   6.532 -	return ret;
   6.533 -}
   6.534 -
   6.535 -inline S32 extractShort2( U8 const *aBuffer, int nOffset )
   6.536 -{
   6.537 -	S32 ret = aBuffer[ nOffset ] << 8;
   6.538 -	ret += aBuffer[ nOffset + 1 ];
   6.539 -
   6.540 -	return ret;
   6.541 -}
   6.542 -
   6.543 -inline bool isSOC( U8 const *aBuffer )
   6.544 -{
   6.545 -	return aBuffer[ 0 ] == 0xFF && aBuffer[ 1 ] == 0x4F;
   6.546 -}
   6.547 -
   6.548 -inline bool isSIZ( U8 const *aBuffer )
   6.549 -{
   6.550 -	return aBuffer[ 0 ] == 0xFF && aBuffer[ 1 ] == 0x51;
   6.551 -}
   6.552 -
   6.553 -bool getMetadataFast( LLImageJ2C &aImage, S32 &aW, S32 &aH, S32 &aComps )
   6.554 -{
   6.555 -	const int J2K_HDR_LEN( 42 );
   6.556 -	const int J2K_HDR_X1( 8 );
   6.557 -	const int J2K_HDR_Y1( 12 );
   6.558 -	const int J2K_HDR_X0( 16 );
   6.559 -	const int J2K_HDR_Y0( 20 );
   6.560 -	const int J2K_HDR_NUMCOMPS( 40 );
   6.561 -
   6.562 -	if( aImage.getDataSize() < J2K_HDR_LEN )
   6.563 -		return false;
   6.564 -
   6.565 -	U8 const* pBuffer = aImage.getData();
   6.566 -
   6.567 -	if( !isSOC( pBuffer ) || !isSIZ( pBuffer+2 ) )
   6.568 -		return false;
   6.569 -
   6.570 -	S32 x1 = extractLong4( pBuffer, J2K_HDR_X1 );
   6.571 -	S32 y1 = extractLong4( pBuffer, J2K_HDR_Y1 );
   6.572 -	S32 x0 = extractLong4( pBuffer, J2K_HDR_X0 );
   6.573 -	S32 y0 = extractLong4( pBuffer, J2K_HDR_Y0 );
   6.574 -	S32 numComps = extractShort2( pBuffer, J2K_HDR_NUMCOMPS );
   6.575 -
   6.576 -	aComps = numComps;
   6.577 -	aW = x1 - x0;
   6.578 -	aH = y1 - y0;
   6.579 -
   6.580 -	return true;
   6.581 -}
   6.582 -
   6.583 -bool LLImageJ2COJ::getMetadata(LLImageJ2C &base)
   6.584 -{
   6.585 -	//
   6.586 -	// FIXME: We get metadata by decoding the ENTIRE image.
   6.587 -	//
   6.588 -
   6.589 -	// Update the raw discard level
   6.590 -	base.updateRawDiscardLevel();
   6.591 -
   6.592 -	S32 width(0);
   6.593 -	S32 height(0);
   6.594 -	S32 img_components(0);
   6.595 -
   6.596 -	if ( getMetadataFast( base, width, height, img_components ) )
   6.597 -	{
   6.598 -		base.setSize(width, height, img_components);
   6.599 -		return true;
   6.600 -	}
   6.601 -
   6.602 -	// Do it the old and slow way, decode the image with openjpeg
   6.603 -
   6.604 -	opj_dparameters_t parameters;	/* decompression parameters */
   6.605 -
   6.606 -	/* set decoding parameters to default values */
   6.607 -	opj_set_default_decoder_parameters(&parameters);
   6.608 -
   6.609 -	parameters.cp_reduce = base.getRawDiscardLevel();
   6.610 -
   6.611 -	opj_codec_t *pDecoder = opj_create_decompress( OPJ_CODEC_J2K );
   6.612 -
   6.613 -	opj_set_error_handler( pDecoder, error_callback, 0 );
   6.614 -	opj_set_warning_handler( pDecoder, warning_callback, 0 );
   6.615 -	opj_set_info_handler( pDecoder, info_callback, 0 );
   6.616 -
   6.617 -	opj_stream_t *pStream = opj_stream_default_create( OPJ_TRUE );
   6.618 -
   6.619 -	opj_stream_set_read_function(pStream, nd_opj_stream_read_fn );
   6.620 -	opj_stream_set_write_function(pStream, nd_opj_stream_write_fn );
   6.621 -	opj_stream_set_skip_function(pStream, nd_opj_stream_skip_fn );
   6.622 -	opj_stream_set_seek_function(pStream, nd_opj_stream_seek_fn );
   6.623 -
   6.624 -	ndUserdata *pStreamdata( new ndUserdata( true ) );
   6.625 -	pStreamdata->mInput = &base;
   6.626 -	opj_stream_set_user_data (pStream, pStreamdata, freeUserdata );
   6.627 -	opj_stream_set_user_data_length( pStream, base.getDataSize() );
   6.628 -
   6.629 -	opj_setup_decoder( pDecoder, &parameters );
   6.630 -
   6.631 -	opj_image_t *image(0);
   6.632 -	opj_read_header( pStream, pDecoder, &image );
   6.633 -
   6.634 -	opj_decode( pDecoder, pStream, image);
   6.635 -
   6.636 -	opj_stream_destroy( pStream );
   6.637 -
   6.638 -	if( pDecoder )
   6.639 -		opj_destroy_codec( pDecoder );
   6.640 -
   6.641 -	if(!image)
   6.642 -	{
   6.643 -		LL_WARNS() << "ERROR -> getMetadata: failed to decode image!" << LL_ENDL;
   6.644 -		return false;
   6.645 -	}
   6.646 -
   6.647 -	// Copy image data into our raw image format (instead of the separate channel format
   6.648 -
   6.649 -	img_components = image->numcomps;
   6.650 -	width = image->x1 - image->x0;
   6.651 -	height = image->y1 - image->y0;
   6.652 -
   6.653 -	base.setSize(width, height, img_components);
   6.654 -
   6.655 -	/* free image data structure */
   6.656 -	opj_image_destroy(image);
   6.657 -	return true;
   6.658 -}
     7.1 --- a/indra/newview/viewer_manifest.py	Thu Apr 12 21:09:38 2018 +0200
     7.2 +++ b/indra/newview/viewer_manifest.py	Fri Apr 13 23:04:06 2018 +0200
     7.3 @@ -628,7 +628,6 @@
     7.4  
     7.5              # For textures
     7.6              self.path("openjpeg.dll")
     7.7 -            self.path("openjp2.dll") # <FS:ND/> OpenJPEG2 if used
     7.8  
     7.9              # These need to be installed as a SxS assembly, currently a 'private' assembly.
    7.10              # See http://msdn.microsoft.com/en-us/library/ms235291(VS.80).aspx

mercurial