# Default acceptable image I/O methods for image related challenges

I do not feel that the default general acceptable I/O methods sufficiently cover and challenges. So I would like to poll.

What are the default acceptable I/O methods specifically for image related challenges?

• I assume the output related answers apply equally to [graphical-output]? – trichoplax May 10 '16 at 12:36
• @trichoplax I guess, yes. – orlp May 10 '16 at 13:55
• @orlp what about using HTML <img ... tag with dataURI image (BMP not base64 encoded) as output (e.g. first snippet here ) ? – Kamil Kiełczewski Sep 20 at 14:41

# Programs may output via a common raster graphics image format

The common raster graphics image formats are .png, .jpg, .tga, .ppm, .gif, .bmp, .tiff.

The output may be through a default allowed output method, e.g. a filename, stdout, function return, etc.

• TIFF here as well. And I take it JPEG and JPG are the same? – Tim May 11 '16 at 12:59
• @Tim Yes, they are the same. – orlp May 11 '16 at 18:35
• Is PDF acceptable, say for LaTeX? – Fatalize May 13 '16 at 5:55
• @Fatalize I don't think so. PDF is way too big of a standard to control what is allowed, and goes way beyond raster images. – orlp May 13 '16 at 8:26
• Double post? idk – HyperNeutrino Dec 13 '17 at 21:31
• If ppm is OK, I think pbm and pgm should be, too. (all the formats referred to as pnm) – wastl Jun 24 at 13:59

# Programs may output by displaying it on screen

Displaying the output image on screen is an acceptable form of output.

• I posted a challenge where output could be larger than the screen for some inputs. I allowed displaying on screen provided that the image can be scrolled to show all parts. – trichoplax May 10 '16 at 12:51
• Probably also permit displaying on a page? That's the natural output format for PostScript programs, for example. – Toby Speight May 16 '16 at 20:44

# Programs may take input via a common raster graphics image format

The common raster graphics image formats are .png, .jpg, .tga, .ppm, .gif, .bmp, .tiff.

The input may be through a default allowed input method, e.g. a filename, stdin, function argument, etc.

• What does this mean? A string of the path to the file, or a loaded file object? – DJMcMayhem May 3 '16 at 4:57
• @DrGreenEggsandHamDJ I edited it to say filename, but it was just a summary of meta.codegolf.stackexchange.com/questions/2447/…. Loaded file objects as a function argument is not a default method. – orlp May 3 '16 at 5:00
• When you say "a function argument", what do you mean? Do you mean the raw bytes of the input in an array as an argument? – Fund Monica's Lawsuit May 3 '16 at 5:31
• @QPaysTaxes Correct. – orlp May 3 '16 at 5:37
• is .tiff common and raster? – Tim May 8 '16 at 20:16
• @Tim according to Wikipedia .TIFF is both raster and commonly used. – trichoplax May 10 '16 at 12:44
• TIFF also has the option to include vector graphics clipping, but code that depends on that wouldn't work with general TIFF files, so that doesn't seem a problem for input. – trichoplax May 10 '16 at 12:47

# Programs may output as a matrix of RGB pixel values

The matrix rows must match the image rows, the matrix columns must match the image columns, and the pixel values must be given as (R, G, B) tuples.

# Programs may output via a common vector graphics image format

The common vector graphics image formats are .svg and a <canvas> HTML block.

The output may be through a default allowed output method, e.g. a file, stdout, function return, etc.

• Output for JavaScript is mostly done through Canvas as that's about it with JavaScript's image API. HTML <canvas> can also be considered as "displaying on screen". – Downgoat May 3 '16 at 5:05
• I'm on the fence for this one. It can trivialize challenges (e.g. "draw a certain Bézier curve"). – orlp May 3 '16 at 5:06
• Even if canvas is disallowed, that's for I/O, I could still use canvas to draw a bezier curve and not use it for I/O. That could also be said about practically any image library. Disallowing <canvas> is making all JavaScript solutions having to implement a binary png parser which is absurd. – Downgoat May 3 '16 at 5:07
• @Downgoat pbm format allows ASCII based image files (not ASCII art) as output, which makes parsing trivial (no compression and minimal header). – trichoplax May 10 '16 at 12:35

# A component of a pixel may be input or output as an integer 0-255

This is not an input method on its own, but input methods that take or return a collection of individual pixels, may input or output a component of such a value as an integer in the range 0-255, where 0 is the least intense, and 255 is maximum intensity.

# Programs may take input as a matrix of RGB pixel values

The matrix rows must match the image rows, the matrix columns must match the image columns, and the pixel values must be given as (R, G, B) tuples.

# Programs may take input as an array of RGB pixel values with dimensions

The pixels are ordered from top-to-bottom, left-to-right (reading order), and the pixel values may be given as (R, G, B) tuples, or all concatenated into one big array.

The latter one big array is useful for example for C, where image I/O is often done by the function signature void f(unsigned char* p, int w, int h), and (p[0], p[1], p[2]) is the first RGB pixel tuple.

As the pixel array does not store dimensions, they can be given as extra arguments.

• Isn't it the same as default array for c++? – Qwertiy May 4 '16 at 9:49
• I would be against any preprocessing of the image but since this just presents the same raw data with no calculation applied to it, I see no problem. – trichoplax May 10 '16 at 12:58
• For an HDL, can array be streamed byte-by-byte or pixel-by-pixel and the dimensions be provided through the timing of HSYNC and VSYNC signals going to the module being submitted as the answer? (same question applies to outputting using an RGB pixel array) – ζ-- Jun 19 '16 at 16:14
• @hexafraction I have no idea what an HDL is, but you make it sound like a separate I/O method altogether. – orlp Jun 19 '16 at 20:26

# A component of a pixel may be input or output as a real number between 0 and 1

This is not an input method on its own, but input methods that take or return a collection of individual pixels, may input or output a component of such a value as a real number in the range 0-1, where 0 is the least intense, and 1 is maximum intensity.

# Programs may output via an array of RGB pixel values with dimensions

The pixels are ordered from top-to-bottom, left-to-right (reading order), and the pixel values must be output as (R, G, B) tuples, or all concatenated into one big array.

As a pixel array does not store dimensions, they must be output as additional information.

• Isn't it the same as default array for c++? – Qwertiy May 4 '16 at 9:50
• I don't see the reason for this being voted lower than "Programs may output as a matrix of RGB values." – trichoplax May 10 '16 at 13:02

## Input and output may be done with builtin image data types from the language and/or library being used

For example, in Python with PIL, a PIL.Image object would be a valid input and output format.

• -1 from me, using built-in image formats is enough of an advantage already, no need to make it worse by not even having to write the code to call the builtin. – orlp May 4 '16 at 4:57
• @orlp I disagree. By allowing image data types as input and output, the focus is more on the actual challenge, and less on getting the data in a usable format. – Mego May 4 '16 at 23:35
• Yet people downvoted my proposed input format that is used everywhere in C and C++, and has no good alternative. – orlp May 5 '16 at 0:36
• @orlp shrug I didn't downvote it but I hate my phone because I had to edit this three times to get it right – Mego May 5 '16 at 0:37
• For the record, this is actually common practice in Mathematica, where people usually write a function taking/returning an image. Additionally, this doesn't even "call the built-in for free". It's just the most natural way to work with an image, because you can simply copy the image itself into Mathematica and then use it. There is no function call involved in loading it (unless the challenge requires loading it from disc). – Martin Ender Jun 6 '16 at 8:46

# Programs may take input via a common vector graphics image format

The common vector graphics image formats are .svg and a <canvas> HTML block.

The input may be through a default allowed input method, e.g. a filename, stdin, function argument, etc.