{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/343","labels_url":"https://api.github.com/repos/bumptech/glide/issues/343/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/343/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/343/events","html_url":"https://github.com/bumptech/glide/issues/343","id":57760033,"number":343,"title":"Disable saving as JPG (i.e. force saving as PNG) v3.5.1","user":{"login":"alex2069","id":1487856,"avatar_url":"https://avatars.githubusercontent.com/u/1487856?v=3","gravatar_id":"","url":"https://api.github.com/users/alex2069","html_url":"https://github.com/alex2069","followers_url":"https://api.github.com/users/alex2069/followers","following_url":"https://api.github.com/users/alex2069/following{/other_user}","gists_url":"https://api.github.com/users/alex2069/gists{/gist_id}","starred_url":"https://api.github.com/users/alex2069/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex2069/subscriptions","organizations_url":"https://api.github.com/users/alex2069/orgs","repos_url":"https://api.github.com/users/alex2069/repos","events_url":"https://api.github.com/users/alex2069/events{/privacy}","received_events_url":"https://api.github.com/users/alex2069/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-16T02:54:26Z","updated_at":"2015-02-16T12:39:40Z","closed_at":null,"body":"We're getting some pretty bad JPG artefacts when loading from cache.\r\nI've determined that the cached images are being saved as JPG format, however I'm unable to determine how to correctly force saving as PNG.\r\nI saw issue #63 and #64 that allowed for this, but it seems this is not longer valid for v3.5.1.\r\n\r\nFrom what I've been able to determine I need to create a <code>BitmapEncoder</code> with <code>Bitmap.CompressFormat.PNG</code>, pass that to <code>StreamBitmapDataLoadProvider</code>, and register it with <code>dataLoadProviderRegistry</code>:\r\n<code>dataLoadProviderRegistry.register(InputStream.class, Bitmap.class, streamBitmapLoadProvider);</code>\r\n\r\nHowever <code>dataLoadProviderRegistry</code> is private, doesn't have a getter, and doesn't accept any input from the builder.\r\nI figured as a quick workaround I could just use reflection during <code>registerComponents</code> to register my own sub-class of <code>StreamBitmapDataLoadProvider</code> and provide my own <code>BitmapEncoder</code>, however during construction of the original <code>dataLoadProviderRegistry</code>, the inputs are cascaded down through <code>ImageVideoDataLoadProvider</code> and <code>ImageVideoGifDrawableLoadProvider</code>. Thus to properly fix it I'd need to effectively copy that entire block providing my <code>BitmapEncoder</code> from the start.\r\n\r\nPlease tell me I'm stupid and missed something really obvious lol.\r\n<br />\r\n<hr>\r\nAs an aside, I think defaulting to a lossy format is a terrible idea. Most people wouldn't expect their disk cache to change what they see coming from the server. Disk space is rarely an issue these days, and for those users that it is, they can clear their app cache or whatever when they need to. Can you imagine what would happen if you tried to save a bitmap on a web browser and what you got was a degraded copy?\r\n\r\nHaving said all that our app has a huge amount of high-res photographic artwork, but also a lot of logos (where JPG compression artefacts are prevalent and very noticeable). I suspect it's possible (though non-trivial) to register custom models/loaders to save as JPG for some resources, but PNG for others? To be honest I doubt I'll bother but would probably consider it if it was simple. In an ideal world there'd be a way to check for a uniform compression complexity and use PNG appropriately - though this is probably a bit excessive heh."},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/74502547","html_url":"https://github.com/bumptech/glide/issues/343#issuecomment-74502547","issue_url":"https://api.github.com/repos/bumptech/glide/issues/343","id":74502547,"user":{"login":"alex2069","id":1487856,"avatar_url":"https://avatars.githubusercontent.com/u/1487856?v=3","gravatar_id":"","url":"https://api.github.com/users/alex2069","html_url":"https://github.com/alex2069","followers_url":"https://api.github.com/users/alex2069/followers","following_url":"https://api.github.com/users/alex2069/following{/other_user}","gists_url":"https://api.github.com/users/alex2069/gists{/gist_id}","starred_url":"https://api.github.com/users/alex2069/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex2069/subscriptions","organizations_url":"https://api.github.com/users/alex2069/orgs","repos_url":"https://api.github.com/users/alex2069/repos","events_url":"https://api.github.com/users/alex2069/events{/privacy}","received_events_url":"https://api.github.com/users/alex2069/received_events","type":"User","site_admin":false},"created_at":"2015-02-16T12:39:40Z","updated_at":"2015-02-16T12:39:40Z","body":"My understanding is that <code>DiskCacheStrategy.SOURCE</code> will not cache transformations (http://bumptech.github.io/glide/javadocs/latest/com/bumptech/glide/load/engine/DiskCacheStrategy.html#SOURCE), which is not a good fix in this case. We use a lot a reasonably heavy transformations that are ideal for caching. e.g. There is a view pager with a blurred background that cross-fades to the next page etc when swiping. Swiping back and forth is nice and quick and smooth due to the caching, which would be unfortunate to lose.\r\n\r\nIt's interesting you mention having space issues (I have many GB free on my Nexus 4 so I guess it never really cross my mind), but there have been a couple of reports of space issues (prior to Glide where we used a custom cache that failed when device was full - oops). It might be interesting to see some analytics of our user base on how much free space users generally have (assuming we can get that kind of info without additional permissions).\r\n\r\nRegarding the <code>inSampleSize</code>, do you have any evidence or articles substantiating this? After adding my gross reflection fix I thought I'd noticed decreased fast scroll performance, but dismissed it thinking it was just testing hiccups. It'd be a shame if this was the case (though in the end it's still orders of magnitude more performant than what Picasso was)."}}