1 | // Need external definition of: scaleX, scaleY |
2 | |
3 | // Up to scaleX-1 pixel columns and scaleY pixel rows may be discarded |
4 | // (those not fitting in a scaleX*scaleY block). The discarded pixels are |
5 | // along the right and bottom border of the image, respectively. |
6 | |
7 | // Benchmark on screenshot for 1 MP: 2.6ms or less (twice as fast as scaleImage!) |
8 | |
9 | int w, h, w2, h2; |
10 | int[] finalPixels; |
11 | |
12 | void scaleDown(BufferedImage img) { |
13 | // TODO: remove the slow part |
14 | scaleDown(main grabbableIntPixels_fastOrSlow(img)); |
15 | } |
16 | |
17 | void scaleDown(GrabbableIntPixels gp) { |
18 | w = gp.w; |
19 | int h = this.h = gp.h; |
20 | int w2 = this.w2 = w/scaleX, h2 = this.h2 = h/scaleY; |
21 | int stride = gp.scanlineStride; |
22 | int scaleArea = scaleX*scaleY; |
23 | |
24 | int[] newPixels = finalPixels = new int[w2*h2]; |
25 | |
26 | int iRow = gp.offset, iOut = 0; |
27 | int[] pixels = gp.data; |
28 | |
29 | for y to h2: { |
30 | int iIn = iRow; |
31 | |
32 | for x to w2: { |
33 | // making one pixel of output image inside this block |
34 | |
35 | int r = 0, g = 0, b = 0; |
36 | |
37 | int iSub = iIn; |
38 | for subY to scaleY: { |
39 | for subX to scaleX: { |
40 | int rgb = pixels[iSub+subX]; |
41 | r += (rgb >> 16) & 0xFF; |
42 | g += (rgb >> 8) & 0xFF; |
43 | b += rgb & 0xFF; |
44 | } |
45 | iSub += stride; |
46 | } |
47 | |
48 | iIn += scaleX; // advance input scaleX pixels to the right |
49 | newPixels[iOut++] = rgbIntFullAlpha(r/scaleArea, g/scaleArea, b/scaleArea); |
50 | } |
51 | |
52 | iRow += stride*scaleY; |
53 | } // for y |
54 | } |
55 | |
56 | BufferedImage get(BufferedImage img) { |
57 | scaleDown(img); |
58 | ret get(); |
59 | } |
60 | |
61 | BufferedImage get() { |
62 | ret bufferedImage(w2, h2, finalPixels); |
63 | } |
64 | |
65 | GrabbableIntPixels grabbableIntPixels() { |
66 | ret GrabbableIntPixels(finalPixels, w2, h2, 0, w2); |
67 | } |
Began life as a copy of #1035219
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1035221 |
Snippet name: | FastDownscale Include v2 - do it all in one conversion. faster! |
Eternal ID of this version: | #1035221/6 |
Text MD5: | 697a189e688a1bb57fa41267363cc635 |
Author: | stefan |
Category: | javax |
Type: | JavaX (incomplete) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-12 02:23:24 |
Source code size: | 1882 bytes / 67 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 134 / 321 |
Version history: | 5 change(s) |
Referenced in: | [show references] |