{"action":"created","issue":{"url":"https://api.github.com/repos/SFML/SFML/issues/1152","repository_url":"https://api.github.com/repos/SFML/SFML","labels_url":"https://api.github.com/repos/SFML/SFML/issues/1152/labels{/name}","comments_url":"https://api.github.com/repos/SFML/SFML/issues/1152/comments","events_url":"https://api.github.com/repos/SFML/SFML/issues/1152/events","html_url":"https://github.com/SFML/SFML/issues/1152","id":177674457,"number":1152,"title":"General improvements for sf::Image","user":{"login":"Fytch","id":10600373,"avatar_url":"https://avatars.githubusercontent.com/u/10600373?v=3","gravatar_id":"","url":"https://api.github.com/users/Fytch","html_url":"https://github.com/Fytch","followers_url":"https://api.github.com/users/Fytch/followers","following_url":"https://api.github.com/users/Fytch/following{/other_user}","gists_url":"https://api.github.com/users/Fytch/gists{/gist_id}","starred_url":"https://api.github.com/users/Fytch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fytch/subscriptions","organizations_url":"https://api.github.com/users/Fytch/orgs","repos_url":"https://api.github.com/users/Fytch/repos","events_url":"https://api.github.com/users/Fytch/events{/privacy}","received_events_url":"https://api.github.com/users/Fytch/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-18T20:22:25Z","updated_at":"2016-09-19T07:29:23Z","closed_at":"2016-09-19T07:29:23Z","body":"I happen to use `sf::Image` quite a lot in a current project but I am widely dissatisfied with its somewhat meager functionality. Possible improvements:\r\n\r\n- Constructor overload that does the same as `sf::Image::create`.\r\n- `sf::Image::create` is poorly implemented. It calls `.resize` on the internal `std::vector` which either leads to every old pixel being copied (even though they are all overwritten shortly after) or to `sf::Image` possessing a lot of memory it doesn't use (because `std::vector::capacity` stays the same regardless). The correct way of implementing this function is to swap the internal vector with a newly created one.\r\n- `sf::Image::create` grants no exception safety. The instance is indeed corrupt after an erroneous `sf::Image::create` invocation because the dimensions and the actual data don't match anymore. However, strong exception safety (no changes in case of an exception being thrown) is easily achievable by just changing the order inside the function. Memory allocation must be done first and only then the actual instance should be modified.\r\n- There should be an overload of `sf::Image::create` that doesn't fill the image with a particular color. This is an optimization when the user intends to overwrite the pixels anyway.\r\n- `sf::Image::swap` should be implemented. The lack thereof forces users to copy the content from one image to another instead of just swapping the vectors' pointers, which leads to significant worse performance.\r\n- `sf::Image::empty` would be nice as `sf::Image.getPixelsPtr() == nullptr` doesn't work and `sf::Image.getSize().x && sf::Image.getSize().y` is verbose. Multiple functions of `sf::Image` contain `if (!m_pixels.empty())`, yet this function isn't available outside the class.\r\n\r\nI can implement these by myself and create a pull request, if others also appreciate these improvements."},"comment":{"url":"https://api.github.com/repos/SFML/SFML/issues/comments/247926704","html_url":"https://github.com/SFML/SFML/issues/1152#issuecomment-247926704","issue_url":"https://api.github.com/repos/SFML/SFML/issues/1152","id":247926704,"user":{"login":"mantognini","id":693483,"avatar_url":"https://avatars.githubusercontent.com/u/693483?v=3","gravatar_id":"","url":"https://api.github.com/users/mantognini","html_url":"https://github.com/mantognini","followers_url":"https://api.github.com/users/mantognini/followers","following_url":"https://api.github.com/users/mantognini/following{/other_user}","gists_url":"https://api.github.com/users/mantognini/gists{/gist_id}","starred_url":"https://api.github.com/users/mantognini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mantognini/subscriptions","organizations_url":"https://api.github.com/users/mantognini/orgs","repos_url":"https://api.github.com/users/mantognini/repos","events_url":"https://api.github.com/users/mantognini/events{/privacy}","received_events_url":"https://api.github.com/users/mantognini/received_events","type":"User","site_admin":false},"created_at":"2016-09-19T07:29:23Z","updated_at":"2016-09-19T07:29:23Z","body":"You are more than welcome to discuss your issue on the forum first as we try to keep this issue tracker for confirmed issues only. The procedure to open a bug/feature request is explained in [the contribution guidelines](http://www.sfml-dev.org/contribute.php). Thanks."}}
{"actor":{"display_login":"mantognini"}}