{"action":"created","issue":{"url":"https://api.github.com/repos/PistonDevelopers/image/issues/305","labels_url":"https://api.github.com/repos/PistonDevelopers/image/issues/305/labels{/name}","comments_url":"https://api.github.com/repos/PistonDevelopers/image/issues/305/comments","events_url":"https://api.github.com/repos/PistonDevelopers/image/issues/305/events","html_url":"https://github.com/PistonDevelopers/image/issues/305","id":59147811,"number":305,"title":"Filter regression in PNG encoding","user":{"login":"mbrubeck","id":5920,"avatar_url":"https://avatars.githubusercontent.com/u/5920?v=3","gravatar_id":"","url":"https://api.github.com/users/mbrubeck","html_url":"https://github.com/mbrubeck","followers_url":"https://api.github.com/users/mbrubeck/followers","following_url":"https://api.github.com/users/mbrubeck/following{/other_user}","gists_url":"https://api.github.com/users/mbrubeck/gists{/gist_id}","starred_url":"https://api.github.com/users/mbrubeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbrubeck/subscriptions","organizations_url":"https://api.github.com/users/mbrubeck/orgs","repos_url":"https://api.github.com/users/mbrubeck/repos","events_url":"https://api.github.com/users/mbrubeck/events{/privacy}","received_events_url":"https://api.github.com/users/mbrubeck/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-02-26T21:36:24Z","updated_at":"2015-02-26T22:26:44Z","closed_at":null,"body":"#298 created a regression that causes some images to be encoded incorrectly as PNG.  This following test case demonstrates the problem.  The PPM file is correct, but every other row of the PNG file is incorrect.\r\n\r\n```rust\r\nlet white = image::Pixel::from_channels(255,255,255,255);\r\nlet black = image::Pixel::from_channels(0,0,0,255);\r\nlet img = image::ImageRgba8(image::ImageBuffer::from_fn(100, 100, move |x, y| {\r\n    if (x + y) % 2 == 0 { white } else { black }\r\n}));\r\nimg.save(&mut File::create(&Path::new(\"test.png\")).unwrap(), image::PNG);\r\nimg.save(&mut File::create(&Path::new(\"test.ppm\")).unwrap(), image::PPM);\r\n```\r\n\r\nReverting #298 fixes the bug.\r\n\r\nLooking at that patch, I think that [this line](https://github.com/PistonDevelopers/image/commit/e01fecbf75eff4a8939e68c49abfb6ab7ed7bce4#diff-e1a0e41840ecaefa415299d6f179b679R90) and [this line](https://github.com/PistonDevelopers/image/commit/e01fecbf75eff4a8939e68c49abfb6ab7ed7bce4#diff-e1a0e41840ecaefa415299d6f179b679R99) are incorrect, since `current[i - bpp]` is not the same as `orig[i - bpp]` in the previous code; it is a value that may have been changed by the preceding `for` loop.\r\n"},"comment":{"url":"https://api.github.com/repos/PistonDevelopers/image/issues/comments/76288281","html_url":"https://github.com/PistonDevelopers/image/issues/305#issuecomment-76288281","issue_url":"https://api.github.com/repos/PistonDevelopers/image/issues/305","id":76288281,"user":{"login":"mbrubeck","id":5920,"avatar_url":"https://avatars.githubusercontent.com/u/5920?v=3","gravatar_id":"","url":"https://api.github.com/users/mbrubeck","html_url":"https://github.com/mbrubeck","followers_url":"https://api.github.com/users/mbrubeck/followers","following_url":"https://api.github.com/users/mbrubeck/following{/other_user}","gists_url":"https://api.github.com/users/mbrubeck/gists{/gist_id}","starred_url":"https://api.github.com/users/mbrubeck/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbrubeck/subscriptions","organizations_url":"https://api.github.com/users/mbrubeck/orgs","repos_url":"https://api.github.com/users/mbrubeck/repos","events_url":"https://api.github.com/users/mbrubeck/events{/privacy}","received_events_url":"https://api.github.com/users/mbrubeck/received_events","type":"User","site_admin":false},"created_at":"2015-02-26T22:26:44Z","updated_at":"2015-02-26T22:26:44Z","body":"Another problem is that [this code](https://github.com/PistonDevelopers/image/commit/e01fecbf75eff4a8939e68c49abfb6ab7ed7bce4#diff-e1a0e41840ecaefa415299d6f179b679R89) uses `-1` as an unsigned integer literal, so `range_step_inclusive` tries to step by `usize::MAX` and stops immediately due to overflow."}}