switch png to pvr with PVRTexTool in c++

Hi,
I’m using PVRTexTool in C++ on macosx
with ePVRTPF_PVRTCI_4bpp_RGBA, I got the PVR with black boundary
with ePVRTPF_PVRTCII_4bpp, I got the PVR with Alpha from 0 to 17
my code is as follows:
[scode lang="{c++}"]{std::string testPath = “/Users/xiao/Documents/perforce/main_1.0_mac_2/PvZ2//tmpDist/all/atlases/sour”;
ImageLib::Image* image = ImageLib::GetImage(testPath);

uint32* sourceBits = image->mBits;
pvrtexture::PixelType powerVRLibraryTargetFormat(ePVRTPF_PVRTCII_4bpp);
pvrtexture::CPVRTextureHeader pvrTextureHeader(pvrtexture::PixelType('b','g','r','a',8,8,8,8).PixelTypeID,
                                               269,
                                               512,
                                               1,
                                               1,
                                               1,
                                               1,
                                               ePVRTCSpacelRGB,
                                               ePVRTVarTypeUnsignedByteNorm,
                                               false);
pvrtexture::CPVRTexture texture(pvrTextureHeader, sourceBits);

bool success = Transcode(texture, powerVRLibraryTargetFormat, ePVRTVarTypeUnsignedByteNorm, ePVRTCSpacelRGB, pvrtexture::ePVRTCBest);  // for test
std::string testPVRImageOutput = testPath + ".pvr";

success = texture.saveFile(testPVRImageOutput.c_str());}[/scode]

I’m looking forward to your help, Thank you!

Hi xiao,

Which version of PVRTexTool are you using to get these two images? How are you displaying the results? Are you viewing them in PVRTexToolGUI?

PVRTC1 textures have to be powers of two. 269x512 will therefore produce 512x512 textures.

Hi,
Thank you for you help. my version is 2016_R 1.2 and I viewed them in both PVRTexToolGUI and IOS devices.
I know that PVRTC1 textures have to be powers of two, that’s why I’m trying PVRTC2 which supports NPOT.
But neither of them made a nice texture. Please review my code in function Transcode, is any param wrong?
Thank you again

Thanks for the information.

There is nothing wrong with your code. I’ve tested it with the 2016 r1.2 release of PVRTexTool on both Windows and OSX but cannot reproduce your texture. I end up with the attached.

What platform are you targeting anyway? PVRTC2 is not exposed on IOS anyway, so sticking with PVRTC1 may be a necessity.

Thanks for your help. I produced the texture by c++ with PVRTexTool SDK. When using PVRTexTool GUI ,I can produce a texture as well as yours, but there are so many PNGs and I need to switch them automatically.

PVRTC2 is not exposed on IOS? Where can I see this message?
https://www.imgcommunity.local/forums/topic/which-devices-support-pvrtc2/
what I see is “All PowerVR Series 5XT and Series6 GPUs are capable of fully supporting PVRTC2 texture decompression, including SGX543,SGX544 and SGX554, G6200 and G6400.”

Meanwhile, is there anything I can do for the ePVRTPF_PVRTCI_4bpp_RGBA texture to make it better?
Thank you very much.

Hi xiao,

Are you using the 2016 r1.2 version of PVRTexLib to match the GUI? Can you make sure that you aren’t using an older version of the library?

That forum post is correct. Those GPUs support PVRTC 2, but the extension isn’t exposed on IOS.

Regarding PVRTC 1, I cannot reproduce your compressed image either. Just compressing it at highest quality I get a far better image than you’re getting. To get the best possible image, call the Bleed function before Transcode:

[scode lang=“C++”]bool success = Bleed(texture);
success &= Transcode(texture, powerVRLibraryTargetFormat, ePVRTVarTypeUnsignedByteNorm, ePVRTCSpacelRGB, pvrtexture::ePVRTCBest);[/scode]

This spills colour (RGB) into fully transparent areas to aid the compressor, resulting in a much better image. I’ve attached the result.

I hope this helps.

Hi,
It’s so amazing that I get a far better texture than I was geting. The function Bleed works.Thanks for your patience.

By the way, The function Bleed return false when I pass a texture with BGRA8888 format, do you know the reason?

The texture with RGBA8888 format works well.

Thank you very much, you helped me a lot

The Bleed function only works with RGBA, and not BGRA or any other channel order. You can easily convert the texture from whatever it is to RGBA8888 before calling the Bleed function by doing the following:

[scode lang=“C++”]bool success = Transcode(texture, pvrtexture::PixelType(‘r’, ‘g’, ‘b’, ‘a’, 8, 8, 8, 8).PixelTypeID, ePVRTVarTypeUnsignedByteNorm, ePVRTCSpacelRGB);
success &= Bleed(texture);
success &= Transcode(texture, powerVRLibraryTargetFormat, ePVRTVarTypeUnsignedByteNorm, ePVRTCSpacelRGB, pvrtexture::ePVRTCBest);[/scode]

Thank you

I’m afraid so. Despite it being available in hardware (in some form) for around a decade it’s just not accessible. It confuses me too.