22
\$\begingroup\$

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?

Please post each I/O method, one per answer.

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

12 Answers 12

18
\$\begingroup\$

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.

If you feel that an image format is left out, please leave a comment.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ TIFF here as well. And I take it JPEG and JPG are the same? \$\endgroup\$
    – Tim
    May 11, 2016 at 12:59
  • \$\begingroup\$ @Tim Yes, they are the same. \$\endgroup\$
    – orlp
    May 11, 2016 at 18:35
  • 1
    \$\begingroup\$ Is PDF acceptable, say for LaTeX? \$\endgroup\$
    – Fatalize
    May 13, 2016 at 5:55
  • 4
    \$\begingroup\$ @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. \$\endgroup\$
    – orlp
    May 13, 2016 at 8:26
  • \$\begingroup\$ Double post? idk \$\endgroup\$
    – hyper-neutrino Mod
    Dec 13, 2017 at 21:31
  • 1
    \$\begingroup\$ If ppm is OK, I think pbm and pgm should be, too. (all the formats referred to as pnm) \$\endgroup\$
    – wastl
    Jun 24, 2019 at 13:59
17
\$\begingroup\$

Programs may output by displaying it on screen

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

\$\endgroup\$
2
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ May 10, 2016 at 12:51
  • 3
    \$\begingroup\$ Probably also permit displaying on a page? That's the natural output format for PostScript programs, for example. \$\endgroup\$ May 16, 2016 at 20:44
15
\$\begingroup\$

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.

If you feel that an image format is left out, please leave a comment.

\$\endgroup\$
7
  • \$\begingroup\$ What does this mean? A string of the path to the file, or a loaded file object? \$\endgroup\$
    – DJMcMayhem
    May 3, 2016 at 4:57
  • \$\begingroup\$ @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. \$\endgroup\$
    – orlp
    May 3, 2016 at 5:00
  • \$\begingroup\$ 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? \$\endgroup\$
    – Nic
    May 3, 2016 at 5:31
  • \$\begingroup\$ @QPaysTaxes Correct. \$\endgroup\$
    – orlp
    May 3, 2016 at 5:37
  • 1
    \$\begingroup\$ is .tiff common and raster? \$\endgroup\$
    – Tim
    May 8, 2016 at 20:16
  • \$\begingroup\$ @Tim according to Wikipedia .TIFF is both raster and commonly used. \$\endgroup\$ May 10, 2016 at 12:44
  • \$\begingroup\$ 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. \$\endgroup\$ May 10, 2016 at 12:47
14
\$\begingroup\$

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.

\$\endgroup\$
11
\$\begingroup\$

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.

\$\endgroup\$
10
\$\begingroup\$

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.

If you feel that an image format is left out, please leave a comment.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ 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". \$\endgroup\$
    – Downgoat
    May 3, 2016 at 5:05
  • 2
    \$\begingroup\$ I'm on the fence for this one. It can trivialize challenges (e.g. "draw a certain Bézier curve"). \$\endgroup\$
    – orlp
    May 3, 2016 at 5:06
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Downgoat
    May 3, 2016 at 5:07
  • \$\begingroup\$ @Downgoat pbm format allows ASCII based image files (not ASCII art) as output, which makes parsing trivial (no compression and minimal header). \$\endgroup\$ May 10, 2016 at 12:35
  • 1
    \$\begingroup\$ I think this should include ps and pdf. That could allow LaTeX for some nice Tikz golfs. \$\endgroup\$
    – corvus_192
    May 21, 2020 at 10:13
10
\$\begingroup\$

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.

\$\endgroup\$
9
\$\begingroup\$

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.

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

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.

\$\endgroup\$
4
  • \$\begingroup\$ Isn't it the same as default array for c++? \$\endgroup\$
    – Qwertiy
    May 4, 2016 at 9:49
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ May 10, 2016 at 12:58
  • \$\begingroup\$ 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) \$\endgroup\$
    – nanofarad
    Jun 19, 2016 at 16:14
  • \$\begingroup\$ @hexafraction I have no idea what an HDL is, but you make it sound like a separate I/O method altogether. \$\endgroup\$
    – orlp
    Jun 19, 2016 at 20:26
7
\$\begingroup\$

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.

\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
5
  • 2
    \$\begingroup\$ -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. \$\endgroup\$
    – orlp
    May 4, 2016 at 4:57
  • 5
    \$\begingroup\$ @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. \$\endgroup\$
    – user45941
    May 4, 2016 at 23:35
  • 1
    \$\begingroup\$ Yet people downvoted my proposed input format that is used everywhere in C and C++, and has no good alternative. \$\endgroup\$
    – orlp
    May 5, 2016 at 0:36
  • \$\begingroup\$ @orlp shrug I didn't downvote it but I hate my phone because I had to edit this three times to get it right \$\endgroup\$
    – user45941
    May 5, 2016 at 0:37
  • 2
    \$\begingroup\$ 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). \$\endgroup\$ Jun 6, 2016 at 8:46
-4
\$\begingroup\$

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.

If you feel that an image format is left out, please leave a comment.

\$\endgroup\$
2
  • 4
    \$\begingroup\$ -1 from me, it is unclear how the input should be represented as vector graphics, and is ripe for abuse to trivialize challenges. \$\endgroup\$
    – orlp
    May 3, 2016 at 5:04
  • 2
    \$\begingroup\$ How exactly is an HTML canvas blocks vector graphics format? They are like more like bitmaps, they can't be resized as their information is internally stored as a matrix of RGB \$\endgroup\$
    – Downgoat
    Jun 19, 2016 at 23:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .