User avatar
Alex_Landherr
Posts: 222
Joined: Mon May 18, 2020 3:14 pm
Location: Sweden
Contact: Twitter

Bit depth of JPEG and PNG Images From PiCam v2.1?

Wed Jul 21, 2021 7:36 pm

I am wondering what the bit depth for the Pi Camera V2.1 is when taking JPEG and PNG images? This would be useful for calculating the maximum number of images my time lapse program can capture and store on a high capacity USB flash drive. All I can find in the documentation is this:
10-bit RAW RGB data - Yes - format conversions available via GPU
Is this the answer to my question?
Helpful answers are appreciated.
I usually respond to Tweets directed at me.
JWST is the Sagrada Família of spacecrafts.

3D Printer: Original Prusa Mini+

OS:
  • Raspberry Pi OS
  • Windows 10
Programming Languages:
  1. Python
  2. Java

drgeoff
Posts: 12180
Joined: Wed Jan 25, 2012 6:39 pm

Re: Bit depth of JPEG and PNG Images From PiCam v2.1?

Wed Jul 21, 2021 7:40 pm

Bit depth of original image (from any source, not just a PiCam) has little correlation with the file size of the JPEG or PNG compressed version.
Quis custodiet ipsos custodes?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11638
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Bit depth of JPEG and PNG Images From PiCam v2.1?

Thu Jul 22, 2021 8:02 am

Whilst JPEG can support greater bit depths, the JPEG hardware block on the Pi only supports 8bit/component (YUV only).

Whilst the PNG spec can support 1, 2, 4, 8, or 16 bits per component, the Pi encoder only handle 8bpc (24bpp). Note that PNG is an RGB format, so there is a format conversion involved from the YUV images that the camera stack produces.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
Alex_Landherr
Posts: 222
Joined: Mon May 18, 2020 3:14 pm
Location: Sweden
Contact: Twitter

Re: Bit depth of JPEG and PNG Images From PiCam v2.1?

Fri Jul 23, 2021 10:52 am

6by9 wrote:
Thu Jul 22, 2021 8:02 am
Whilst JPEG can support greater bit depths, the JPEG hardware block on the Pi only supports 8bit/component (YUV only).

Whilst the PNG spec can support 1, 2, 4, 8, or 16 bits per component, the Pi encoder only handle 8bpc (24bpp). Note that PNG is an RGB format, so there is a format conversion involved from the YUV images that the camera stack produces.
A follow-up question, so to calculate the theoretical maximum PNG file size would go like this?:
Step 1: Multiply the detectors number of horizontal pixels by the number of vertical pixels to get the total number of pixels of the detector.

Step 2: Multiply total number of pixels by the bit depth of the detector (16 bit, 14 bit etc.) to get the total number of bits of data.

Step 3: Dividing the total number of bits by 8 equals the file size in bytes.

Step 4: Divide the number of bytes by 1024 to get the file size in kilobytes. Divide by 1024 again and get the file size in megabytes.
From this page:
https://4nsi.com/faq/how-do-i-calculate ... ital-image
Helpful answers are appreciated.
I usually respond to Tweets directed at me.
JWST is the Sagrada Família of spacecrafts.

3D Printer: Original Prusa Mini+

OS:
  • Raspberry Pi OS
  • Windows 10
Programming Languages:
  1. Python
  2. Java

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 29346
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bit depth of JPEG and PNG Images From PiCam v2.1?

Fri Jul 23, 2021 10:53 am

That gives you the size of the data portion of the file, but PNG has a header, which may be a set numbers of bytes, you will need to look that up and add it to the total.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Working in the Applications Team.

User avatar
Alex_Landherr
Posts: 222
Joined: Mon May 18, 2020 3:14 pm
Location: Sweden
Contact: Twitter

Re: Bit depth of JPEG and PNG Images From PiCam v2.1?

Sat Jul 24, 2021 8:35 pm

jamesh wrote:
Fri Jul 23, 2021 10:53 am
That gives you the size of the data portion of the file, but PNG has a header, which may be a set numbers of bytes, you will need to look that up and add it to the total.
Where could I find that info? A simple web search?
Helpful answers are appreciated.
I usually respond to Tweets directed at me.
JWST is the Sagrada Família of spacecrafts.

3D Printer: Original Prusa Mini+

OS:
  • Raspberry Pi OS
  • Windows 10
Programming Languages:
  1. Python
  2. Java

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11638
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Bit depth of JPEG and PNG Images From PiCam v2.1?

Sat Jul 24, 2021 8:51 pm

That formula gives you the uncompressed size for the image. width * height * bpp / 8 (bits per byte), and optionally convert to kB or MB.
There are some theoretical images that will result in no compression through any codec, but reality is that they are fairly artificial.

Assuming no compression would do for a worst case estimate. JPEG does add a thumbnail and metadata, which is a max of 64kB. PNG is a fairly small header (<1kb IIRC).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Camera board”