r/cpp • graphics and network things • Apr 05 '18

2D Graphics : A More Modest Proposal

Like a lot of folks, I have been following the story of the 2D Graphics ideas for inclusion in C++. Today, there was a post summing up the history of how it ran into trouble: https://www.reddit.com/r/cpp/comments/89q6wr/sg13_2d_graphics_why_it_failed/ My own tldr is basically that graphics is potentially a huge topic, and people tried to cram a lot of graphics functionality into C++ as a first step. A lot of it seemed to be focused on trying to paint a house that hadn't been built yet. Without a simple, completely generic foundation to build fancy features on top of, it wasn't super useful to get off in the weeds of how exactly you would display an image or draw onto it. As people worked on various iterations of proposals, people generally agreed that graphics are cool, and some sort of graphics support could be quite useful, and generally asked, "If this proposal isn't what you want, what do you propose instead?"

So, I haven't put a ton of thought into this, and I haven't fleshed it out for a formal paper with a precise spec, I'd love to toss a pitch at the Reddit community and see what people think of my spin on this topic. Perhaps it'll evolve into something that I or somebody else actually formalizes into a paper for a proposal.

So, what would I propose? An intentionally very narrow scope. Basically, the dumbest, stupidest, simplest image container that is marginally useful.

A very simple container would consist of integers for width and height, storage for the pixels, a minimum metadata describing the image content, and some simple accessor functions for getting and setting pixels. And not much else.

It would support uint8 and float32 data types with n channels.

  • How would I display it?

I dunno, with some GUI API. I don't care and I don't have to. Concepts like windows and screens are explicitly out of scope for what I would propose. The idea is that one could write completely generic image processing code to create an image, and then GUI API's like Qt or WxWidgets would be easy to adapt to using the new image class. Qt's QString provides a QString::fromStdString() function. I would expect a future version of QImage would support something like QImage::fromStdImage() in a similar manner. The glue code to adapt a standard image to some new GUI API would be quite simple, so you could write your image handling code and use whatever GUI system you would like, or is most appropriate for your platform quite easily.

  • So this proposal doesn't include GUI?

Not merely "No," but rather emphatically, "Hell no." It constitutes a massive expansion of scope that is easily underestimated, and requires interacting with things like windowing systems that will likely be much harder to integrate into other GUI systems than a simple image class would be since it would need concepts like an event loop that could interfere with an application's main event loop by blocking it or swallowing events. Having to figure out how to do this well shouldn't block the additional of a simple image class.

  • Is it GPU accelerated?

Maybe. Mostly no. C++ has no concept of a GPU at present. I think that an image spec is the wrong place to introduce it. If you are using something like Cuda which compiles C++ code for GPU execution, then drawing using the "std::image" would presumably be made as performant as possible by the compiler vendor. But there is no way to enumerate GPU's, tell the new operator to allocate memory in a GPU's address space, etc. That can all be added independently of an image class, then the image class would be possible to allocate in the GPU memory, and acted on using some GPU drawing API.

API's such as OpenGL and Vulkan could easily interoperate with the image class with a bit of glue, such that you could upload a std::image for use as a texture, or read a GPU framebuffer into host memory and get the result as a std::image. std::image would not, itself have a concept for expressing a graphics API's texture handle or the like as the image.

  • How would I load such an image from disk

I dunno, use some library. I like OpenImageIO.

And here's where the utility of std::image appears, despite the emphatic lack of features! If you can use your favorite library to load an image into memory, and you can use your favorite GUI API for displaying it, then your favorite image related libraries can suddenly all talk to each other. std::image becomes the lingua franca between OpenImageIO, Qt, Wx Widgets, OpenCV, Vulkan, etc., etc., in a C++ application. You no longer need to worry about n-factorial glue wrappers between various image formats as you add libraries to your application to be able to bounce from any API to any API.

  • Copying is slow

The API will need some support for creating an image by copying an existing image, or by creating a non-owning view, or by taking ownership of an existing pixel storage. It'll also need an API for "un-owning" pixel storage. In this way, an OpenImageIO class can be made into a std::image, and then stuffed into a QImage for display without ever copying the pixels. The exact API needs a little thinking. There would still be a little overhead of constructing/destructing three class instances to shuffle one image around. But that overhead isn't going to be incredibly high compared to copying the pixel data.

  • Pixel storage

Chunky pixels - not planar. Support approximating planar data storage if you need it using a std::vector<std::image> with each image in the vector storing on plane. 1-n channels would be supported, though 4 channel RGBA images would probably be the most common. All channels would be the same resolution.

  • Space filling curves, tile based access, etc

Textures are often stored in wacky formats. Vulkan has a concept of "Optimal" storage for an image based on what's most efficient to sample such that geometrically nearby texels are stored in nearby memory locations to improve locality of access in caches. Some image formats like EXR store images in tiles which can be sparsely populated. (pg. 9)

None of that would have any explicit support in my concept of std::image. It's just a linear, flat, contiguous buffer of pixels in-order. Don't let the perfect be the enemy of the good here. You are welcome to store pixels in some z-curve order that suits your application, and anything that processes individual pixels would let it pass unmolested. (Like color corrections. Doubling the brightness of every pixel doesn't care what order the pixels are stored in, as long as the consistent chunky storage is consistent.) If the place you send your pixels supports that format, good for you. If not, it'll probably look wrong and you'll have nobody to blame but yourself.

  • Colorspaces

I think a std::string with a color space name would be about as well as you can do for something at this level. If you are using something like OpenColorIO, there may be a whole range of color configurations that only exist on a user's machine at runtime. So trying to make a set of enums or template classes based on color spaces would be a failure because it's completely impossible to know what colorspaces a user will be dealing with at compile time. It's expected that a user may wind up using colorspaces that the developer of an application never heard of in his life. Specifying colorspaces thoroughly is way, way, way, way outside of the scope of the C++ language. Just the Documentation Guide for ACES colorspace (TB-2014-001) is nine pages, and that's just the document that refers you to the documentation for other specific specs! (And ACES actually specifies several color spaces in addition to the main 2065-1 spec.) The sRGB spec is apparently 16 pages. Rec.709, Log spaces, RedCine, Raw spaces, Rec.601, Linear with sRGB primaries, Alexa, scene-referred vs. display-referred spaces, etc, should all rightly be outside the scope of the C++ language. Doing good color space handling requires more pages of spec than the rest of C++, some of the specs cost money, some of the specs are underspecified or proprietary, etc.

Ten years ago, you might reasonably argue that it would be useful just to explicitly support sRGB and call it a day. Today ordinary consumer equipment supports weird HDR modes, and even the dumbest GPU on the market supports floating point texture input even if some still don't support more than 8 bit output. Nailing it down too much isn't just a waste of effort, it's actively pounding a hole in your own foot.

I'd make a std::string field for the colorspace and mention it could be populated with strings like "sRGB." It's up to application developers to do sensible things with their pixels. This is a storage container, not training wheels.

  • What about YUV?

Decimated-channel formats like YUV-4:2:0 would not be supported. (Though you could make a std::vector<std::image> where the first image is full res luma and the next two are half res chroma channels, as mentioned above for planar storage. I'm not gonna fight you. But the developer is responsible for doing something useful with that vector of image planes.)

Full res YUV can be stored in chunky pixel format. A lot of stuff will assume it's RGB, but I don't care. This proposal doesn't have any operations on the image in it -- just the container. Some later proposal might suggest operators that would care about the contents more deeply.

  • What about 10 bit images?

No special effort to deal with odd integer formats. 8 bit is obviously extremely common so it would be silly not to support it. Past that, just use float. Maybe somebody could talk me into the importance of 16 or 32 bit integer storage, but it'd frankly be a fairly uncommon use case to require integer storage of many bits. I know it's not unheard of, but I think there's logic in covering the 90% use case as easily as possible, rather than making things harder on the 90% for the sake of some use cases that will be rare.

Gosh, I have already gone on way longer than I expected about this. (The implementation would be much shorter than my attempt to justify implementing it!) I am curious to hear people's thoughts about this baby step into graphics for C++. Am I way off-base? This seems like exactly the sort of thing that would be the right first step that all of the other stuff that people want could be built to pass around. Since graphics is in the air today, I am curious to hear what other people think about trying massively narrow the scope and start with the minimum thing that would be useful to the most people.

2 Upvotes

50 comments sorted by

11

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Apr 05 '18

Some of this sounds like what my colleague and I are working on.

4

u/wrosecrans graphics and network things Apr 05 '18

Sounds neat. Obviously, if something like this came from nV, it'd get a lot more eyeballs than some rando with a reddit account. I'd be curious to hear where you guys are going with it.

14

u/sumo952 Apr 05 '18

For standardization? Or as an NVIDIA library?

5

u/blelbach NVIDIA | ISO C++ Library Evolution Chair Apr 06 '18

std

1

u/ibroheem Apr 05 '18

Savagery!

33

u/johannes1971 Apr 05 '18

So you want to standardize std::vector<uint8_t> as an image format. I'm sorry, how is that helping anybody?

  • The concept of a container for pixels is not generally a problem that needs solving. It has already been solved, and considerably better than this.

  • This approach is incorrect anyway: you want an image format that doesn't need some kind of conversion step before hitting the screen. That means adjusting to whatever the OS demands of you.

  • This also does not meet the goal of getting beginners to easily get something on the screen. Not unless you want to start them by implementing their own line-drawing algorithms and whatever.

  • There are already numerous highly capable graphics libraries out there that could be used (whether standardized or not!), and are quite frankly a thousand times more attractive than having this kind of garbage in the standard.

The naive approach taken to graphics by people working on possible standardisation stands in sharp contrast to the incredibly detailed approach taken in other areas, such as threads, atomics, sockets, file IO, etc. I attribute this to lack of experience in that particular field by the people involved: they simply don't have the knowledge necessary to come up with an acceptable 2D API. Given this clear lack of involvement by professionals in the field of 2D graphics, it would be a much better choice to just leave it alone. If we need a library for helping students get up to speed, provide it as a separate tool, and don't make it part of the standard.

What the C++ community needs is a way to install that library. What we need is package management: some way for students, and professionals, to add additional libraries to their projects without spending days figuring out dependencies, build errors, and compiler settings. Once we have that, we'll have plenty of choices for whatever library we want to use.

> c++pm install https://www.curl.com/latest $HOME/packages/curl/latest
> c++pm add $HOME/packages/curl/latest $HOME/projects/my_project
> c++pm update $HOME/projects/my_project

That is what we need. Can we please have that?

3

u/wrosecrans graphics and network things Apr 05 '18

So you want to standardize std::vector<uint8_t> as an image format. I'm sorry, how is that helping anybody?

By providing a standard class that can be built on in the future, and used for interop between libraries. Also, I clearly stated that it would need more than 8 bit support and suggest that there would be a float type as well.

The concept of a container for pixels is not generally a problem that needs solving. It has already been solved, and considerably better than this.

It has been solved by every single library that deals with this stuff, in different ways because the standard is silent about it. Having so many examples of people reinventing the wheel implies that it's clearly the sort of thing that should be considered for standardisation.

This approach is incorrect anyway: you want an image format that doesn't need some kind of conversion step before hitting the screen. That means adjusting to whatever the OS demands of you.

The example I gave of a QImage constructed with the contents of a std::image would be trivial to display, without needing to worry about the details. Worst case scenario, the GUI API would do some format conversion internally to get it on screen.

This also does not meet the goal of getting beginners to easily get something on the screen. Not unless you want to start them by implementing their own line-drawing algorithms and whatever.

I feel very strongly that getting images on screen is way out of scope for a first proposal for 2D graphics. Making a proposal that involves stuff like input and a windowing system abstraction seems like there is just an error in naming if it is called "2D Graphics."

There are already numerous highly capable graphics libraries out there that could be used (whether standardized or not!), and are quite frankly a thousand times more attractive than having this kind of garbage in the standard.

It seems like the point of intersection of "numerous" libraries is exactly the sort of thing that should be in the standard!

I attribute this to lack of experience in that particular field by the people involved: they simply don't have the knowledge necessary to come up with an acceptable 2D API. Given this clear lack of involvement by professionals in the field of 2D graphics, it would be a much better choice to just leave it alone.

I'd argue that 2D graphics isn't really a field. There are a great many fields that use 2D graphics. I can claim professional experience in GUI application development and doing pipeline development for Visual Effects in film and television. (Hence some of the libraries I used as examples are probably best known in VFX, such as OpenColorIO.)

If we need a library for helping students get up to speed, provide it as a separate tool, and don't make it part of the standard.

This, I agree with. What I am suggesting would be useful for students, but also in various real applications.

What the C++ community needs is a way to install that library. What we need is package management:

Uhhh... Neat. But orthogonal to what I am talking about. You can reasonable expected that c++ libraries will use standard constructs like std::string and std::vector. If there was some vector class available in the package repos, some people would certainly use it, but not necessarily many. Being in the standard means it is the thing that everybody else can build on when they make their libraries that would live in your suggest package manager. So, I could build a blur algorithm that lives as a small package in the repository which operates on std::image, and you could build a package that displays the std::image I blurred. Absent a type in the standard for us to use when building our small packages, I need to do a whole lot of extra work to publish my blur package rather than being able to make something with the narrow scope of "blur a std::image."

3

u/kalmoc Apr 05 '18

Package managers do exist you know (not that there isn't room for improvement)

6

u/johannes1971 Apr 05 '18

As far as I know there is none that will let me:

  • download libraries without relying on a centralized repository

  • works across a range of platforms (including Windows and Mac) and compilers

  • works without me having to install a few gigabytes of build systems

  • let me install multiple versions of a library side by side

But if you can think of one, by all means propose it for standardisation!

7

u/DarkLordAzrael Apr 05 '18

Conan fits all of these right now. There is a central repository, but you can use any additional repositories you want (including hosting your own.) It supports all major platforms and doesn't require building the libraries locally, so you don't need the build tools they use. It also specifies the version to download and will happily allow you to have multiple versions or even multiple variants of the same version.

1

u/oldprogrammer Apr 05 '18

Just curious about some of your issues:

download libraries without relying on a centralized repository

What is wrong with having a central repo? Works quite well in the Maven/Java world.

works across a range of platforms (including Windows and Mac) and compilers

Looking back again at Maven, it has the concept of a classifier which is often used to distinguish components that are platform specific. For example, lwjgl (opengl for Java) allows pulling platform specific native libraries for the OpenGL code using this model.

works without me having to install a few gigabytes of build systems

As long as there is only 1 build system needed that works across platforms this shouldn't be an issue. Now if you need different build systems for different libraries then yes, this is an issue.

let me install multiple versions of a library side by side

Why would you want different versions of the same library for the same platform for a given application? Shouldn't there be only one version for an app? Then so long as the deployed application can locate its version this shouldn't be a problem?

I completely agree what C++ is missing is a solid build tool and dependency management system. With my limited exposure in recent years to current C++ (been in the Java world for a while) build systems I think CMake handles the cross platform build parts, so if there was just a way to handle dependency management in a commonly accepted way much like how Maven's dependency management is the defacto standard in Java, that would go a long way to eliminating the need to expand the C++ standard includes.

2

u/johannes1971 Apr 05 '18

What is wrong with having a central repo?

It means there need to be gatekeepers and maintainers. That's all fine for major open source libraries, but how about less well-known libraries? How about company-specific libraries? Inevitably choices will have to be made - but is there really a technical reason for that?

Having a distributed approach seems more democratic (no barrier to entry, set up a web page and you're done), more flexible (you could use libraries directly from the source, but there's nothing stopping someone from setting up a collection of vetted libraries from other sources), and more in-line with the spirit of the internet. And as I said, I don't see any major technical hurdles - so maybe the question should really be "what's wrong with having a distributed approach?" ;-)

Why would you want different versions of the same library for the same platform for a given application?

Not for a given application, but on my machine. It's because I want to maintain older versions of software. Coming back to an old application to make a quick change should not automatically imply that I first need to port it to the latest version of whatever libraries it uses. Doing that could easily raise the cost of the quick change from an hour worth of testing to a month-long verification cycle.

As for the build tool, I'm completely fine with a build tool being built into this package manager (or the other way around). I don't really care how a library gets transformed into something I can use, as long as it happens with a minimum of fuss. I don't even care about it doing it efficiently: external libraries get built only if and when a new version is introduced, which are generally rare occasions (and if you make them part of your normal daily build cycle, you're doing it wrong).

1

u/oldprogrammer Apr 06 '18

It means there need to be gatekeepers and maintainers.

I've never published a library to ibiblio but I would have assumed it would be something like that. Not sure what the tollgates are there. And I don't believe that would be an issue for small libraries.

The problem with a distributed approach is keeping the structure and layout consistent so that if you need a given library all you need is the base URL to fetch it. Maven allows naming custom repos so long as they follow the common directory structure, so perhaps not a central repo but an agreed upon distribution structure and meta data like the pom files in the Maven repos.

Coming back to an old application to make a quick change should not automatically imply that I first need to port it to the latest version of whatever libraries it uses.

100% agree with this, that is where a consistent versioning scheme comes into play where you can specify an exact version to pull in or have the build tool pull the latest snapshot at your discretion.

2

u/konanTheBarbar Apr 05 '18

I agree that we need better or even standardized package management. Imho that has nothing to do with the standardization of new vocubulary types.

So you want to standardize std::vector<uint8_t> as an image format.

I think that's quite unfair to say... That's almost like saying:

It's completely nonsense to standardize std::string, when we already std::vector<char>

1

u/1-05457 Apr 10 '18

Particularly given std::image would have to have multiple channels per pixel.

0

u/[deleted] Apr 05 '18

[deleted]

7

u/pklait Apr 05 '18

That code-snippet did not look like C++ to me.

0

u/[deleted] Apr 05 '18

[deleted]

1

u/encyclopedist Apr 05 '18

There is a C++ wrapper, libSDL2pp

2

u/kwan_e Apr 05 '18

since it would need concepts like an event loop

I agree we probably don't want a full blown GUI, but I don't see a problem with just being able to create one dumb window. Just like iostreams doesn't care about terminfo or termcap, yet handles running in a console window, there's no reason why a simple dumb graphics library can't handle a dumb window (ie, with no event loop or other bells and whistles).

2

u/wrosecrans graphics and network things Apr 05 '18

Depending on the OS/windowing system, no event loop means you can't do fairly expected stuff like move/resize/close the window. It also means that you need to create some sort of expectations about how to interpret the contents of the pixels buffer when you display it, which means you brush up against the colorspaces issues unless you don't care what gets displayed when you display it.

At that point, you are definitely 100% making a feature that's only useful in toys. I have a hard time considering that useful for teaching/learning purposes, because it's learning stuff that can't ever be used in a real application. If I want to learn to make applications, that API just kind of winds up being an obstacle I have to get through in a course before I can get to something I'll be able to use.

If somebody wants to add a display functionality as a subsequent proposal to the simple image container idea, cool. Let it get bikeshedded separately. But I still think there's value in just starting with the data structure for an image so the people who want to do a "display an image" proposal can just focus on the displaying part when the time comes.

I am pretty convinced that "be something to many people" is a better starting point than "be some things to some people" or the "be many things to a few people" approach that SG13 fell into. I am pretty much just gonna be shouting NO at every reasonable sounding suggestion for "one more thing" like a deranged two year old. :)

1

u/kwan_e Apr 05 '18

Depending on the OS/windowing system, no event loop means you can't do fairly expected stuff like move/resize/close the window.

You don't have to expose an event loop to the developer for that. The most that is really needed is to provide a callback for a resize event. Nothing else is needed.

which means you brush up against the colorspaces issues unless you don't care what gets displayed when you display it. At that point, you are definitely 100% making a feature that's only useful in toys.

Which is no different from iostreams. iostreams is really only useful in toys. Yet I would think most people would rather teach with iostreams than with the printf family.

Everyone understands RGB. It's even the main colourspace for web programming. That hasn't held back web development from being more than just a toy.

2

u/wrosecrans graphics and network things Apr 05 '18

You don't have to expose an event loop to the developer for that. The most that is really needed is to provide a callback for a resize event. Nothing else is needed.

If there is an event loop, it either blocks so the application developer's code isn't running except through some callback system, or it's in another thread and you can't display your image without the complexity of a multithreaded GUI. (eep) If the event loop exists then it'll potentially interfere with a main event loop, swallowing events and such if you try and use sthe std::display_window from a GUI app that is already trying to use events. That makes it toxic.

Tons of people use std::cout in real applications. It doesn't make anything explode, and it's fast enough for many uses.

1

u/kwan_e Apr 05 '18

Nothing wrong with a callback system. C++ has lambda functions now, making reactive programming simple. Even Javascript programmers have no problem with reactive programming.

As for interfering with the main event loop, that's always going to happen with any GUI library. I don't see that as a problem since you're always going to need to teach that.

Tons of people use std::cout in real applications. It doesn't make anything explode, and it's fast enough for many uses.

Yes? So what is your problem with a graphical equivalent (in terms of role, rather than implementation) of iostreams? A dumb way to display an image would not make anything explode and is fast enough for many uses.

2

u/drjeats Apr 05 '18

Iostreams isn't a great example since we're hopefully gonna have fmtlib standardized which would be better for both beginners and real world programs.

Also getting window resize messages still requires an event loop sonewhere. Either the user code is pumping the message queue, or there's some implicit thread spawned somewhere that takes care of all the window messages hidden away and just dispatching callbacks for specific messages, like glfw.

I like glfw, but an explicit OS event queue api more like SDL seems like a better foundation.

3

u/degski Apr 05 '18

Event loop:

int main ( ) {

    App app;

    while ( app.is_active ( ) ) {

        app.run ( );
    }

    return 0;
}

That's my game loop, no need for std support.

2

u/Heuristics Apr 06 '18

I want

#include <game>
auto myGame = std::make_game<std::FPS>();
myGame.run();

2

u/degski Apr 07 '18 edited Apr 07 '18

Just philosophical (there's nothing inherently wrong with the above), but I don't like the code as it doesn't expose the loop itself. As this std::graphics-lib is placed under the banner of "teaching C++ to beginners" (god (Bjarne?) only knows why, but that's another issue), it therefore abstracts away too much. Additionally, as a beginner, I think sticking with the (queried) screen-rate (your video card will really not write more often than the advertised frequency) or just assume 60Hz (and default enable (or not disable) vsync, if available), is appropriate, so no need for the templated fps-rate.

But, of course and in order to demonstrate my point above, we can go further to reduce code-length.

int main ( ) { A a; }

The default constructor calls a.run(), which will call a.run_frame() in a (while-) loop. We have thrown away the baby with the bath-water, though!

I also think we have already have a very good teaching lib, it's called std::vector, it exposes many STL-concepts/approaches (templates/allocators/iterators/algorithms/lvalues/rvalues/move-semantics/initializer-lists), while still being simple enough (in the case of a std::vector) to be easily understood conceptually by the beginner.

4

u/kalmoc Apr 05 '18

I think that is exactly the right approach: Focus on vocabulary types that can be used by the various libraries out there as an interchange format.

I can't speak to the soundness of your suggested design aspects, but I agree, it is more important to have something that is easy to use and good enough the mythical 90% of the time instead of creating a fully generic and maximal powerful solution. I think the most reasonable approach would be to look at existing libraries, check what functionality their interface types provide and base the proposal on that.

3

u/wrosecrans graphics and network things Apr 05 '18

"Vocabulary type" is exactly the term I should I have thought to use when I was doing my brain dump. Thanks.

1

u/jube_dev Apr 05 '18

One existing library is CImg. It is the base for G'MIC which is integrated in many image processing softwares like the Gimp or Krita.

2

u/sumo952 Apr 05 '18

Do you have any experience with it? It claims to be "modern C++" and it's a single header file, which makes it potentially very useful. But the website seems from 2004 and has information like it supports "[...] PC Linux 32 bits, with g++. PC Windows 32 bits, with Visual C++ Express Edition." which makes me very worried.

One huge problem with it is the CeCILL-C license - most company lawyers wouldn't go near that or even inspect it further (too much work) - it wouldn't be considered. Many people working on open-source projects also refrain from including anything with GPL or LGPL-like licenses because they want their software to be widely used.

Probably would be very worth looking at the design of the library though :-)

1

u/jube_dev Apr 05 '18

I was thinking about the design more than the actual implementation. As I said, it is used in G'MIC, so it's maintained. I cited this library because I think it fits the description of this post.

3

u/dutiona Apr 05 '18 edited Apr 05 '18

You know, trying to figure out what exactly an image is (from the point of view of image processing library implementor) is basically the subject of my Ph.D. thesis (that has started 6 months ago). I'm currently trying very hard to define a concept Image and list what are the possible models and model specializations of it. And when you want to have an approach that is compatible with the standard approach, it's not that easy. Reference work includes Range's design discussion here: https://ericniebler.github.io/std/wg21/D4128.html to have proper morphers (view) and algorithms (transform, for_each) separation.

Some image types that model the concept Image are (not exhaustive) :

* ImageND (specialization, Image2D, Image3D, Hyperspectral)
* bits (think of vector<bool> huehuehue)
* image with look up table
* graph, tree
* yeilded by a maths function
* ...

I won't go into details but if you want a proper Image concept, you need to think of stuff like neighborhood, extensions, iteration, interleaves, buffering (for large image (TB astro), nmap, streams, over network), points (they can be anything, really, just need to model (IIRC) EqualityComparable and StrictTotallyOrdered.

Well my point is, in my lab we've got a team (in which I am) that has worked the last 15 years on this problem, with publications, theses, lib implementation, etc. to back up all of this. We made design errors and iterated over it. It's oriented impage processing but I think that, if the committee is willing to encourage work on this, we may be willing to get involved: this is stuff we know about. (I don't know who nor when though, need to discuss with my Professor about that)

2

u/wrosecrans graphics and network things Apr 05 '18

You know, trying to figure out what exactly an image is (from the point of view of image processing library implementor) is basically the subject of my Ph.D. thesis

Heh, that sounds about right. It's also why I have tried to focus on narrowing down the scope to something pretty much trivial in the form of a useful image container rather than one which tried to be all things to all people.

Any container which tried to express every possible concept of image-ness becomes something that is so generic that it's basically impossible to write single code than do useful processing on any variation of it.

4

u/[deleted] Apr 05 '18

If people are interested I could try to sketch my take on it, but with the understanding that at this time, I cannot commit too many resources to "championing it to the end" without changes to my current life (I'm the guy that wrote some of those linked emails).

1

u/sumo952 Apr 05 '18 edited Apr 05 '18

std::image becomes the lingua franca between OpenImageIO, Qt, Wx Widgets, OpenCV, Vulkan, etc., etc., in a C++ application. You no longer need to worry about n-factorial glue wrappers between various image formats as you add libraries to your application to be able to bounce from any API to any API.

That would be really great. Couldn't agree more with that. However I think that an std::multi_dim_array_view (whatever it would be called) solves this sort-of too, and perhaps even in a better way. Sure it would always be non-owning, but no library would probably going to switch their image format anytime soon, if ever, and they'd have special requirements anyway, that one generic image type wouldn't cover. So a standardized, generic, multi-dimensional view on the data might be the better solution.

Maybe you or SG13 people should work towards that? I think the multi-dim array view people could use some help, if there is at all still someone working on it, it seems pretty dead.

Apart from that, I'd like to see some small proposals that cover things discussed in this thread (https://groups.google.com/a/isocpp.org/forum/?fromgroups#!topic/sg13/gUr98RZMU7M): Cross-platform abstractions for graphics context, and handling OS events (windows, windowing, input) - and incidentally texture/image formats is also mentioned in that thread.

Oh, and I wish we had image IO (read/write png, jpeg, tiff) in the standard library. Or finally a modern or header-only replacement for libpng/libjpeg. The same for reading video files - and reading data from webcams. That would be an other, small-ish, well-scoped thing.

1

u/wrosecrans graphics and network things Apr 05 '18

That would be an other, small-ish, well-scoped thing.

lol. Is it still April 1st?

Seriously, join the devel list for a library like OpenImageIO and see some of the odd corner cases that people deal with. If OIIO becomes mature enough, you could try to propose it as something to get adopted as a language feature like happens with boost. I just don't think you'll ever get traction for that because it's more useful as a library that gets fast iteration than a language spec that gets locked down. A vocabulary type for image is more useful as something that gets locked down because it becomes the obvious thing to interoperate between your favorite image reader library and whatever you want to do with it.

2

u/encyclopedist Apr 05 '18

Reading image files and even more so, reading video files, in in no way "smallish". Neither is it well-scoped, given that there are hundreds of formats, and most of them have dozens of variations. For example, no known application fully supports even JPEG specification.

1

u/sumo952 Apr 05 '18

Well sure, but you will never cover 100% of anything. libpng+libjpeg+libtiff cover I'd guess 99% of all the images out there. Of course there are very specialized domains (for example medical imaging, or maybe movie studios) that mainly use different formats. But that's not relevant here. It's about having easy access to something that is useful to 90% of the people, and not to every single person on the planet.

1

u/DerDangDerDang Apr 05 '18

Much of this appears in boost GIL - could be a good starting point?

1

u/wrosecrans graphics and network things Apr 05 '18

Basically, I think that GIL is too flexible to make a good candidate for inclusion in the standard. It's extremely generic to the point of supporting things like non-byte-aligned image data in its image classes. Which means that writing code that can handle all GIL variations becomes quite complex. Paring down to a minimal container means every library like GIL can interoperate with it.

Obviously, if std::image doesn't support a pixel format used in GIL, you wouldn't be able to do a zero-copy to make it, but it'd be a single-copy/conversion to go from some strange raw sensor data format in GIL to std::image, and then zero copy to go from std::image to an FFMPEG AVPicture or whatever, because AVPicture would support the common format of std::image pretty easily. (Then from the AVPivture you might do some subsequent conversion to YUYV or whatever to stuff into a compressed video file.)

1

u/DerDangDerDang Apr 05 '18

That's absolutely a fair point, thanks for your considered response. I wonder though if some of the (small c) concepts from GIL could be usefully turned into (capital C) Concepts in the standard. That would allow you to separate the storage from the valid operations on a notional image, which would feel much more like a C++stdlib feature than a somewhat customisable container would - IMO.

I'd also be interested in seeing how GIL's more interesting iterators could work with Ranges.

Pragmatically though, I can see that getting existing graphics libraries to interoperate with a fairly concrete std::image is an order of magnitude more likely than getting them interested in supporting abstract and esoteric sounding concepts. And of course none of this GIL-like stuff is likely to make graphics more approachable, probably the opposite!

1

u/wrosecrans graphics and network things Apr 05 '18

Adopting a GIL image container into the standard certainly isn't the craziest idea anybody ever suggested. As much as I find it way too generic to be useful day-to-day (much like my nemesis, Boost Graphics library, which supports more permutations than it will ever have users which means that it's possible no two programmers have ever done quite the same thing with it!), a GIL container is still much narrower in scope that the windows, input, sprites, drawing, singing and dancing megalibrary that variations of SG13 have covered. I feel like GIL is so generic, it's a bit like, "What if we started with std::string, but then spent most of our effort generalising it for non-character types." It's more general, but maybe std::string would be the wrong place to solve that problem, and not more useful.

I'd be a hard-no on including all of GIL since it has some utility functions for loading images from disk and the like that I'd firmly consider out of scope for a 1.0 effort. (Every library is currently forced to have some variation of a half-hearted image loader like that, since there's no lingua franca for populating your image container if you make one. Standardising means it's no longer in a vacuum, so the necessity is no longer there.) I am a stick in the mud. I am comfortable being a stick in the mud.

1

u/DerDangDerDang Apr 05 '18

I think you've convinced me you're onto the right approach. std::string is a great analogy - sure it's missing a lot of functionality and could be more general, but it's existence provides a lingua franca container that even severely NIH-minded libraries tend not to ignore.

1

u/wrosecrans graphics and network things Apr 05 '18

Exactly.

I parse a CSV, it gives me a std::string. I dome some processing and aggregation with a regex library that can operate on std::string. I review the results in a GUI that displays the contents of a std::string. I stuff that resulting data into a SQL database through an ORM using a std::string. I read the data back from the database and give a std::string to an HTTP API to shoot it out the network. And then you get a web page that says "John" is the most common baby name in the year you were born, or whatever.

But I don't need CSV support in my HTTP library to do it. B'cause, you know... there's a std library that other libraries can build on top of.

2

u/DerDangDerDang Apr 05 '18

and rather tellingly - nobody tried to standardise CSV parsing or database access before we had a standard string. (That's a bit of a straw-man given the timescales involved, but still a useful talking point I think.)

1

u/degski Apr 05 '18

nobody tried to standardise CSV parsing

You'd need to std CSV (with a new name: SCSV?), i.e. dis-allow any other separators than a comma (or any other (but one single) separator), before std parsing.

2

u/1-05457 Apr 10 '18

Finally, a sensible 2D graphics standard proposal.

1

u/kmhofmann https://selene.dev Apr 12 '18

Some of this sounds like what I've recently implemented in my image representation library: https://github.com/kmhofmann/selene

0

u/[deleted] Apr 05 '18

[deleted]

1

u/sumo952 Apr 05 '18

SFML?

1

u/degski Apr 05 '18 edited Apr 05 '18

Yes, +1.

There are quite a few posts in this thread (and in the thread, where this thread is a response to) touching upon [the problem of] compiling resources into a binary. On windows, I use the overloaded functions of LoadFromResource<T>(...) as defined in https://gist.github.com/degski/18b983d5153b85004eb28c9d8fd409fa . This mostly abstracts away all differences between resource types (sounds, fonts, images etc...). Unfortunately, the VS specific way of integrating the loading of resources (.rc and resource.h) is messy and does not allow for a lot of abstraction. You''ll need to create a .rc file and a resource.h. I've included some examples of some I've used for a project, just to show what needs to be in them (the project was about AI agents in games, pong, is just a test case). If any u has a better way of dealing with the .rc and resource.h, I'd be highly interested.