diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2025-03-28 21:49:58 +0200 |
---|---|---|
committer | Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> | 2025-03-31 09:56:10 +0300 |
commit | 8d5dab9f67d54ce20768c0ccda58f27693cb20c9 (patch) | |
tree | 0fe79bf228132552160f2b0dd60dfa389a5c9035 | |
parent | b1822e36e531a3c423404f0aa875cbf6949061a0 (diff) |
#3809 Fix J2C Upload
-rw-r--r-- | indra/llimage/llimagedimensionsinfo.cpp | 20 | ||||
-rw-r--r-- | indra/llimage/llimagedimensionsinfo.h | 1 | ||||
-rw-r--r-- | indra/newview/llfilepicker.cpp | 6 | ||||
-rw-r--r-- | indra/newview/lllocalbitmaps.cpp | 20 | ||||
-rw-r--r-- | indra/newview/lllocalbitmaps.h | 1 | ||||
-rw-r--r-- | indra/newview/llviewermenufile.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llviewertexturelist.cpp | 9 |
7 files changed, 56 insertions, 3 deletions
diff --git a/indra/llimage/llimagedimensionsinfo.cpp b/indra/llimage/llimagedimensionsinfo.cpp index d4efbcfad2..49a1777fe5 100644 --- a/indra/llimage/llimagedimensionsinfo.cpp +++ b/indra/llimage/llimagedimensionsinfo.cpp @@ -27,6 +27,7 @@ #include "stdtypes.h" #include "llimagejpeg.h" +#include "llimagej2c.h" #include "llimagedimensionsinfo.h" @@ -63,6 +64,8 @@ bool LLImageDimensionsInfo::load(const std::string& src_filename,U32 codec) return getImageDimensionsTga(); case IMG_CODEC_JPEG: return getImageDimensionsJpeg(); + case IMG_CODEC_J2C: + return getImageDimensionsJ2c(); case IMG_CODEC_PNG: return getImageDimensionsPng(); default: @@ -214,6 +217,23 @@ bool LLImageDimensionsInfo::getImageDimensionsJpeg() return !sJpegErrorEncountered; } +bool LLImageDimensionsInfo::getImageDimensionsJ2c() +{ + clean(); + + LLPointer<LLImageJ2C> jpeg_image = new LLImageJ2C; + if (jpeg_image->load(mSrcFilename)) + { + mWidth = jpeg_image->getWidth(); + mHeight = jpeg_image->getHeight(); + return true; + } + mWarning = "texture_load_format_error"; + LL_WARNS() << "J2C load error: " << LLImage::getLastThreadError() << LL_ENDL; + + return false; +} + bool LLImageDimensionsInfo::checkFileLength(S32 min_len) { // Make sure the file is not shorter than min_len bytes. diff --git a/indra/llimage/llimagedimensionsinfo.h b/indra/llimage/llimagedimensionsinfo.h index 681d66ae4e..820cf33d7e 100644 --- a/indra/llimage/llimagedimensionsinfo.h +++ b/indra/llimage/llimagedimensionsinfo.h @@ -91,6 +91,7 @@ protected: bool getImageDimensionsTga(); bool getImageDimensionsPng(); bool getImageDimensionsJpeg(); + bool getImageDimensionsJ2c(); S32 read_s32() { diff --git a/indra/newview/llfilepicker.cpp b/indra/newview/llfilepicker.cpp index 716e6cd9e3..96ac41a2bf 100644 --- a/indra/newview/llfilepicker.cpp +++ b/indra/newview/llfilepicker.cpp @@ -52,7 +52,7 @@ LLFilePicker LLFilePicker::sInstance; #if LL_WINDOWS #define SOUND_FILTER L"Sounds (*.wav)\0*.wav\0" -#define IMAGE_FILTER L"Images (*.tga; *.bmp; *.jpg; *.jpeg; *.png)\0*.tga;*.bmp;*.jpg;*.jpeg;*.png\0" +#define IMAGE_FILTER L"Images (*.tga; *.bmp; *.jpg; *.jpeg; *.j2c; *.jp2; *.png)\0*.tga;*.bmp;*.jpg;*.jpeg;*.j2c;*.jp2;*.png\0" #define ANIM_FILTER L"Animations (*.bvh; *.anim)\0*.bvh;*.anim\0" #define COLLADA_FILTER L"Scene (*.dae)\0*.dae\0" #define GLTF_FILTER L"glTF (*.gltf; *.glb)\0*.gltf;*.glb\0" @@ -559,7 +559,7 @@ bool LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename, } mOFN.lpstrDefExt = L"j2c"; mOFN.lpstrFilter = - L"Compressed Images (*.j2c)\0*.j2c\0" \ + L"Compressed Images (*.j2c *.jp2)\0*.j2c;*.jp2\0" \ L"\0"; break; case FFSAVE_SCRIPT: @@ -649,6 +649,8 @@ std::unique_ptr<std::vector<std::string>> LLFilePicker::navOpenFilterProc(ELoadF case FFLOAD_IMAGE: allowedv->push_back("jpg"); allowedv->push_back("jpeg"); + allowedv->push_back("j2c"); + allowedv->push_back("jp2"); allowedv->push_back("bmp"); allowedv->push_back("tga"); allowedv->push_back("bmpf"); diff --git a/indra/newview/lllocalbitmaps.cpp b/indra/newview/lllocalbitmaps.cpp index 31c9eb8966..72a7fe8814 100644 --- a/indra/newview/lllocalbitmaps.cpp +++ b/indra/newview/lllocalbitmaps.cpp @@ -38,6 +38,7 @@ /* image compression headers. */ #include "llimagebmp.h" #include "llimagetga.h" +#include "llimagej2c.h" #include "llimagejpeg.h" #include "llimagepng.h" @@ -106,6 +107,10 @@ LLLocalBitmap::LLLocalBitmap(std::string filename) { mExtension = ET_IMG_JPG; } + else if (temp_exten == "j2c" || temp_exten == "jp2") + { + mExtension = ET_IMG_J2C; + } else if (temp_exten == "png") { mExtension = ET_IMG_PNG; @@ -356,6 +361,21 @@ bool LLLocalBitmap::decodeBitmap(LLPointer<LLImageRaw> rawimg) break; } + case ET_IMG_J2C: + { + LLPointer<LLImageJ2C> jpeg_image = new LLImageJ2C; + if (jpeg_image->load(mFilename)) + { + jpeg_image->setDiscardLevel(0); + if (jpeg_image->decode(rawimg, 0.0f)) + { + rawimg->biasedScaleToPowerOfTwo(LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT); + decode_successful = true; + } + } + break; + } + case ET_IMG_PNG: { LLPointer<LLImagePNG> png_image = new LLImagePNG; diff --git a/indra/newview/lllocalbitmaps.h b/indra/newview/lllocalbitmaps.h index e169f96e70..06770334e4 100644 --- a/indra/newview/lllocalbitmaps.h +++ b/indra/newview/lllocalbitmaps.h @@ -89,6 +89,7 @@ class LLLocalBitmap ET_IMG_BMP, ET_IMG_TGA, ET_IMG_JPG, + ET_IMG_J2C, ET_IMG_PNG }; diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp index ce66dbc03f..7a079b267d 100644 --- a/indra/newview/llviewermenufile.cpp +++ b/indra/newview/llviewermenufile.cpp @@ -378,7 +378,7 @@ void LLMediaFilePicker::notify(const std::vector<std::string>& filenames) #if LL_WINDOWS static std::string SOUND_EXTENSIONS = "wav"; -static std::string IMAGE_EXTENSIONS = "tga bmp jpg jpeg png"; +static std::string IMAGE_EXTENSIONS = "tga bmp jpg jpeg j2c jp2 png"; static std::string ANIM_EXTENSIONS = "bvh anim"; static std::string XML_EXTENSIONS = "xml"; static std::string SLOBJECT_EXTENSIONS = "slobject"; diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index ae723b4068..9f23d39506 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -1419,6 +1419,15 @@ bool LLViewerTextureList::createUploadFile(const std::string& filename, image->setLastError("Couldn't load the image to be uploaded."); return false; } + + // calcDataSizeJ2C assumes maximum size is 2048 and for bigger images can + // assign discard to bring imige to needed size, but upload does the scaling + // as needed, so just reset discard. + // Assume file is full and has 'discard' 0 data. + // Todo: probably a better idea to have some setMaxDimentions in J2C + // called when loading from a local file + image->setDiscardLevel(0); + // Decompress or expand it in a raw image structure LLPointer<LLImageRaw> raw_image = new LLImageRaw; if (!image->decode(raw_image, 0.0f)) |