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 6171843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:17:16+00:00 2026-05-23T23:17:16+00:00

I’m trying to write a JPEG/JFIF encoder and decoder from scratch using C. I

  • 0

I’m trying to write a JPEG/JFIF encoder and decoder from scratch using C. I experimented writing a sample JPEG file, but it seems that I cannot open it using MS paint, Firefox. But I can decode it using JPEGsnoop ( http://www.impulseadventure.com/photo/jpeg-snoop.html?ver=1.5.2) and http://nothings.org/stb_image.c . I think the sample JPEG file complies the JPEG/JFIF standard, I don’t know why applications like MS paint and Firefox cannot open it.

Here is how the sample JPEG looks like:


    SOI
       APP0 segment
       DQT  segment (contains two quantization tables)
       COM  segment
       SOF0 segment
       DHT  segment (contains four Huffman tables)
       SOS  segment
       huffman encoded data
    EOI

The sample JPEG file has three component Y Cb Cr. No subsampling for Cb Cr component.
The two quantization tables are all filled with ones.
The Four huffman tables in DHT segment are all identical, it looks like this


      [0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0]
      [0,1,2, ... , 254]

That means all the codes are 8bits, so huffman encoding does not really compress data.

The huffman encoded data look like this:


       [0x0000(DC) 0x0000(AC)](Y)  
       [0x0000(DC) 0x0000(AC)](Cb) 
       [0x0000(DC) 0x0000(AC)](Cr)  for all (i, j) MCUs except (10, 10)

       the data in (10, 10) MCU: 
       [0x0008(DC) 0x0000(DC), 0x0000(AC)](Y)  
       [0x0000(DC) 0x0000(AC)](Cb) 
       [0x0000(DC) 0x0000(AC)](Cr)

Can anyone tell me what is wrong with this sample JPEG file? thanks.

Here is a link to the sample JPEG file (ha.jpg) http://www.guoxiaoyong.net/ha.jpg

  • 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-23T23:17:18+00:00Added an answer on May 23, 2026 at 11:17 pm

    I had a similar problem years ago with some PNG code (though I didn’t write it from scratch). It turns out my code was more standards compliant than the libraries by Windows, some browsers, etc. They did fine on typical cases, but choked on unusual and contrived images, even if they were completely in line with the standard. A common way to trip them up was to use an odd pixel width for the image. Almost half of my test suite was not viewable with Windows. (This was many versions ago, like Windows 95. The Windows codecs have improved substantially.)

    I ended up building the open source PNG library and using it as my reference implementation. As long as the images that my code produced could be parsed by the reference implementation and vice versa, I called it good. I also checked that my code could display any image that Windows could display. Every time I found a bug, I added the image to my test suite before I fixed it. That was good enough for my project.

    You could do the same. I believe there’s an open source JPEG library that’s widely used as a reference implementation.

    If you really want to figure out why Firefox (or whatever) cannot open your image, you could try starting with an image that does open in Firefox. Incrementally make small changes (e.g, with a hex editor) to make it more like the image that fails. That might help you narrow down what aspect of your image is tripping up the application. Admittedly, some of those steps may be hard to try.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.