How to access the pixel value after decompression of dds files

Feb 25, 2013 at 3:13 PM
I have loaded a dds file using LoadFromDDSFile and then decompressed it to

DXGI_FORMAT_R8G8B8A8_UNORM now I want to save this bitmap and also access the pixel

each pixel value. my file is 6464 pixels so after decompression I should expect to have 4096 pixel

values. Please help me how to save this format in a bitmap file and also how to access its pixel

values.

This is how I did so far after loading the dds file into const Image
img:

ScratchImage bmp;
hr = Decompress(*img, DXGI_FORMAT_R8G8B8A8_UNORM, bmp);
if(FAILED(hr))
    cout << "Decompression to bmp (R8G8B8 failed)" << endl;
Coordinator
Feb 25, 2013 at 6:20 PM
Edited Feb 25, 2013 at 6:24 PM
BC decompression does not change the number of pixels in the image. The only thing that changes is the 'stride' and number of 'rows' in the image, which is all handled by calling the utility function ComputePitch.

If you want examples of processing data in a ScratchImage, DirectXTex itself is a pretty good sample. Take a look at the PremultiplyAlpha source code as an example of an operation that is applied to each pixel in an image.

If you are always using R8G8B8A8_UNORM as your format, you can of course perform the operation in the original
RGBA32 format rather than using the facilities to convert formats to a RGBAF32 format as an intermediate solution.

You can also simplify the operation even more if you know it is always a 1D or 2D dimension structure, but if you want a general solution it needs to support 1D, 2D, 1DArray, 2DArray/Cubemap, and 3D. There's a lot of examples of working with Image structures in DirectXTexImage.cpp
Feb 25, 2013 at 7:32 PM
Where can I find this PremultiplyAlpha source code?

after the code above I put the following code but can you tell me what is missing to see the pixels?
XMVECTOR temp[16];
const uint8_t *BMPpSrc = BMPImg->pixels;
const size_t rowPitch = BMPImg->rowPitch;
int i = 0;
for( size_t h=0; h < BMPImg->height; h += 4 )
{
    const uint8_t *BMPsptr = BMPpSrc;

    for( size_t count = 0; count < rowPitch; count += sbpp*4 )
    {
        temp[count] = BMPpSrc[count];
        cout << i << ") " <<temp[count] << endl;
        i++;
        BMPsptr += sbpp*4;
        //dptr += 8;
    }

    BMPpSrc += rowPitch*4;
    //pDest += bmp.rowPitch;
}
Coordinator
Feb 25, 2013 at 10:29 PM
The source for DirectXTex is included in the package, so just open the project and search away.

The first loop is only valid for actually Block Compressed data. In non-BC format content, you shouldn't be skipping scanlines like that. There are exactly as many rows as the height in this case.

The same is true of the second loop. For non-BC format content you should not be skipping every 4 pixels across.
Feb 26, 2013 at 10:51 AM
Edited Feb 26, 2013 at 11:47 AM
Ok, but what in the second loop should I have to print out the pixel values one by one. I mean, what is the array that has all the pixels so I can print them out using these two nested loops?



for( size_t h=0; h < BMPImg->height; h++ )
{
const uint8_t *BMPsptr = BMPpSrc;

for( size_t count = 0; count < rowPitch; count++ )
{

    cout << what do I need here to print out the pixel values? << endl;
    i++;
    BMPsptr += sbpp;
    //dptr += 8;
}

BMPpSrc += rowPitch;
}
Mar 4, 2013 at 9:54 AM
Why in the BC.cpp, inside EncodeBC1 function (with the assumption that flag is 0 and the format is DXGI_FORMAT_BC1_UNORM) Color is multiplied by g_Luminance?

I am asking because I loaded a dds file (64*64 and DXGI_FORMAT_BC1_UNORM) and then converted it to DXGI_FORMAT_R8G8B8A8_UNORM then converted it back to

DXGI_FORMAT_BC1_UNORM and I am debugging the code to see why some of the pixel values are changing and just before the color is multiplied by g_Luminance, the

pixel values are calculated correctly respect to the original dds file, but when multiplied by g_Luminance then it changes the pixel values which in the end it is no more

like the original values. Can you please explain about the algorithm of EncodeBC1 and why the Color is multiplied by g_Luminance? is there any documentation about

EncodeBC1? Because after that there is Dir and Diff and some more variables which I don't understand their use and what are they?
Coordinator
Mar 4, 2013 at 6:59 PM
Edited Mar 4, 2013 at 6:59 PM
The DXT1-5 algorithm from D3DX has long used that perceptual weighting factor as part of the standard algorithm. With DirectXTex, you can use BC_FLAGS_UNIFORM to not use this (which is the same as using a weighting of 1,1,1,1). This option was included in the Xbox 360 XGRAPHICS library, but not in D3DX.

Generally, with color data you will get better visual results using the perceptual weighting. The main use for BC_FLAGS_UNIFORM is for textures that aren't actually color data...
Mar 8, 2013 at 10:20 PM
Can you give me a reference for the function OptimizeRGB? or some links to algorithm of this function. Because I would like to know for example what are pC3, pC4, pD3, pD4, AB (I think AB is the diagonal length of RGB cubic model right? ), fAB (and why we calculate fAB?) , DIR, Mid and so on.