# Fractals/Computer graphic techniques/2D/gfile

Graphic files
One can :
* directly create graphic file
* open existing graphic file
* add/read/remove text information to graphic file
Types of graphic files :
* images
** static images
*** SDR file formats: PNG8, JPG,
*** HDR file formats: FITS, JPEG XR, JPEG XT, Logluv TIFF, exr (OpenEXR), RGBE image format, TIFF, PNG64, AV1
** moving images
*** video ( ogg file ) - one needs special program ( viewer) to run it
*** animation ( animated gif file without viewer)
* non-image files
** fomula files
** parameter files
** gradient files
** lightning files
** source code

# Static images

Digital Image Representation
* raster
* vector
Dynamic range of the image
* LDR
** standard LDR
** LDR tone mapped from HDR
** Pseudo-HDR or Exposure Blending or Exposure fusion = Images that have been merged from several exposures without creating an intermediate HDR image and without the use of tone mapping
* HDR
** data = Unprocessed HDR = floating point framebuffer ( in OpenGl GL_RGB16F, GL_RGBA16F, GL_RGB32F, or GL_RGBA32F )
** AV1 Image File Format (AVIF) is an open, royalty-free image file format specification for storing images or image sequences compressed with AV1 in the HEIF container format.[

## Comparison of graphics file formats

* Comparison of graphics file formats in wikipedia
* File_types in commons
* Graphic Formatting Guidelines from National Library of Medicine
* File Formats from National Library of Medicine
* Allowed file types for Fractal Forum: kfr, jpg, jpeg, gif, png, ufr, upr, uxf, ucl, ufm, map, par, m3a, m3f, m3i, m3p, m3c, frag, m3v, zip, ifp, lua, txt
Size and resolution of the image
graphics file formats by precision :
| Format | Supported Bith Depth | Use in Animation and VFX |
| JPEG | 8 bit sRGB | Preview renders. Use 100% quality. Small file size, fast to load in player. Also as background in 3D or plate for Matchmove. Never as intermediate format TARGA (tga) |
| TARGA (tga) | 8 bit sRGB | Very old, but still used in TVC post as intermediate |
| TIFF | 8 and 16 bit sRGB. 32 bit linear float. | Standard if intermediate 16-bit integer is required |
| PNG | 8 and 16 bit sRGB. 8 bit Palette-based | Standard Web format. Supports lossless, therefore useful |
| Cineon (dpx, cin) | 8, 10, 12, 16 sRGB and logarithmic | Used as delivery, intermediate and output format. Standard for telecine and DI grading |
| Photoshop (psd) | 8 and 16 bit sRGB. 32 bit linear float | Photoshop work default. Can be used as intermediate delivering layers to next stage |
| Radiance (hdr) | 32 bit linear float | Standard format to store HDR images used in Image Based Lighting |
| OpenEXR (exr) | 16 bit linear float. 32 bit linear float | The standard for rendering and intermediate in VFX |
| pfm | four byte IEEE 754 single precision floating point extension | PFM is supported by the programs Photoshop,[16] GIMP, and ImageMagick. It is supported by the de facto reference implementation netpbm |

## Raster files

* farbfeld - the simplest RGB image format, quite minimal, though there is not much software supporting it (at least so far)

### AVIF

AV1 Image File Format (AVIF) is an open, royalty-free image file format specification for storing images or image sequences compressed with AV1 in the HEIF container format. It competes with HEIC, which uses the same container format built upon ISOBMFF, but HEVC for compression. Version 1.0.0 of the AVIF specification was finalized in February 2019.
In a number of tests by Netflix in 2020, AVIF showed better compression efficiency than JPEG as well as better detail preservation, fewer blocking artifacts and less color bleeding around hard edges in composites of natural images, text and graphics.
AVIF features
* Multiple color space, including:
** HDR (with PQ (transfer function)Template:Failed verification or Hybrid log–gamma (HLG) transfer functions and BT.2020 color primaries, as part of BT.2100)
** Standard-dynamic-range (SDR) with sRGB / BT.709 / BT.601 or with wide color gamut)
** Color space signaling via Coding-independent code points(CICP) (ITU-T H.273 and ISO/IEC 23091-2) or ICC profiles
* Lossless compression and lossy compression
* 8-, 10-, and 12-bit color depths
* Monochrome (alpha/depth) or multi-components
* 4:2:0, 4:2:2, 4:4:4 chroma subsampling and RGB
* Film grain
* Image sequences/animation

### bmp

* read and write windows BMP files in c by Tony Cook
* A 24-bit v.3 BMP Primer Written by Christophe

### HDR

High dynamic range file formats
* AVIF is a file format developed by Alliance for Open Media. It's an open standard which already enjoys fairly broad support in major web browsers for standard images. AVIF offers numerous advantages over JPG
* PNG has 1, 2, 4, 8 and 16-bit greyscale support and 8 and 16-bit-per-sample (That is, 24 and 48-bit) Truecolour support
** 16-bit integer ProPhotoRGB PNG: Saturated colours
* PFM file - floating point image format for HDR images
* EXR (OpenEXR): 16-bit OpenEXR files can be considered a good colour precision/file size compromise for the general case OpenEXR has support for color depth using: 16-bit floating-point (half), 32-bit floating-point and 32-bit unsigned integer
* TIFF
* RGBE image format or Radiance HDR is an image format invented by Gregory Ward Larson for the Radiance rendering system. It stores pixels as one byte each for RGB (Red, green and blue) values with a one byte shared exponent. Thus it stores four bytes per pixel

### jpeg

* description by Gertbuschmann
* Independent JPEG Group
* JPEGclub.org develops new JPEG features and maintains the Independent JPEG Group's (IJG) software.
* jpeg-faq
* compression-faq
* reference
* the three major tools of the IJG software:
** cjpeg (compress JPEG): compresses the named image file, or the standard input if no file is named, and produces a JPEG/JFIF file on the standard output. The currently supported input file formats are: PPM (PBMPLUS color format), PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit format). (RLE is supported only if the URT library is available.). See also New cjpeg features
** djpeg (decompress JPEG)
** jpegtran (transcode JPEG - lossless):
How to use it :

### pgm

* cprogram_to_read_PGM/PGM.c by Richard Zanibbi in May 1998
* PGMB_IO binary Portable Gray Map (PGM) Files Read and Write Utilities by John Burkardt
* example binary pgm files by John Burkardt

### ppm

* Here are various programs for creating pbm file
* PPM file in c by Mukund
* ppm files in c by JOSEPH THOMAS
* PGM file and C++ program by Ilya Voyager
* Load and draw ppm/pgm files using glut by Lori L Scarlatos
* Underhanded C: The Leaky Redaction by John Meacham
* ppm file in Haskell from University of Melbourne
* PPM in Haskell by Ryan Lothian
* Image processing in Haskell using PPM by Daniel Díaz
The image (expanded): w:Image:tiny6pixel.png
The above image was expanded without interpolation, using the imagemagick command
The P6 format of the same image will store each color component of each pixel with one byte (thus three bytes per pixel) in the order Red, Green then Blue. The file will be smaller but the color information will not be readable by humans:
The PPM format is not compressed and thus requires more space and bandwidth than a compressed format would require. For example, the above 192x128 PNG image has a file size of 187 bytes. When converted to a 192x128 PPM image, the file size is 73848 bytes. The PPM format is generally an intermediate format used for image work before converting to a more efficient format, for example the PNG (Portable Network Graphics) format. The PPM format can be converted to PNG without loss of information.
The PPM format is certainly simple to write from scratch. The following Python code makes the above example image. It can be adapted to making useful images by reading or constructing an array of numerical data, and programming a conversion of the data to color triplets.
Similar code in C :
Assembler code
C code
Static array for one color : code in C for creating pgm text file :
To compile it :
To run it :
Remember that :
* fwrite is used for binary files
* fprintf is used for binary and text files
so if you want to use fwrite then you will get binary file ( even if you will open it in text mode ):
C code : Static 2D array for whole image
C code : virtual 2D array and dynamic 1D array
Here image is a virtual 2D array, but in program we use 1D array.
Relations between indexes :
Here is whole program where we only check ranges of array's indexes without using explicit array :
Lua code for binary B@W PBM file :
Python code

### pfm

PFM (Portable FloatMap) is the unofficial floating point Netpbm image format for HDR images
* PFM_ReadWrite in c++ by Antoine Toisoul Le Cann and version for OpenCV 3
* read and write pfm file, and view it in c++ and opencv by wpfhtl
* PFM Portable FloatMap Image Format by Paul Debevec
* pfm format description from netpbm
* pfm and OpenCV in c++
* c++
** python code by Patrick Chilton
** hdri tools
* imageMagic Check if you have hdri feature : "identify -version" and look for hdri
** display
** create
* gimp ( 2.8 not but 2.10 opens)
** plugin
* darktable
* c
** Unofficial PBM format for HDR images, PFM (Portable Float Map) Written by Paul Bourke
** C library for reading and writing PNM (PBM/PGM/PPM) and PFM images by Nikolaos Kavvadias
Portable Float Map (PFM) format
* Analogous to PPM / PGM / PBM
* binary file
* No compression
* There are no comments in these files
Structure
* text header = 3 lines of text. Each of the three lines of text ends with a 1-byte Unix-style carriage return: 0x0a in hex, not the Windows/DOS CR/LF combination.
** Files begins with type = ASCII characters "PF" or "Pf". PF means it's a color PFM ( 3-channel RGB color imag). Pf means it's a grayscale PFM ( a monochrome single-channel image).
** next line is resolution : 2 integers = [xres] [yres]" indicates the x and y resolutions of the image
** last line is contains sigle floating point value: byte_order.
* data : Three float per pixel ( series of three 4-byte IEEE 754 single precision floating point numbers for each pixel, specified in left to right, bottom to top order )
The text header of a .pfm file takes the following form:
Check file using xxd:
output :

### png

* png file format

### nrrd

* nrrd: description of the format

### raw

Raw file format:
* binary file, it means tha you cannot open it in the text editor but only in the special program or a hex editor
* raster file: file "consist of a sequential listing of pixel (data) values, described row by row, beginning with the top row, working left to right. "
* not compressed
* the file contains no image formatting information so to work with raw files one should know it's structure and size
* File size depends only on the image dimensions and pixel data format
Types
* data ( non color data, need processing)
* static image ( data = color)
** non photo image = image created by computer
** photo = image from digital camera. It need demosaicing
*** DNG
*** HEIC
*** RAW Canon’s CR3
*** Nikon’s NEF
*** Sony’s ARW
* video,like Y4M
Docs
* photo SE questions tagged raw
Sources
* camera
* scaner
* internet
** bettertechtips 6 Websites to Download RAW Images for Free By Aliko Sunawang Update: July 12, 2022
Library for raw editing:
* libraw
* libvips
* ImageMagic rgb raw
* rawtherapee
Example Fractal programs using raw format:
* SuperFractalThing by K I Martin ( Java, cross-platform )
* Kalles Fraktaler by Karl Runmo uses kfb map files
** kf-extras programs for manipulating output from Kalles Fraktaler 2
* Mandel Machine by Botond Kósa
* mandelbulber ( m3p file holds only the parameters, while .m3i holds also the raw image )
Photo editors for raw files
* Photivo
* RawTherapee
** git
** main page
* digikam
* darktable
* dcraw
How to work with raw files ?

### RGBE image format

* RGBE image format or Radiance HDR is an image format invented by Gregory Ward Larson for the Radiance rendering system. It stores pixels as one byte each for RGB (red, green, and blue) values with a one byte shared exponent. Thus it stores four bytes per pixel.

### tiff

* TIFF – Highest Quality Raster Image Format
* channels in TIFF files can be in any IEEE 754 floating-point format too, including the 128 bit one, for 384 bits (48 bytes) per pixel in the RGB, YCbCr and CIE Lab* formats and 512 bits (64 bytes) per pixel in the CMYK format. Same applies to any alpha channel
* supports lossless compression, in which no image data is lost during the compression process. One can use also uncompressed TIFF image.
* supports alpha channel (transparency)
* It supports YCbCr, RGB, CMYK and CIELab color spaces
* Not supported by all web services or programs
* slower to open, larger files
* libtiff - c library and utilities

## vector
### SVG

* creating SVG files
* SVG images with src code

### Dot

Dot files are text files describing graphs in dot language. Example file :
This file can be converted to other formats using command line program dot. For example, to svg :

## Mixed
### Image files with metadata

image files :
* png images with embedded metadata
* ppm images with embedded metadata
* gif – FractInt output with embedded metadata http://www.nahee.com/spanky/www/fractint/fractint.html
* EXR format, OpenEXR, extension .exr

### DICOM

* DICOM

### exr

OpenExr - an open and non-proprietary extended and highly dynamic range (HDR) image format, saving both Alpha and Z-depth buffer information.
Description
* Programming openexr in polish wikibooks
exr file format
* standard: OpenExr
* extension: exr
* colors are always stored in scene linear color spaces, without any data loss. That makes them suitable to store renders that can later be composited, color graded and converted to different output formats.
* Files can also contain data that is not actually a color. For example normal or displacement maps merely contain vectors and offsets. Such images should be marked as Non-Color Data so that no color space conversion happens on them.
Programs
* exrtact - various tools to manipulate EXR images
* HDR + WCG Image Viewer by Simon Tao

### eps
# Moving images

* Video formats used in Commons
* GNU Parallel
* Converting video
* list of ffmpeg2theora parameters
* videos of quadratic Julia sets
* videos of quadratic Mandelbrot set
* FFMPEG File Formats

## Animated gif

Convert pgm ( or other ) static files into animated gif using BASH and Image Magic :
or another version by ClaudiusMaximus
Don't forget about : 12.5MP limit = 500 x 500 x 50 frames = 600 x 600 x 34 frames = 1000 x 1000 x 12 frames

## MPEG

Steps from pgm to video using Image Magic convert :
* pgm files to gif files
* gif files to video

## WebM

One can made a video from images. For examp
e creating WebM video files using ffmpeg
or ffmpeg2theora:
If you use files names containing parameter ( here Cx ), then it would be easy to sort files and make video :

## Y4M

* video file in YUV4Mpeg format
* raw video before compressing into other formats

# Graphic file documentation

* metadata
** exif
** comments
** chaunk
* ICC
* separate file
** parameter files
** separate text file

### ICC

how a color profile ( ICC) is stored in an image depends on the image format
* In PNG, for example, it's contained in a PNG iCCP chunk
* In JPEG, it's stored in a particular "marker"
* For other image formats, see http://www.color.org/profile_embedding.xalter

## Metadata

* pngmeta

## EXIF

* exif
* exiv2
* exifviewer
* exiftools

## Comment

Using Image Magic :
* comment
* escape
Image Magic one can add comment to png image using mogrify :
or using convert :
To read comment from png :
or :

## Chunk

A chunk is a fragment of information which is used in many multimedia formats, such as PNG, IFF, MP3 and AVI. Each chunk contains a header which indicates some parameters (e.g. the type of chunk, comments, size etc.) In the middle there is a variable area containing data which are decoded by the program from the parameters in the header.
Text chunk is one of standard ancillary PNG chunks. Its name is a tEXt.
Standard keywords for PNG text chunks:
The ancillary chunks currently known to ImageMagick are bKGD, cHRM, gAMA, iCCP, oFFs, pHYs, sRGB, tEXt, tRNS, vpAg, and zTXt.
Example with convert from Image Magic :
On can use pnmtopng utility :
pnmtopng -text file.txt 1000.pgm > 1000.png
where text file file.txt is :
png-text-embaded

## separate text file

Save pgm file and also text file with some description of the image:

## Parameter files

Parameters can be read from both parameter and image files :
parameter files :
* fct extension is used by Gnofract 4D
* .fzs extension is used by Fractal Zoomer ( binary file)
* F3 or f3.toml is used by fractaler-3 program
* kfr extension is used by Kalles Fraktaler 2 http://www.chillheimer.de/kallesfraktaler/
* mdz extension is used by Mandelbrot Deep Zoom
* mm extension is used by mightymandel
* mmit extension is used by Mandel Machine
* mp extension is used by mandelbrot-perturbator
* m3p extension is used by Mandelbulb3D
* par extension is used by Fractint
* sft extension is used by SuperFractalThing
* upr extension is used by UltraFractal
* XML extension is used by David Eck Java program to save Mandelbrot Settings
See also:
* fractalforums: kfb-to-mmit-converter

### Reading parameters
# Viewer for programmers

This program :
* opens binary ppm ( P6) or pgm ( P5) files
* it does not opens asci versions of these files.
It can be used to check image by checking output in console as mouse moves. Add your code to Motion function and update Zxmin and Zymin ( world coordinate).
It not works for newest version of OpenGl.

# References

* ↑ Computability of the Feigenbaum Julia set by Artem Dudko, Michael Yampolsky
* ↑ admvfx : file-formats-and-bit-depth by Benjamin Seide
* 1 2 "AV1 Image File Format (AVIF)". AOMediaCodec.GitHub.io. Archived from the original on 29 November 2018. Retrieved 25 November 2018.
* ↑ Mavlankar, Aditya; De Cock, Jan; Concolato, Cyril; Swanson, Kyle; Moorthy, Anush; Aaron, Anne (2020-02-13). "AVIF for Next-Generation Image Coding". The Netflix Tech Blog. Archived from the original on 2020-02-15. Retrieved 2021-11-19.
* ↑ "AOMediaCodec / av1-avif". GitHub. Retrieved 2022-02-05.
* 1 2 Concolato, Cyril (14 October 2019). "AV1 Image File Format (AVIF)" (PDF). AOMedia. Archived (PDF) from the original on 5 November 2019. Retrieved 6 November 2019.
* ↑ "Film Grain Synthesis for AV1 Video Codec" (PDF). Archived (PDF) from the original on 7 January 2021. Retrieved 14 December 2020.
* ↑ Bit depth colour precision in raster images (By Denis Kozlov)
* ↑ The Computer Language Benchmarks Game
* ↑ portable-floatmap-format-io-java by Nayuki
* ↑ imagemagick : high-dynamic-range
* ↑ HDR by Josef Pelikán & Alexander Wilkie
* ↑ [:w:Raw image format|Raw image format in wikipedia]
* ↑ wikipedia: Binary_file
* ↑ wikipedia: Image_file_formats - Raster_formats
* ↑ PARALLEL IMPLEMENTATION OF FRACTAL IMAGE COMPRESSION By Ryan F. UYS
* ↑ rawpedia - The encyclopedia of RawTherapee, raw shooting and everything raw
* ↑ itsfoss : raw-image-tools-linux
* ↑ photo.stackexchange question: is-tiff-really-of-higher-quality-than-png-24
* ↑ blender manual: color management
* ↑ Gnu Parallel
* ↑ Moebius transformation animated GIFs by Fritz Mueller
* ↑ ReCode Project - Topographic Form animated by ClaudiusMaximus
* ↑ How this video was made by Mukund
* ↑ mini-fract in Lisp by Yannick Gingras
* ↑ fileinfo : extension y4m
* ↑ pngmeta
* ↑ PNG and exif
* ↑ Image Magic - escape
* ↑ Stackoverflow : How to add extra meta data to PNG?
* ↑ Stackoverflow : Insert a text chunk into a png image
* ↑ wikipedia : Chunk (information)
* ↑ PNG (Portable Network Graphics) Specification, Version 1.2 : chunk
* ↑ https://github.com/gbenison/png-text-embed
* ↑ Mightymandel doc