Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 900393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:22:49+00:00 2026-05-15T15:22:49+00:00

How do I read the image color information for each pixel of PVRTC image?

  • 0

How do I read the image color information for each pixel of PVRTC image?

Here is my code extracting the integer arrays

    NSData *data = [[NSData alloc] initWithContentsOfFile:path];

 NSMutableArray *_imageData = [[NSMutableArray alloc] initWithCapacity:10];

 BOOL success = FALSE;
 PVRTexHeader *header = NULL;
 uint32_t flags, pvrTag;
 uint32_t dataLength = 0, dataOffset = 0, dataSize = 0;
 uint32_t blockSize = 0, widthBlocks = 0, heightBlocks = 0;
 uint32_t width = 0, height = 0, bpp = 4;
 uint8_t *bytes = NULL;
 uint32_t formatFlags;

 header = (PVRTexHeader *)[data bytes];

 pvrTag = CFSwapInt32LittleToHost(header->pvrTag);

 if (gPVRTexIdentifier[0] != ((pvrTag >>  0) & 0xff) ||
  gPVRTexIdentifier[1] != ((pvrTag >>  8) & 0xff) ||
  gPVRTexIdentifier[2] != ((pvrTag >> 16) & 0xff) ||
  gPVRTexIdentifier[3] != ((pvrTag >> 24) & 0xff))
 {
  return FALSE;
 }

 flags = CFSwapInt32LittleToHost(header->flags);
 formatFlags = flags & PVR_TEXTURE_FLAG_TYPE_MASK;

 if (formatFlags == kPVRTextureFlagTypePVRTC_4 || formatFlags == kPVRTextureFlagTypePVRTC_2)
 {
  [_imageData removeAllObjects];

  if (formatFlags == kPVRTextureFlagTypePVRTC_4)
   _internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  else if (formatFlags == kPVRTextureFlagTypePVRTC_2)
   _internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;


  _width = width = CFSwapInt32LittleToHost(header->width);
  _height = height = CFSwapInt32LittleToHost(header->height);

  if (CFSwapInt32LittleToHost(header->bitmaskAlpha))
   _hasAlpha = TRUE;
  else
   _hasAlpha = FALSE;

  dataLength = CFSwapInt32LittleToHost(header->dataLength);

  bytes = ((uint8_t *)[data bytes]) + sizeof(PVRTexHeader);

  // Calculate the data size for each texture level and respect the minimum number of blocks
  while (dataOffset < dataLength)
  {
   if (formatFlags == kPVRTextureFlagTypePVRTC_4)
   {
    blockSize = 4 * 4; // Pixel by pixel block size for 4bpp
    widthBlocks = width / 4;
    heightBlocks = height / 4;
    bpp = 4;
   }
   else
   {
    blockSize = 8 * 4; // Pixel by pixel block size for 2bpp
    widthBlocks = width / 8;
    heightBlocks = height / 4;
    bpp = 2;
   }

   // Clamp to minimum number of blocks
   if (widthBlocks < 2)
    widthBlocks = 2;
   if (heightBlocks < 2)
    heightBlocks = 2;

   dataSize = widthBlocks * heightBlocks * ((blockSize  * bpp) / 8);

   [_imageData addObject:[NSData dataWithBytes:bytes+dataOffset length:dataSize]];

                   for (int i=0; i < mipmapCount; i++)
                    {

              NSLog(@"width:%d, height:%d",width,height);

              data = [[NSData alloc] initWithData:[_imageData objectAtIndex:i]];
              NSLog(@"data length:%d",[data length]);

//extracted 20 sample data, but all u could see are large integer number
for(int i = 0; i < 20; i++){
NSLog(@”data[%d]:%d”,i,data[i]);
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T15:22:50+00:00Added an answer on May 15, 2026 at 3:22 pm

    PVRTC is a 4×4 (or 8×4) texel, block-based compression system that takes into account surrounding blocks to represent two low frequency images with which higher frequency modulation data is combined in order to produce the actual texel output. A better explanation is available here:

    http://web.onetel.net.uk/~simonnihal/assorted3d/fenney03texcomp.pdf

    So the values you’re extracting are actually parts of the encoded blocks and these need to be decoded correctly in order to get sensible values.

    There are two ways to get to the colour information: decode/decompress the PVR texture information using a software decompressor or render the texture using a POWERVR graphics core and then read the result back. I’ll only discuss the first option here.

    It’s rather tricky to assemble a decompressor from only the information there, but fortunately there’s C++ decompression source code in the POWERVR SDK which you can get here – download one of the iPhone SDKs for instance:

    http://www.imgtec.com/powervr/insider/powervr-sdk.asp

    It’s in the Tools/PVRTDecompress.cpp file.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the following code of java to read image data on
I read here that when sending an image for print it can have multiple
I want to read the RGB values for each pixel from a .bmp file,
How can I use JavaScript or jQuery to read the color of a pixel
I am trying out a sample code that converts a color image to grey
How can I read the colors of an image with python using google app
How do I read an image in C so that I can have direct
So I'm able to read an image file successfully, and pass it back to
Is there a good way to read RAW image files (especially Canon CR2 and
I am using WIC (Windows Imaging Component) in my WPF application to read/write image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.