# switch png to pvr with PVRTexTool in c++

**URL:** <https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485>\
**Category:** PowerVR Insider\
**Tags:** pvrtextool\
**Created:** [August 22, 2016, 3:12am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485 "2016-08-22T03:12:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaoyl](https://avatars.discourse-cdn.com/v4/letter/x/5fc32e/32.png) [@xiaoyl](https://forums.imgtec.com/u/xiaoyl)\
**Post date:** [August 22, 2016, 3:12am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/1 "2016-08-22T03:12:57Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Lawrence](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@Lawrence](https://forums.imgtec.com/u/Lawrence)\
**Post date:** [August 22, 2016, 10:28am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/2 "2016-08-22T10:28:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xiaoyl](https://avatars.discourse-cdn.com/v4/letter/x/5fc32e/32.png) [@xiaoyl](https://forums.imgtec.com/u/xiaoyl)\
**Post date:** [August 23, 2016, 12:56am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/3 "2016-08-23T00:56:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lawrence](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@Lawrence](https://forums.imgtec.com/u/Lawrence)\
**Post date:** [August 23, 2016, 10:37am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/4 "2016-08-23T10:37:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xiaoyl](https://avatars.discourse-cdn.com/v4/letter/x/5fc32e/32.png) [@xiaoyl](https://forums.imgtec.com/u/xiaoyl)\
**Post date:** [August 24, 2016, 1:21am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/5 "2016-08-24T01:21:26Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![Lawrence](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@Lawrence](https://forums.imgtec.com/u/Lawrence)\
**Post date:** [August 24, 2016, 9:30am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/6 "2016-08-24T09:30:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xiaoyl](https://avatars.discourse-cdn.com/v4/letter/x/5fc32e/32.png) [@xiaoyl](https://forums.imgtec.com/u/xiaoyl)\
**Post date:** [August 25, 2016, 5:20am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/7 "2016-08-25T05:20:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Lawrence](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@Lawrence](https://forums.imgtec.com/u/Lawrence)\
**Post date:** [August 25, 2016, 12:01pm UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/8 "2016-08-25T12:01:14Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![xiaoyl](https://avatars.discourse-cdn.com/v4/letter/x/5fc32e/32.png) [@xiaoyl](https://forums.imgtec.com/u/xiaoyl)\
**Post date:** [August 26, 2016, 6:49am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/9 "2016-08-26T06:49:55Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![SimonFenney](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/simonfenney/32/257_2.png) [@SimonFenney](https://forums.imgtec.com/u/SimonFenney)\
**Post date:** [September 22, 2016, 8:12am UTC](https://forums.imgtec.com/t/switch-png-to-pvr-with-pvrtextool-in-c/2485/10 "2016-09-22T08:12:29Z")

</div>

> [@](#):
>
> PVRTC2 is not exposed on IOS?

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.
