Transcode was not successful

Following my initial and first problem with PVRTexTool here: PVRTexLib in C# (with C++ tests)
I come across another problem separate to the one linked above.

I try to transcode an image from RGBA8888 to R8. This has no special meaning and is meant to serve as an example for me to learn how I set up the transcoder options.

I currently set up my options like this:

PVRTexLib_TranscoderOptions* CreateOptions()
{
    auto options = new PVRTexLib_TranscoderOptions();

    options->sizeofStruct = 0x2c;
    options->doDither = false;
    options->colourspace = PVRTexLibColourSpace::PVRTLCS_Linear;
    options->maxRange = 1;
    options->pixelFormat = PVRTexLibPixelFormat::R8;
    options->quality = PVRTexLibCompressorQuality::PVRTLCQ_PVRTCHigh;

    options->channelType[0] = { PVRTexLibVariableType::PVRTLVT_UnsignedByte };
    options->channelType[1] = { PVRTexLibVariableType::PVRTLVT_UnsignedByte };
    options->channelType[2] = { PVRTexLibVariableType::PVRTLVT_UnsignedByte };
    options->channelType[3] = { PVRTexLibVariableType::PVRTLVT_UnsignedByte };

    return options;
}

The PixelFormat R8 is setup as the value 0x0000000861626772, which defines the rgba encoding, where only the R channel is defined with 8 bits. This could already be a potential problem in why the Transcode may fail.

I would like someone to tell me if the options are correctly set up like this on first glance. I will reply with my full sample application code.

int main()
{
    auto data = new char[16*4];
    for (int i = 0; i < 16*4; i++)
        data[i] = 0;

    auto attribs = CreateParams();
    auto header = PVRTexLib_CreateTextureHeader(attribs);
    auto texture = PVRTexLib_CreateTexture(header, data);

    // Transcode texture
    auto options = CreateOptions();    // See CreateOptions method in my initial post
    auto successful = PVRTexLib_TranscodeTexture(texture, *options);
}

PVRHeader_CreateParams* CreateParams()
{
    PVRHeader_CreateParams* params = new PVRHeader_CreateParams();

    params->width = 4;
    params->height = 4;
    params->depth = 1;

    // Setting to zero means library will not use and/or print height/width information
    params->numMipMaps = 1;

    // Additionally to numMipMaps, if any of the number values is 0, PVRTexLib_GetTextureDataPtr will return 0
    params->numArrayMembers = 1;
    params->numFaces = 1;
    params->pixelFormat = PVRTexLibPixelFormat::RGBA8888;
    params->colourSpace = PVRTexLibColourSpace::PVRTLCS_Linear;
    params->channelType = PVRTexLibVariableType::PVRTLVT_UnsignedByte;
    params->preMultiplied = false;

    return params;
}

R8 is set up as 0x0000000861626772.
RGBA8888 is set up as 0x0808080861626772.

Hi onepiecefreak,

Thanks for your interest in PVRTexTool. I’ll forward your questions to the Tools Team and come back to you shortly.

Best regards,
Alejandro

Hi onepiecefreak,

The Tools Team has reviewed your issue.

The call to PVRTexLib_TranscodeTexture is failing due to passing the pixel format with a named channel (R/G/B/A) with a bit width of 0, which is not supported.

You have two options here:
1. Use the correct encoding for R8 which is 0x800000072.
2. Use the macro PVRTGENPIXELID defined in PVRTexLibDefines.h to create uncompressed pixel format IDs in a more straightforward way.

Best regards,
Alejandro

Oh, interesting. I thought I had to always give all color components and then just set their bit depth to zero, if they are not needed.

Thanks for the tip with the PVRTGENPIXELID macro. I will try that out and report back.

Yes, that worked. Thank you.

Hi onepiecefreak,

Glad it worked, please come back if you have more questions.

Best regards,
Alejandro