GitHub PullRequestReviewCommentEvent at 2014-11-10 07:53:02
Repository: lesson2
Actor: thevery
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/comments/20069770","id":20069770,"diff_hunk":"@@ -1,12 +1,145 @@\n package ru.ifmo.md.lesson2;\n \n import android.app.Activity;\n+import android.graphics.Bitmap;\n+import android.graphics.BitmapFactory;\n+import android.os.AsyncTask;\n import android.os.Bundle;\n+import android.view.View;\n+import android.widget.ImageView;\n \n public class MyActivity extends Activity {\n \n+    // a task so that UI thread doesn't have the 200ms lag associated with slow rescaling\n+    private class AsyncResizeTask extends AsyncTask<Boolean, Void, Bitmap> {\n+        @Override\n+        public Bitmap doInBackground(Boolean[] params) {\n+            Bitmap rv = getAdjustedImage(params[0]);\n+            if (params[0])\n+                fastImage = rv;\n+            else\n+                slowImage = rv;\n+            return rv;\n+        }\n+\n+        @Override\n+        public void onPostExecute(Bitmap bm) {\n+            view.setImageBitmap(bm);\n+            rescaleTask = null;\n+        }\n+    }\n+\n+    static int[] pixelTransformTable = new int[256];\n+\n+    static {\n+        for (int i = 0; i < 256; i++) { // offers subjectively better quality\n+            pixelTransformTable[i] = (int) (Math.sqrt(((float) i) / 255.0f) * 255.0f);\n+        }\n+    }\n+\n+    private final static int TARGET_WIDTH = 434;\n+    private final static int TARGET_HEIGHT = 405;\n+\n+    private boolean useFast = false;\n+\n+    private ImageView view;\n+\n+    private int[] oldPixels = null;\n+    private Bitmap fastImage = null;\n+    private Bitmap slowImage = null;\n+    private int oldW;\n+    private int oldH;\n+\n+    private AsyncResizeTask rescaleTask = null;\n+\n+    private Bitmap getAdjustedImage(boolean fast) {\n+        int w = TARGET_WIDTH;\n+        int h = TARGET_HEIGHT;\n+\n+        if (oldPixels == null) {\n+            Bitmap sourceBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.source);\n+            oldW = sourceBitmap.getWidth();\n+            oldH = sourceBitmap.getHeight();\n+            oldPixels = new int[oldW * oldH];\n+            sourceBitmap.getPixels(oldPixels, 0, oldW, 0, 0, oldW, oldH);\n+        }\n+\n+        int[] newPixels = new int[w * h];\n+        int[] oldPixels = this.oldPixels; // someone said java is slightly faster this way\n+\n+        if (fast) { // fast method: nearest\n+            for (int y = 0; y < h; y++) {\n+                for (int x = 0; x < w; x++) {\n+                    newPixels[x + y * w] = oldPixels[y * oldW / h + (w - 1 - x) * oldH / w * oldW];\n+                }\n+            }\n+        } else { // slow method: plain 'supersampling'\n+            int[] scratchpad = new int[w * h];\n+\n+            for (int x = 0; x < oldW; x++)\n+                for (int y = 0; y < oldH; y++) {\n+                    int targetX = w - 1 - y * w / oldH;\n+                    int targetY = x * h / oldW;\n+                    int targetIdx = targetX + targetY * w;\n+\n+                    int cpv = newPixels[targetIdx];\n+                    int csv = oldPixels[x + y * oldW];\n+                    int r = (cpv & 0xff) * scratchpad[targetIdx] + (csv & 0xff);\n+                    int g = ((cpv & 0xff00) >> 8) * scratchpad[targetIdx] + ((csv & 0xff00) >> 8);\n+                    int b = ((cpv & 0xff0000) >> 16) * scratchpad[targetIdx] + ((csv & 0xff0000) >> 16);\n+\n+                    scratchpad[targetIdx]++;\n+\n+                    r /= scratchpad[targetIdx];\n+                    g /= scratchpad[targetIdx];\n+                    b /= scratchpad[targetIdx];\n+\n+                    newPixels[targetIdx] = 0xff000000 | (b << 16) | (g << 8) | r;\n+                }\n+        }\n+        int[] pixelTransformTable = MyActivity.pixelTransformTable;","path":"app/src/main/java/ru/ifmo/md/lesson2/MyActivity.java","position":100,"original_position":100,"commit_id":"7d2fee7b73492ccf0fa768348ba8ffbf5eb85f57","original_commit_id":"7d2fee7b73492ccf0fa768348ba8ffbf5eb85f57","user":{"login":"thevery","id":99576,"avatar_url":"https://avatars.githubusercontent.com/u/99576?v=3","gravatar_id":"","url":"https://api.github.com/users/thevery","html_url":"https://github.com/thevery","followers_url":"https://api.github.com/users/thevery/followers","following_url":"https://api.github.com/users/thevery/following{/other_user}","gists_url":"https://api.github.com/users/thevery/gists{/gist_id}","starred_url":"https://api.github.com/users/thevery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thevery/subscriptions","organizations_url":"https://api.github.com/users/thevery/orgs","repos_url":"https://api.github.com/users/thevery/repos","events_url":"https://api.github.com/users/thevery/events{/privacy}","received_events_url":"https://api.github.com/users/thevery/received_events","type":"User","site_admin":false},"body":"static variables usually mean bad technical design and lead to memory leaks","created_at":"2014-11-10T07:53:02Z","updated_at":"2014-11-10T07:53:02Z","html_url":"https://github.com/IFMO-MobDev-2014/lesson2/pull/3#discussion_r20069770","pull_request_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/comments/20069770"},"html":{"href":"https://github.com/IFMO-MobDev-2014/lesson2/pull/3#discussion_r20069770"},"pull_request":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3","id":21538751,"html_url":"https://github.com/IFMO-MobDev-2014/lesson2/pull/3","diff_url":"https://github.com/IFMO-MobDev-2014/lesson2/pull/3.diff","patch_url":"https://github.com/IFMO-MobDev-2014/lesson2/pull/3.patch","issue_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/issues/3","number":3,"state":"open","locked":false,"title":"Кузнецов Николай, 2539","user":{"login":"knah","id":4705494,"avatar_url":"https://avatars.githubusercontent.com/u/4705494?v=3","gravatar_id":"","url":"https://api.github.com/users/knah","html_url":"https://github.com/knah","followers_url":"https://api.github.com/users/knah/followers","following_url":"https://api.github.com/users/knah/following{/other_user}","gists_url":"https://api.github.com/users/knah/gists{/gist_id}","starred_url":"https://api.github.com/users/knah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knah/subscriptions","organizations_url":"https://api.github.com/users/knah/orgs","repos_url":"https://api.github.com/users/knah/repos","events_url":"https://api.github.com/users/knah/events{/privacy}","received_events_url":"https://api.github.com/users/knah/received_events","type":"User","site_admin":false},"body":"Somewhat efficient (in my opinion) way to complete the task.\r\nResizing algorithms are nearest for fast, and supersampling for best, and although it may not actually be the best, it still provides decent quality and is relatively fast.\r\nFor changing color, square root-based method is used, as it allows for subjective brightening without quality degradation. In addition, it's fast.\r\nAll resulting images are cached for reuse, as \"best\" method requires around 200ms of processing on Galaxy S2. In order to make app even more responsive, AsyncTask is used to perform calculations in separate thread.","created_at":"2014-09-20T16:09:23Z","updated_at":"2014-11-10T07:53:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fa4763e6eff3ef638ddec5ddd2a00b442e3ca227","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3/commits","review_comments_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3/comments","review_comment_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/comments/{number}","comments_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/issues/3/comments","statuses_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/statuses/7d2fee7b73492ccf0fa768348ba8ffbf5eb85f57","head":{"label":"knah:master","ref":"master","sha":"7d2fee7b73492ccf0fa768348ba8ffbf5eb85f57","user":{"login":"knah","id":4705494,"avatar_url":"https://avatars.githubusercontent.com/u/4705494?v=3","gravatar_id":"","url":"https://api.github.com/users/knah","html_url":"https://github.com/knah","followers_url":"https://api.github.com/users/knah/followers","following_url":"https://api.github.com/users/knah/following{/other_user}","gists_url":"https://api.github.com/users/knah/gists{/gist_id}","starred_url":"https://api.github.com/users/knah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knah/subscriptions","organizations_url":"https://api.github.com/users/knah/orgs","repos_url":"https://api.github.com/users/knah/repos","events_url":"https://api.github.com/users/knah/events{/privacy}","received_events_url":"https://api.github.com/users/knah/received_events","type":"User","site_admin":false},"repo":{"id":24232593,"name":"lesson2","full_name":"knah/lesson2","owner":{"login":"knah","id":4705494,"avatar_url":"https://avatars.githubusercontent.com/u/4705494?v=3","gravatar_id":"","url":"https://api.github.com/users/knah","html_url":"https://github.com/knah","followers_url":"https://api.github.com/users/knah/followers","following_url":"https://api.github.com/users/knah/following{/other_user}","gists_url":"https://api.github.com/users/knah/gists{/gist_id}","starred_url":"https://api.github.com/users/knah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knah/subscriptions","organizations_url":"https://api.github.com/users/knah/orgs","repos_url":"https://api.github.com/users/knah/repos","events_url":"https://api.github.com/users/knah/events{/privacy}","received_events_url":"https://api.github.com/users/knah/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/knah/lesson2","description":"","fork":true,"url":"https://api.github.com/repos/knah/lesson2","forks_url":"https://api.github.com/repos/knah/lesson2/forks","keys_url":"https://api.github.com/repos/knah/lesson2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/knah/lesson2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/knah/lesson2/teams","hooks_url":"https://api.github.com/repos/knah/lesson2/hooks","issue_events_url":"https://api.github.com/repos/knah/lesson2/issues/events{/number}","events_url":"https://api.github.com/repos/knah/lesson2/events","assignees_url":"https://api.github.com/repos/knah/lesson2/assignees{/user}","branches_url":"https://api.github.com/repos/knah/lesson2/branches{/branch}","tags_url":"https://api.github.com/repos/knah/lesson2/tags","blobs_url":"https://api.github.com/repos/knah/lesson2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/knah/lesson2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/knah/lesson2/git/refs{/sha}","trees_url":"https://api.github.com/repos/knah/lesson2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/knah/lesson2/statuses/{sha}","languages_url":"https://api.github.com/repos/knah/lesson2/languages","stargazers_url":"https://api.github.com/repos/knah/lesson2/stargazers","contributors_url":"https://api.github.com/repos/knah/lesson2/contributors","subscribers_url":"https://api.github.com/repos/knah/lesson2/subscribers","subscription_url":"https://api.github.com/repos/knah/lesson2/subscription","commits_url":"https://api.github.com/repos/knah/lesson2/commits{/sha}","git_commits_url":"https://api.github.com/repos/knah/lesson2/git/commits{/sha}","comments_url":"https://api.github.com/repos/knah/lesson2/comments{/number}","issue_comment_url":"https://api.github.com/repos/knah/lesson2/issues/comments/{number}","contents_url":"https://api.github.com/repos/knah/lesson2/contents/{+path}","compare_url":"https://api.github.com/repos/knah/lesson2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/knah/lesson2/merges","archive_url":"https://api.github.com/repos/knah/lesson2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/knah/lesson2/downloads","issues_url":"https://api.github.com/repos/knah/lesson2/issues{/number}","pulls_url":"https://api.github.com/repos/knah/lesson2/pulls{/number}","milestones_url":"https://api.github.com/repos/knah/lesson2/milestones{/number}","notifications_url":"https://api.github.com/repos/knah/lesson2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/knah/lesson2/labels{/name}","releases_url":"https://api.github.com/repos/knah/lesson2/releases{/id}","created_at":"2014-09-19T14:22:14Z","updated_at":"2014-09-20T15:56:01Z","pushed_at":"2014-09-20T16:07:32Z","git_url":"git://github.com/knah/lesson2.git","ssh_url":"git@github.com:knah/lesson2.git","clone_url":"https://github.com/knah/lesson2.git","svn_url":"https://github.com/knah/lesson2","homepage":null,"size":2286,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"IFMO-MobDev-2014:master","ref":"master","sha":"9b8bc9dcaabdafe4d3362f2b59ddb02eb35f548e","user":{"login":"IFMO-MobDev-2014","id":8738407,"avatar_url":"https://avatars.githubusercontent.com/u/8738407?v=3","gravatar_id":"","url":"https://api.github.com/users/IFMO-MobDev-2014","html_url":"https://github.com/IFMO-MobDev-2014","followers_url":"https://api.github.com/users/IFMO-MobDev-2014/followers","following_url":"https://api.github.com/users/IFMO-MobDev-2014/following{/other_user}","gists_url":"https://api.github.com/users/IFMO-MobDev-2014/gists{/gist_id}","starred_url":"https://api.github.com/users/IFMO-MobDev-2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IFMO-MobDev-2014/subscriptions","organizations_url":"https://api.github.com/users/IFMO-MobDev-2014/orgs","repos_url":"https://api.github.com/users/IFMO-MobDev-2014/repos","events_url":"https://api.github.com/users/IFMO-MobDev-2014/events{/privacy}","received_events_url":"https://api.github.com/users/IFMO-MobDev-2014/received_events","type":"Organization","site_admin":false},"repo":{"id":24223856,"name":"lesson2","full_name":"IFMO-MobDev-2014/lesson2","owner":{"login":"IFMO-MobDev-2014","id":8738407,"avatar_url":"https://avatars.githubusercontent.com/u/8738407?v=3","gravatar_id":"","url":"https://api.github.com/users/IFMO-MobDev-2014","html_url":"https://github.com/IFMO-MobDev-2014","followers_url":"https://api.github.com/users/IFMO-MobDev-2014/followers","following_url":"https://api.github.com/users/IFMO-MobDev-2014/following{/other_user}","gists_url":"https://api.github.com/users/IFMO-MobDev-2014/gists{/gist_id}","starred_url":"https://api.github.com/users/IFMO-MobDev-2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IFMO-MobDev-2014/subscriptions","organizations_url":"https://api.github.com/users/IFMO-MobDev-2014/orgs","repos_url":"https://api.github.com/users/IFMO-MobDev-2014/repos","events_url":"https://api.github.com/users/IFMO-MobDev-2014/events{/privacy}","received_events_url":"https://api.github.com/users/IFMO-MobDev-2014/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/IFMO-MobDev-2014/lesson2","description":"","fork":false,"url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2","forks_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/forks","keys_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/teams","hooks_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/hooks","issue_events_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/issues/events{/number}","events_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/events","assignees_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/assignees{/user}","branches_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/branches{/branch}","tags_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/tags","blobs_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/git/refs{/sha}","trees_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/statuses/{sha}","languages_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/languages","stargazers_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/stargazers","contributors_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/contributors","subscribers_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/subscribers","subscription_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/subscription","commits_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/commits{/sha}","git_commits_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/git/commits{/sha}","comments_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/comments{/number}","issue_comment_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/issues/comments/{number}","contents_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/contents/{+path}","compare_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/merges","archive_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/downloads","issues_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/issues{/number}","pulls_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls{/number}","milestones_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/milestones{/number}","notifications_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/labels{/name}","releases_url":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/releases{/id}","created_at":"2014-09-19T09:19:36Z","updated_at":"2014-09-24T16:10:59Z","pushed_at":"2014-09-19T14:43:35Z","git_url":"git://github.com/IFMO-MobDev-2014/lesson2.git","ssh_url":"git@github.com:IFMO-MobDev-2014/lesson2.git","clone_url":"https://github.com/IFMO-MobDev-2014/lesson2.git","svn_url":"https://github.com/IFMO-MobDev-2014/lesson2","homepage":null,"size":27197,"stargazers_count":1,"watchers_count":1,"language":"Groovy","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":91,"mirror_url":null,"open_issues_count":74,"forks":91,"open_issues":74,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3"},"html":{"href":"https://github.com/IFMO-MobDev-2014/lesson2/pull/3"},"issue":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/issues/3"},"comments":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/IFMO-MobDev-2014/lesson2/statuses/7d2fee7b73492ccf0fa768348ba8ffbf5eb85f57"}}}}