Problem with 8888 to pvr

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?

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

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

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

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.

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.

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 :slight_smile:

Fantastic! Glad you’ve got that working now :slight_smile: