Skip to content

Commit 1c72cd7

Browse files
Hecklezzakleshchev
authored andcommitted
Fix uploading small textures with OpenJPEG, and minor logging refactor.
1 parent 230244b commit 1c72cd7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

indra/llimagej2coj/llimagej2coj.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,20 @@ class JPEG2KEncode : public JPEG2KBase
551551
opj_set_warning_handler(encoder, opj_warn, this);
552552
opj_set_error_handler(encoder, opj_error, this);
553553

554-
U32 tile_count = (rawImageIn.getWidth() >> 6) * (rawImageIn.getHeight() >> 6);
554+
U32 width_tiles = (rawImageIn.getWidth() >> 6);
555+
U32 height_tiles = (rawImageIn.getHeight() >> 6);
556+
557+
// Allow images with a width or height that are MIN_IMAGE_SIZE <= x < 64
558+
if (width_tiles == 0 && (rawImageIn.getWidth() >= MIN_IMAGE_SIZE))
559+
{
560+
width_tiles = 1;
561+
}
562+
if (height_tiles == 0 && (rawImageIn.getHeight() >= MIN_IMAGE_SIZE))
563+
{
564+
height_tiles = 1;
565+
}
566+
567+
U32 tile_count = width_tiles * height_tiles;
555568
U32 data_size_guess = tile_count * TILE_SIZE;
556569

557570
// will be freed in opj_free_user_data_write
@@ -857,12 +870,11 @@ bool LLImageJ2COJ::encodeImpl(LLImageJ2C &base, const LLImageRaw &raw_image, con
857870
{
858871
JPEG2KEncode encode(comment_text, reversible);
859872
bool encoded = encode.encode(raw_image, base);
860-
if (encoded)
873+
if (!encoded)
861874
{
862-
LL_WARNS() << "Openjpeg encoding implementation isn't complete, returning false" << LL_ENDL;
875+
LL_WARNS() << "Openjpeg encoding was unsuccessful, returning false" << LL_ENDL;
863876
}
864877
return encoded;
865-
//return false;
866878
}
867879

868880
bool LLImageJ2COJ::getMetadata(LLImageJ2C &base)

0 commit comments

Comments
 (0)