Fractals/Computer graphic techniques/2D/gfile

"Any computer-generated picture is a finite collection of pixels." ( A Dudko, M Yampolsky)

a matrix of color entries (a.k.a. image)

Graphic files

One can :
 * directly create graphic file
 * open existing graphic file
 * add/read/remove text information to graphic file

Types of graphic files : =Static images= Digital Image Representation
 * 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
 * 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

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) 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):

Command 'cjpeg' not found, but can be installed with: sudo apt install libjpeg-progs       # version 1:9d-1, or sudo apt install libjpeg-turbo-progs  # version 2.1.2-0ubuntu1

How to use it :

./a.out | cjpeg > temp.jpg && open temp.jpg

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

P3 3 2 255 255 0 0 0 255 0 0 0 255 255 255 0 255 255 255 0 0 0
 * 1) the P3 means colors are in ascii, then 3 columns and 2 rows, then 255 for max color, then RGB triplets

The image (expanded):

The above image was expanded without interpolation, using the imagemagick command

convert -sample %6400 tiny6pixel.ppm tiny6pixel.png 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: P6 3 2 255 !@#$%^&*_+|{}:"<
 * 1) any comment string

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 : so if you want to use fwrite then you will get binary file ( even if you will open it in text mode ):
 * fwrite is used for binary files
 * fprintf is used for binary and text files

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 : i = ix + iy*iWidth; // index of 1D array ix = i % iWidth; iy = (i- ix) / iWidth; 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: [type] [xres] [yres] [byte_order]

Check file using xxd:

xxd memorial.pfm|head

output : 00000000: 5046 0a35 3132 2037 3638 0a2d 312e 3030 PF.512 768.-1.00 00000010: 3030 3030 0a00 8020 3c00 001e 3b00 0038 0000... <...;..8

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

SVG

 * creating SVG files
 * SVG images with src code

Dot
Dot files are text files describing graphs in dot language. Example file :

digraph "BinaryAddingMachine" { a [shape=circle] b [shape=circle] a -> a [label="1/1",color=red]; a -> a [label="2/2",color=blue]; b -> a [label="1/2",color=red]; b -> b [label="2/1",color=blue]; }

This file can be coverted to other formats using command line program dot. For example, to svg :

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 :

comment: My test comment

or :

identify -format "%c" X.ppm

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: Title           Short (one line) title or caption for image Author          Name of image's creator Description     Description of image (possibly long) Copyright       Copyright notice Creation Time   Time of original image creation Software        Software used to create the image Disclaimer      Legal disclaimer Warning         Warning of nature of content Source          Device used to create the image Comment         Miscellaneous comment; conversion from GIF comment

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 :

Title           Short (one line) title or caption for image Author          Name of image's creator Description     Description of image (possibly long) Copyright       Copyright notice Creation Time   Time of original image creation Software        Software used to create the image Disclaimer      Legal disclaimer Warning         Warning of nature of content Source          Device used to create the image Comment         Miscellaneous comment; conversion from GIF comment

png-text-embaded

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

Parameter files
A parameter file is a small text file which contains all the settings required to produce a particular image ( Gnofract4D)

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.

=See also=

=References=