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

  • SEARCH
  • Home
  • 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 9172667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:24:16+00:00 2026-06-17T16:24:16+00:00

Short question: Does anyone know why HQ2x is producing corrupt PNGs or knows of

  • 0

Short question:

Does anyone know why HQ2x is producing corrupt PNGs or knows of another implementation that supports transparency that I can try.

Longer question:

I’m attempting to use HQ2x (with alpha support) to produce upscaled images.

The problem however is that the following code produces corrupt PNGs.

UIImage *image = [UIImage imageNamed:@"testIcon.png"];
NSMutableData *data = [NSMutableData dataWithData:UIImagePNGRepresentation(image)];

uint32_t *imageData = (uint32_t *) malloc([data length]);
uint32_t *newImageData = (uint32_t *) malloc(image.size.width * 4 * image.size.height * 4 * sizeof(uint32_t));

[data getBytes:imageData];

hqxInit();
hq2x_32(imageData, newImageData, image.size.width, image.size.height);


FILE *file;
file = fopen("/Users/iPhone/Desktop/out.png","w");
fwrite(newImageData, image.size.width * 4 * image.size.height * 4 * sizeof(uint32_t), 1, file);
fclose(file);

Examining the first few bytes of the output, I can deduce that something has gone wrong as there are two intermingled PNG Magic Numbers (89 50 4e 47 0d 0a 1a 0a):

89 50 4E 47 89 50 4E 47 0D 0A 1A 0A 0D 0A 1A 0A

The input image is not corrupted.

This is an objective-c program, but the important bits are in pure c.

  • 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-06-17T16:24:17+00:00Added an answer on June 17, 2026 at 4:24 pm

    Parts of this answer were discussed in chat. (Transcript)

    The blob you write to /Users/iPhone/Desktop/out.png is raw pixel data. You have to encode it as PNG because hq2x_32 doesn’t do it automatically.

    If you’re not decoding your PNG before you pass it to hq2x_32 then your input and subsequently your output is wrong.

    Take a look at hqx.c, you can see that the data passed to hq2x_32 is first decoded and then the output is manually encoded. Both transformations are handled using DevIL.

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

Sidebar

Related Questions

Does anyone know how to retrieve a short sentence from within the main string?
Question: Does anyone know how to change the current directory of an already running
Short question: Is the parent of an entity group included in that entity group
Short question: I'm trying to make that in a given page (uses tabs) back
Does anyone know of any platforms supported by the C standard, for which there
This is a long shot, but does anyone know of an algorithm for estimating
Does anyone know how to set the date format for the Team - History
Short question, is the following ok: struct X { A& x; A y; X()
Short question: Is it possible to detect window.open() in a UIWebView using the UIWebViewDelegate
Short Question: Can I specify wildcards for custom console folding? If so, what is

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.