# Problem with 8888 to pvr

**URL:** <https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796>\
**Category:** PowerVR Insider\
**Tags:** pvrtextool\
**Created:** [May 27, 2013, 6:15pm UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796 "2013-05-27T18:15:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ninnndza](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@ninnndza](https://forums.imgtec.com/u/ninnndza)\
**Post date:** [May 27, 2013, 6:15pm UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/1 "2013-05-27T18:15:41Z")

</div>

I’m trying convert bmp image to pvr.  
  
Using VS 2010  
  
My code:  
  
  
  
//data is unsigned char\*  
  
PVRTextureHeaderV3 pvrHeader;  
  
  
  
pvrHeader.u32Version = PVRTEX3\_IDENT;  
  
pvrHeader.u32Flags = true ? PVRTEX3\_PREMULTIPLIED : 0;  
  
pvrHeader.u64PixelFormat = PVRStandard8PixelType.PixelTypeID;  
  
pvrHeader.u32ColourSpace = ePVRTCSpacelRGB;  
  
pvrHeader.u32ChannelType = ePVRTVarTypeUnsignedByteNorm;  
  
pvrHeader.u32Height = height; //512  
  
pvrHeader.u32Width = width; //512  
  
pvrHeader.u32Depth = 1;  
  
pvrHeader.u32NumSurfaces = 1;  
  
pvrHeader.u32NumFaces = 1;  
  
pvrHeader.u32MIPMapCount = 1;  
  
pvrHeader.u32MetaDataSize = 0;  
  
  
  
CPVRTexture sTexture( pvrHeader, data ); [crashes here]  
  
  
  
  
  
  
  
When I pass NULL as data, everything is fine but I don’t deliver data to structure (obvious white pvr).  
  
  
  
I’ve searched forum and found function PVRU.CompressPVR which is depreciated. Can provide sample code with png/bmp -\> pvr?

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forums.imgtec.com/u/tobias)\
**Post date:** [May 28, 2013, 7:27am UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/2 "2013-05-28T07:27:29Z")

</div>

Hi Ninnndza,  
  
  
  
The code you’ve written is correct, so I can think of two reasons why your code is crashing there:

1. You’ve not got enough data in your buffer, this is possible if the data wasn’t already in an rgba8888 uncompressed format. However I’m going to guess that the more likely scenario is:  
2. You’re using the DLL version of PVRTexLib and haven’t declared “\_WINDLL\_IMPORT” in your preprocessor. Due to annoying weirdnesses with windows, this needs to be declared to properly import the functions and classes, otherwise it will almost always crash when allocating data.  
  
  
  
Hopefully it’s the second issue, and you should be able to fix it quickly. Let me know if this doesn’t solve it for you.  
  
  
  
Regards,  
  
Tobias

---

<div class="post-metadata">

**Author:** ![ninnndza](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@ninnndza](https://forums.imgtec.com/u/ninnndza)\
**Post date:** [May 29, 2013, 6:27pm UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/3 "2013-05-29T18:27:56Z")

</div>

I seems like I’m not converting bitmap to 8888 (pink texture with addons 🙂 ) , so I’ts nothin with dll preprocessor (declarated on top).

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forums.imgtec.com/u/tobias)\
**Post date:** [May 30, 2013, 7:18am UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/4 "2013-05-30T07:18:45Z")

</div>

Aww, I guessed wrong :(! So have you got it working now?

---

<div class="post-metadata">

**Author:** ![ninnndza](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@ninnndza](https://forums.imgtec.com/u/ninnndza)\
**Post date:** [May 30, 2013, 12:30pm UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/5 "2013-05-30T12:30:48Z")

</div>

I’m using FreeImage as bmp loader:  
  
FIBITMAP \*src = GenericLoader(“ighter.bmp”, 0);  
  
if (src == NULL) {  
  
std::cerr \<\< “Error: Invalid input image type.” \<\< std::endl;  
  
exit\_message(EXIT\_FAILURE);  
  
}  
  
  
  
// Allocate a raw buffer  
  
int width = FreeImage\_GetWidth(src);  
  
int height = FreeImage\_GetHeight(src);  
  
int scan\_width = FreeImage\_GetPitch(src);  
  
BYTE _bits = (BYTE_)malloc(height \* scan\_width);  
  
  
  
// convert the bitmap to raw bits (top-left pixel first)  
  
FreeImage\_ConvertToRawBits(bits,  
  
src,  
  
scan\_width,  
  
24, //when set 32 image is filled with constant color (grey?)  
  
FI\_RGBA\_RED\_MASK,  
  
FI\_RGBA\_GREEN\_MASK,  
  
FI\_RGBA\_BLUE\_MASK,  
  
true);  
  
  
  
  
  
FreeImage\_Unload(src);  
  
  
  
//input data  
  
data = reinterpret\_cast(bits) ;  
  
  
  
  
  
Instead of color texture, I’m getting B&W pvr.

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forums.imgtec.com/u/tobias)\
**Post date:** [May 30, 2013, 12:38pm UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/6 "2013-05-30T12:38:35Z")

</div>

Hmm, assuming your pvr texture code is the same, I’d suspect a problem with the way FreeImage is loading it, but I can’t be sure (looking at the freeimage documentation it seems you’ve done the right thing…) I would suggest dumping the raw bits to a file and loading it with something like GIMP to verify what it looks like. PVRTexToolGUI also has a raw data loader which you could use to achieve the same.

---

<div class="post-metadata">

**Author:** ![ninnndza](https://avatars.discourse-cdn.com/v4/letter/n/f1d935/32.png) [@ninnndza](https://forums.imgtec.com/u/ninnndza)\
**Post date:** [May 30, 2013, 3:35pm UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/7 "2013-05-30T15:35:51Z")

</div>

I’ve started looking at raw bits and everything was right except alpha which was 0 -setting mask 0xff000000 for each bit solved problem (BGR to RGB conversion for bmp also made by other mask).  
  
  
  
Thank you 🙂

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forums.imgtec.com/u/tobias)\
**Post date:** [May 31, 2013, 6:37am UTC](https://forums.imgtec.com/t/problem-with-8888-to-pvr/1796/8 "2013-05-31T06:37:46Z")

</div>

Fantastic! Glad you’ve got that working now 🙂
