• All submissions to this site are governed by Second Life Project Contribution Agreement. By submitting patches and other information using this site, you acknowledge that you have read, understood, and agreed to those terms.
Issue Details (XML | Word | Printable)

Key: VWR-1475
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Normal Normal
Assignee: Tofu Linden
Reporter: Eddy Stryker
Votes: 2
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
1. Second Life Viewer - VWR

OpenJPEG always uploads single layer lossless images

Created: 01/Jul/07 06:22 PM   Updated: 18/Mar/08 04:53 AM
Return to search
Component/s: None
Affects Version/s: 1.15.0.x, 1.15.1.x, 1.16.0.x, 1.17.0.x, 1.17.1, Source code, First Look: Voice, 1.18.0
Fix Version/s: 1.19.0.5

File Attachments: 1. Text File openjpeg_compression.patch (0.6 kB)
2. Text File slviewer-1.17.3.0-openjpeg-use-lossy-encoding-20070709.patch (2 kB)
3. Text File slviewer-1.18.0.6-openjpeg-use-lossy-encoding-20070716.patch (2 kB)
4. Text File slviewer-1.18.4.3-openjpeg-use-lossy-encoding.patch (1 kB)
5. Text File VWR-1475-ll.patch (1 kB)

Issue Links:
Relates

Source Version: 1.17.0.2 in SVN, at release/indra/llimagej2coj
Linden Lab Issue ID: SL-47228
Patch attached: Patch attached


 Description  « Hide
Sculptie fans are going to hate me for this one .

The encodeImpl() for OpenJPEG currently assigns tcp_numlayers to 1 (through a convoluted parameters.tcp_numlayers++ and tcp_rates[0] to 0 and leaves it at that. This creates a single layer, lossless JPEG2000 file for every image uploaded. The attached patch changes it to create the same number of layers as files created by Kakadu-4.2.1 with close approximations of equivalent compression levels for each layer.

Even better than this would be changing encodeImpl() to add a lossless mode, and adding the lossless support to Kakadu as well but this is all I can do without having access to the KDU code.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Lex Neva added a comment - 02/Jul/07 08:51 AM
Wait, so you're telling me that currently, all textures uploaded into SL are lossless jpegs?

Eddy Stryker added a comment - 02/Jul/07 12:20 PM
If you are using the compiled GPL client without dropping the Kakadu library in, then yes.

Lex Neva added a comment - 03/Jul/07 09:33 AM
Ah, I see. One wonders if this could be used to create pathologically huge textures in order to purposefully lag people.

Sardonyx Linden added a comment - 03/Jul/07 11:38 AM
Eddy, nice catch

I'm looking into this now.


Seg Baphomet added a comment - 03/Jul/07 09:53 PM
Ah, beat me to it. Here's my patch:

— linden.orig/indra/llimagej2coj/llimagej2coj.cpp 2007-06-26 18:46:57.00000>
+++ linden.patched/indra/llimagej2coj/llimagej2coj.cpp 2007-07-03 14:55:02.00>
@@ -211,10 +211,14 @@

/* set encoding parameters to default values */
opj_set_default_encoder_parameters(&parameters);

  • parameters.tcp_rates[0] = 0;
  • parameters.tcp_numlayers++;
  • parameters.cp_disto_alloc = 1;
    parameters.cod_format = 0;
    + parameters.irreversible = 1;
    + parameters.tcp_distoratio[0] = 45.0f;
    + parameters.tcp_numlayers = 1;
    + parameters.cp_fixed_quality = 1;
    + if(raw_image.getComponents() >= 3){ + parameters.tcp_mct = 1; + }
    if (!comment_text)
    {
    parameters.cp_comment = "";

Notes/Recommendations:

This enables the "irreversible" aka lossy DWT, which is what KDU uses. The irreversible DWT is also the code path that Dzonatas and me have optimized quite a bit.

I use a single layer with rate distortion control, I haven't looked at what KDU does. This part could use tuning.

I enable the MCT when there's at least three channels, basically this transforms RGB to YUV format before encoding. This should always be used with RGB images, KDU does, OpenJPEG's command line encoder does, however OpenJPEG's codec configuration API is rather icky (non-existent) and doesn't do this for you. Best bet seems to be to look at codec/image_to_j2k.c for how to set codec parameters.

Ultimately we do want a way to upload lossless textures for use with sculpt maps. MCT may not be of help there.

Note that tcp_rates is a float, so the constants should be in float format to prevent un-necessary casts.


Seg Baphomet added a comment - 03/Jul/07 09:54 PM
I should note that my patch seems to fix all the strange texture baking problems OpenJPEG has always had.

Eddy Stryker added a comment - 08/Jul/07 05:30 AM
Using a single layer for non-lossless images isn't getting us all the way there, because the main feature of JPEG2000 that SL utilizes is the multiple streaming quality layers. The numbers I used (which need to be switched to floating point values in the patch) were based on hand tuning with filesize comparison and visual comparison of the quality of each layer to what SL+KDU output, so not perfect but it should be close. However some of the other parts of your patch should probably be pulled over such as enabling the irreversible DWT, MCT, etc.

Seg Baphomet added a comment - 09/Jul/07 09:55 PM
Okay, I added your settings to mine, and also added a kludge to allow switching between lossless and lossy using a hidden preference. Avatar textures look really nice now, even when lossy.

We need to work out some kind of UI to allow users to upload lossless textures, preferably only when uploading sculpt maps. I don't enable MCT when doing lossless at the moment, really more testing needs to be done to see if MCT does any good with sculpt maps. Not using MCT seems to be what caused the strange colors and color fringing with avatar textures.


Seg Baphomet added a comment - 09/Jul/07 10:06 PM
Ooops, I messed up the lossless rate progression, I intended it to be 1280, 320, 80, 20, 5, 0 which would be /4 each time.

Eddy Stryker added a comment - 11/Jul/07 12:03 AM
When we do lossless uploads in libsecondlife (using OpenJPEG) they are just single layer with tcp_rates[0] = 0; like the current OpenSL code. The images are small enough that there is more overhead downloading multiple resolution layers from the grid rather than just grabbing the full quality ~7KB sculpt map. Other than that I think this is looking great, even if OpenJPEG isn't beating Kakadu on speed right now we can outdo it with features.

Seg Baphomet added a comment - 19/Jul/07 11:30 AM
Updated patch, stick to a single layer when encoding lossless.

Eddy Stryker added a comment - 19/Jul/07 11:46 AM
Sounds good. Lindens looking at this issue I would recommend the latest patch that Seg has posted as it is a combination of all the efforts here.

Sardonyx Linden added a comment - 23/Jul/07 11:12 AM
Seg, what version of openjpeg is this patch for? It doesn't compile with the precompiled version that we bundle, so I'll need to update our library.

Seg Baphomet added a comment - 23/Jul/07 09:42 PM
Its against 1.2. What version is currently bundled?

1.3 should have some major speed improvements if things go to plan.


Renault Clio added a comment - 28/Jul/07 04:31 AM
This did indeed appear to fix the texture baking issues. Now my character doesn't look like some LCD induced hallucination anymore, once the baked textures went to the server.

Renault Clio added a comment - 28/Jul/07 04:45 AM
Spoke too soon.

Seg Baphomet added a comment - 23/Nov/07 01:43 PM
New version of the patch, uses the "reversible" flag that's now available.

Can we get this merged please?


Tofu Linden added a comment - 26/Nov/07 03:13 AM
Hi Seg - is this still requiring simply OpenJPEG 1.2?

Seg Baphomet added a comment - 26/Nov/07 08:53 AM
I'm wondering why it doesn't work with 1.1.x.

1.18.3.x seems to be distributing with OpenJPEG 1.2 now anyway so this patch should work.


Tofu Linden added a comment - 26/Nov/07 09:05 AM
Yup, we're on 1.2 on all platforms now so I'll take a look. Thanks.

Tofu Linden added a comment - 27/Nov/07 07:32 AM
The good news is that the compressed images with this patch are about 1/12 the size as before - the bad news is that it kinda shows in the quality! The results are still about 1/5 the size of KDU's compressed images, so I'm going to pump up the quality to see at which point they seem to become comparable.

Tofu Linden added a comment - 27/Nov/07 09:40 AM
Attached is the patch I'll likely be applying - it's the same as Seg's but with bandwidth/quality tuning a lot closer to our current KDU levels.

Tofu Linden added a comment - 28/Nov/07 10:18 AM
Fixed internally (maintenance-4). Thanks for the patches!

WarKirby Magojiro added a comment - 22/Dec/07 01:09 PM
I've changed all fixed internally issues to Resolved: Fix pending.