How many bytes are needed for a full sketch of progressive JPEG?

I am trying to create a bootloader that downloads progressive files in two steps:

  • Download the minimum number of bytes to create a thumbnail (0-10%)
  • Download the remaining bytes for the thumbnail. (11% -100%)

I want to do this in order to have thumbnails available earlier, without having to download a separate thumbnail. Taking an image (3426398 bytes) that was created using jpegtran -copy all -progressive -outfile progressive.jpg original.jpg , and then taking the first 350,000 bytes with dd if=progressive.jpg of=thumb.jpg bs=1 count=350000 , I got a thumbnail that works.

Is there a way to find out how many bytes I have to transfer in order to get an image where all lines are available? So, only image quality degradation?

+4
source share
1 answer

A progressive JPEG image consists of the Scan series. Each scan provides more detailed information for each MCU (more A / C ratios). The first scan usually represents only the DC values ​​for each MCU. This turns out to be the ideal amount of information to get a 1/8 thumbnail image.

In a JPEG file, each scan begins with an SF (start of scan) FFDA marker. To find out how much data is required to complete the first scan, just search the file data to start the second scan (second FFDA marker) and you have the answer. Due to the rules of byte token 2, the byte sequence of FF DA cannot be anything but an SOS token. The compressed data that should encode the FF value, followed by the DA, must be encoded as FF 00 DA.

+5
source

Source: https://habr.com/ru/post/1235277/


All Articles