Intel® Integrated Performance Primitives
Community support and discussions relating to developing high-performance vision, signal, security, and storage applications.

Jpeg2000 to DXT5n

ericfriedman
Beginner
137 Views
Hello,
I have a normal map saved as a JP2. Using the UIC codecs and the CIPPImage class, I want to load in the JP2, then convert it to a DXT5, but with the source red channel placed in the destination alpha channel.
Here is my code:
CStdFileInput inStream;
inStream.Open("test.jp2")
PARAMS_JPEG2K params;
ZeroMemory(&params, sizeof(PARAMS_JPEG2K));
params.nthreads = 2;
CIppImage image;
ReadImageJPEG2000(inStream, params,image);
CStdFileOutput outStream;
ioutStream.Open("test.dds")
CIppImage alphaImage;
image.ToRGBA32(alphaImage);
int dxt5Order[4] = { 3, 1, 2, 0 };
alphaImage.SwapChannels(dxt5Order);
PARAMS_DDS ddsParams;
ZeroMemory(&ddsParams, sizeof(ddsParams));
ddsParams.ac = 1;
ddsParams.nthreads = 2;
ddsParams.fmt = DDS_DXT5;
SaveImageDDS(alphaImage, ddsParams, outStream);
The resulting image is a gray-scale texture and a blank alpha channel. I get the same result whether or not I call SwapChannels on alphaImage, which leads me to believe that SaveImageDDS isn't handling something properly with 4 channel textures, or toRGBA32 is bugged. That or I'm doing something wrong, which is more likely :)
Does anyone see something is wrong w/ my approach?
Thank you,
Eric
0 Kudos
1 Solution
Vladimir_Dudnik
Employee
137 Views
Hi Eric,

I think you should specify ddsParams.ac = 0 (to not add Alpha channel, as you already converted image to 4-channels). You may also need to specify ddsParams.ycocg = 0 - to prevent convertion to YCoCg color space before encoding to DXT5 format.

Regards,
Vladimir

View solution in original post

2 Replies
Vladimir_Dudnik
Employee
138 Views
Hi Eric,

I think you should specify ddsParams.ac = 0 (to not add Alpha channel, as you already converted image to 4-channels). You may also need to specify ddsParams.ycocg = 0 - to prevent convertion to YCoCg color space before encoding to DXT5 format.

Regards,
Vladimir
ericfriedman
Beginner
137 Views
Thanks Vladimir. I was confused as to what the .ac meant. Setting it to zero fixed the issue.
Eric
Reply