Skip to content

Commit d844aa0

Browse files
committed
#3816 Fix J2C Upload
1 parent b1822e3 commit d844aa0

File tree

7 files changed

+57
-3
lines changed

7 files changed

+57
-3
lines changed

indra/llimage/llimagedimensionsinfo.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "stdtypes.h"
2828

2929
#include "llimagejpeg.h"
30+
#include "llimagej2c.h"
3031

3132
#include "llimagedimensionsinfo.h"
3233

@@ -63,6 +64,8 @@ bool LLImageDimensionsInfo::load(const std::string& src_filename,U32 codec)
6364
return getImageDimensionsTga();
6465
case IMG_CODEC_JPEG:
6566
return getImageDimensionsJpeg();
67+
case IMG_CODEC_J2C:
68+
return getImageDimensionsJ2c();
6669
case IMG_CODEC_PNG:
6770
return getImageDimensionsPng();
6871
default:
@@ -214,6 +217,23 @@ bool LLImageDimensionsInfo::getImageDimensionsJpeg()
214217
return !sJpegErrorEncountered;
215218
}
216219

220+
bool LLImageDimensionsInfo::getImageDimensionsJ2c()
221+
{
222+
clean();
223+
224+
LLPointer<LLImageJ2C> jpeg_image = new LLImageJ2C;
225+
if (jpeg_image->load(mSrcFilename))
226+
{
227+
mWidth = jpeg_image->getWidth();
228+
mHeight = jpeg_image->getHeight();
229+
return true;
230+
}
231+
mWarning = "texture_load_format_error";
232+
LL_WARNS() << "J2C load error: " << LLImage::getLastThreadError() << LL_ENDL;
233+
234+
return false;
235+
}
236+
217237
bool LLImageDimensionsInfo::checkFileLength(S32 min_len)
218238
{
219239
// Make sure the file is not shorter than min_len bytes.

indra/llimage/llimagedimensionsinfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class LLImageDimensionsInfo
9191
bool getImageDimensionsTga();
9292
bool getImageDimensionsPng();
9393
bool getImageDimensionsJpeg();
94+
bool getImageDimensionsJ2c();
9495

9596
S32 read_s32()
9697
{

indra/newview/llfilepicker.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LLFilePicker LLFilePicker::sInstance;
5252

5353
#if LL_WINDOWS
5454
#define SOUND_FILTER L"Sounds (*.wav)\0*.wav\0"
55-
#define IMAGE_FILTER L"Images (*.tga; *.bmp; *.jpg; *.jpeg; *.png)\0*.tga;*.bmp;*.jpg;*.jpeg;*.png\0"
55+
#define IMAGE_FILTER L"Images (*.tga; *.bmp; *.jpg; *.jpeg; *.j2c; *.jp2; *.png)\0*.tga;*.bmp;*.jpg;*.jpeg;*.j2c;*.jp2;*.png\0"
5656
#define ANIM_FILTER L"Animations (*.bvh; *.anim)\0*.bvh;*.anim\0"
5757
#define COLLADA_FILTER L"Scene (*.dae)\0*.dae\0"
5858
#define GLTF_FILTER L"glTF (*.gltf; *.glb)\0*.gltf;*.glb\0"
@@ -559,7 +559,7 @@ bool LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename,
559559
}
560560
mOFN.lpstrDefExt = L"j2c";
561561
mOFN.lpstrFilter =
562-
L"Compressed Images (*.j2c)\0*.j2c\0" \
562+
L"Compressed Images (*.j2c *.jp2)\0*.j2c;*.jp2\0" \
563563
L"\0";
564564
break;
565565
case FFSAVE_SCRIPT:
@@ -649,6 +649,9 @@ std::unique_ptr<std::vector<std::string>> LLFilePicker::navOpenFilterProc(ELoadF
649649
case FFLOAD_IMAGE:
650650
allowedv->push_back("jpg");
651651
allowedv->push_back("jpeg");
652+
allowedv->push_back("j2c");
653+
allowedv->push_back("jp2");
654+
allowedv->push_back("png");
652655
allowedv->push_back("bmp");
653656
allowedv->push_back("tga");
654657
allowedv->push_back("bmpf");

indra/newview/lllocalbitmaps.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
/* image compression headers. */
3939
#include "llimagebmp.h"
4040
#include "llimagetga.h"
41+
#include "llimagej2c.h"
4142
#include "llimagejpeg.h"
4243
#include "llimagepng.h"
4344

@@ -106,6 +107,10 @@ LLLocalBitmap::LLLocalBitmap(std::string filename)
106107
{
107108
mExtension = ET_IMG_JPG;
108109
}
110+
else if (temp_exten == "j2c" || temp_exten == "jp2")
111+
{
112+
mExtension = ET_IMG_J2C;
113+
}
109114
else if (temp_exten == "png")
110115
{
111116
mExtension = ET_IMG_PNG;
@@ -356,6 +361,21 @@ bool LLLocalBitmap::decodeBitmap(LLPointer<LLImageRaw> rawimg)
356361
break;
357362
}
358363

364+
case ET_IMG_J2C:
365+
{
366+
LLPointer<LLImageJ2C> jpeg_image = new LLImageJ2C;
367+
if (jpeg_image->load(mFilename))
368+
{
369+
jpeg_image->setDiscardLevel(0);
370+
if (jpeg_image->decode(rawimg, 0.0f))
371+
{
372+
rawimg->biasedScaleToPowerOfTwo(LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT);
373+
decode_successful = true;
374+
}
375+
}
376+
break;
377+
}
378+
359379
case ET_IMG_PNG:
360380
{
361381
LLPointer<LLImagePNG> png_image = new LLImagePNG;

indra/newview/lllocalbitmaps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class LLLocalBitmap
8989
ET_IMG_BMP,
9090
ET_IMG_TGA,
9191
ET_IMG_JPG,
92+
ET_IMG_J2C,
9293
ET_IMG_PNG
9394
};
9495

indra/newview/llviewermenufile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void LLMediaFilePicker::notify(const std::vector<std::string>& filenames)
378378

379379
#if LL_WINDOWS
380380
static std::string SOUND_EXTENSIONS = "wav";
381-
static std::string IMAGE_EXTENSIONS = "tga bmp jpg jpeg png";
381+
static std::string IMAGE_EXTENSIONS = "tga bmp jpg jpeg j2c jp2 png";
382382
static std::string ANIM_EXTENSIONS = "bvh anim";
383383
static std::string XML_EXTENSIONS = "xml";
384384
static std::string SLOBJECT_EXTENSIONS = "slobject";

indra/newview/llviewertexturelist.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,15 @@ bool LLViewerTextureList::createUploadFile(const std::string& filename,
14191419
image->setLastError("Couldn't load the image to be uploaded.");
14201420
return false;
14211421
}
1422+
1423+
// calcDataSizeJ2C assumes maximum size is 2048 and for bigger images can
1424+
// assign discard to bring imige to needed size, but upload does the scaling
1425+
// as needed, so just reset discard.
1426+
// Assume file is full and has 'discard' 0 data.
1427+
// Todo: probably a better idea to have some setMaxDimentions in J2C
1428+
// called when loading from a local file
1429+
image->setDiscardLevel(0);
1430+
14221431
// Decompress or expand it in a raw image structure
14231432
LLPointer<LLImageRaw> raw_image = new LLImageRaw;
14241433
if (!image->decode(raw_image, 0.0f))

0 commit comments

Comments
 (0)