0 && height > 0) && (currentWidth > width || currentHeight > height)){
264 | float widthScale = (float) width / currentWidth;
265 | float heightScale = (float) height / currentHeight;
266 | scale = Math.min(widthScale, heightScale);
267 | }
268 | return scale;
269 | }
270 |
271 | }
272 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/Utils/MemoryComputeUtil.java:
--------------------------------------------------------------------------------
1 | package com.light.core.Utils;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.light.body.Light;
6 |
7 | /**
8 | * Created by xiaoqi on 2017/11/22
9 | */
10 |
11 | public class MemoryComputeUtil {
12 | private final static String TAG = Light.TAG + "-MemoryComputeUtil";
13 |
14 | //单位kb
15 | public static int getMemorySize(Bitmap bitmap){
16 | Bitmap.Config config = bitmap.getConfig();
17 | int width = bitmap.getWidth();
18 | int height = bitmap.getHeight();
19 | L.e(TAG, "width:" + width + "height:"+ height);
20 | int totalSize;
21 | if(config.equals(Bitmap.Config.ALPHA_8)){
22 | totalSize = width * height;
23 | }else if(config.equals(Bitmap.Config.ARGB_4444)){
24 | totalSize = width * height * 2;
25 | }else if(config.equals(Bitmap.Config.RGB_565)){
26 | totalSize = width * height * 2;
27 | }else {
28 | //ARGB_8888
29 | totalSize = width * height * 4;
30 | }
31 | L.e(TAG, "totalMemorySize:"+ totalSize / 1024 +"kb");
32 | return totalSize / 1024;
33 | }
34 |
35 | public static int getMemorySize2(Bitmap bitmap){
36 | return bitmap.getByteCount();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/Utils/SimpleSizeCompute.java:
--------------------------------------------------------------------------------
1 | package com.light.core.Utils;
2 |
3 | import android.graphics.BitmapFactory;
4 |
5 | /**
6 | * Created by xiaoqi on 2017/11/22
7 | */
8 | public class SimpleSizeCompute {
9 |
10 | public static int computeSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) {
11 | int initialSize = computeInitialSampleSize(options, minSideLength, maxNumOfPixels);
12 | int roundedSize;
13 | if (initialSize <= 8) {
14 | roundedSize = 1;
15 | while (roundedSize < initialSize) {
16 | roundedSize <<= 1;
17 | }
18 | } else {
19 | roundedSize = (initialSize + 7) / 8 * 8;
20 | }
21 | if(Math.max(options.outWidth, options.outHeight) / roundedSize < minSideLength){
22 | roundedSize >>= 1;
23 | }
24 | return roundedSize;
25 | }
26 |
27 | private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) {
28 | double w = options.outWidth;
29 | double h = options.outHeight;
30 | int lowerBound = (maxNumOfPixels <0 ) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));
31 | int upperBound = (minSideLength <0) ? 128 :(int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength));
32 | if (upperBound < lowerBound) {
33 | return lowerBound;
34 | }
35 | if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
36 | return 1;
37 | } else if (minSideLength == -1) {
38 | return lowerBound;
39 | } else {
40 | return upperBound;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/Utils/UriParser.java:
--------------------------------------------------------------------------------
1 | package com.light.core.Utils;
2 |
3 | import android.database.Cursor;
4 | import android.net.Uri;
5 | import android.provider.MediaStore;
6 |
7 | import com.light.body.Light;
8 |
9 | /**
10 | * Created by xiaoqi on 2017/11/24
11 | */
12 |
13 | public class UriParser {
14 |
15 | /**
16 | * http scheme for URIs.
17 | */
18 | public static final String HTTP_SCHEME = "http";
19 |
20 | /**
21 | * https scheme for URIs.
22 | */
23 | public static final String HTTPS_SCHEME = "https";
24 |
25 | /**
26 | * File scheme for URIs.
27 | */
28 | public static final String LOCAL_FILE_SCHEME = "file";
29 |
30 | /**
31 | * Content URI scheme for URIs.
32 | */
33 | public static final String LOCAL_CONTENT_SCHEME = "content";
34 |
35 | /**
36 | * Asset scheme for URIs.
37 | */
38 | public static final String LOCAL_ASSET_SCHEME = "asset";
39 |
40 | /**
41 | * Resource scheme for URIs.
42 | */
43 | public static final String LOCAL_RESOURCE_SCHEME = "res";
44 |
45 |
46 | /**
47 | * android.resource scheme for URIs.
48 | */
49 | public static final String LOCAL_ANDROID_RESOURCE_SCHEME = "android.resource";
50 |
51 |
52 | /**
53 | * Data scheme for URIs.
54 | */
55 | public static final String DATA_SCHEME = "data";
56 |
57 | /**
58 | * /**
59 | * Check if uri represents network resource.
60 | *
61 | * @param uri uri to check.
62 | * @return true if uri's scheme is equal to "http" or "https".
63 | */
64 | public static boolean isNetworkUri(Uri uri) {
65 | final String scheme = getSchemeOrNull(uri);
66 | return HTTPS_SCHEME.equals(scheme) || HTTP_SCHEME.equals(scheme);
67 | }
68 |
69 | /**
70 | * Check if uri represents local file.
71 | *
72 | * @param uri uri to check.
73 | * @return true if uri's scheme is equal to "file".
74 | */
75 | public static boolean isLocalFileUri(Uri uri) {
76 | final String scheme = getSchemeOrNull(uri);
77 | return LOCAL_FILE_SCHEME.equals(scheme);
78 | }
79 |
80 | /**
81 | * Check if uri represents local content.
82 | *
83 | * @param uri uri to check.
84 | * @return true if uri's scheme is equal to "content".
85 | */
86 | public static boolean isLocalContentUri(Uri uri) {
87 | final String scheme = getSchemeOrNull(uri);
88 | return LOCAL_CONTENT_SCHEME.equals(scheme);
89 | }
90 |
91 | /**
92 | * Check if uri represents local asset.
93 | *
94 | * @param uri uri to check.
95 | * @return true if uri's scheme is equal to "asset".
96 | */
97 | public static boolean isLocalAssetUri(Uri uri) {
98 | final String scheme = getSchemeOrNull(uri);
99 | return LOCAL_ASSET_SCHEME.equals(scheme);
100 | }
101 |
102 | /**
103 | * Check if uri represents local resource.
104 | *
105 | * @param uri uri to check.
106 | * @return true if uri's scheme is equal to {@link #LOCAL_RESOURCE_SCHEME}.
107 | */
108 | public static boolean isLocalResourceUri(Uri uri) {
109 | final String scheme = getSchemeOrNull(uri);
110 | return LOCAL_RESOURCE_SCHEME.equals(scheme);
111 | }
112 |
113 | public static boolean isLocalAnroidResourceUri(Uri uri) {
114 | final String scheme = getSchemeOrNull(uri);
115 | return LOCAL_ANDROID_RESOURCE_SCHEME.equals(scheme);
116 | }
117 |
118 | /**
119 | * Check if the uri is a data uri.
120 | */
121 | public static boolean isDataUri(Uri uri) {
122 | return DATA_SCHEME.equals(getSchemeOrNull(uri));
123 | }
124 |
125 | /**
126 | * @param uri uri to extract scheme from, possibly null.
127 | * @return null if uri is null, result of uri.getScheme() otherwise.
128 | */
129 | public static String getSchemeOrNull(Uri uri) {
130 | return uri == null ? null : uri.getScheme();
131 | }
132 |
133 | /**
134 | * A wrapper around {@link Uri#parse} that returns null if the input is null.
135 | *
136 | * @param uriAsString the uri as a string.
137 | * @return the parsed Uri or null if the input was null.
138 | */
139 | public static Uri parseUriOrNull(String uriAsString) {
140 | return uriAsString != null ? Uri.parse(uriAsString) : null;
141 | }
142 |
143 | public static String getPathFromFileUri(final Uri srcUri) {
144 | return srcUri.getPath();
145 | }
146 |
147 | public static String getAbsPath(final Uri srcUri) {
148 | return srcUri.toString();
149 | }
150 |
151 |
152 | public static String getPathFromContentUri(final Uri srcUri) {
153 | String result = null;
154 | String[] proj = { MediaStore.Images.Media.DATA };
155 | Cursor cursor = Light.getInstance().getContext().getContentResolver().query(srcUri, proj, null, null,
156 | null);
157 | if (cursor != null) {
158 | cursor.moveToFirst();
159 | int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
160 | if(idx >= 0){
161 | result = cursor.getString(idx);
162 | }
163 | cursor.close();
164 | }
165 | if(result == null){
166 | throw new RuntimeException("Uri pares error!");
167 | }
168 | return result;
169 | }
170 | }
171 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/Utils/http/HttpDownLoader.java:
--------------------------------------------------------------------------------
1 | package com.light.core.Utils.http;
2 |
3 | import android.net.Uri;
4 | import android.text.TextUtils;
5 |
6 | import com.light.body.LightCache;
7 | import com.light.core.Utils.UriParser;
8 | import com.light.core.listener.OnCompressFinishListener;
9 |
10 | import java.io.ByteArrayOutputStream;
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.net.HttpURLConnection;
14 | import java.net.MalformedURLException;
15 | import java.net.URL;
16 |
17 | /**
18 | * Created by xiaoqi on 2017/12/20
19 | */
20 | public class HttpDownLoader {
21 |
22 | private static final int MAX_REDIRECTS = 5;
23 |
24 | private static final int HTTP_TEMPORARY_REDIRECT = 307;
25 |
26 | private static final int HTTP_PERMANENT_REDIRECT = 308;
27 |
28 | private static final int TIMEOUT = 30000;
29 |
30 | public static void downloadImage(boolean openDiskCache, String url, OnCompressFinishListener callback) {
31 | if (TextUtils.isEmpty(url))
32 | return;
33 | Uri uri = Uri.parse(url);
34 | downloadImage(openDiskCache, uri, callback);
35 | }
36 |
37 | public static void downloadImage(boolean openDiskCache, Uri uri, OnCompressFinishListener callback) {
38 | if (!UriParser.isNetworkUri(uri)){
39 | callback.onError(new Exception("uri is not net uri"));
40 | return;
41 | }
42 |
43 | HttpURLConnection connection = obtainHttpURLConnection(uri, MAX_REDIRECTS);
44 | InputStream is = null;
45 | if (connection == null){
46 | callback.onError(new Exception("get connection error"));
47 | return;
48 | }
49 | try {
50 | is = connection.getInputStream();
51 | if (callback != null){
52 | byte[] bytes = transformToByteArray(is);
53 | if(openDiskCache){
54 | LightCache.getInstance().save(UriParser.getAbsPath(uri), bytes);
55 | }
56 | callback.onFinish(bytes);
57 | }
58 | } catch (IOException e) {
59 | e.printStackTrace();
60 | callback.onError(e);
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | callback.onError(e);
64 | } finally {
65 | if (is != null) {
66 | try {
67 | is.close();
68 | } catch (IOException e) {
69 | e.printStackTrace();
70 | }
71 | }
72 | if (connection != null) {
73 | connection.disconnect();
74 | }
75 | }
76 | }
77 |
78 | public static byte[] downloadImage(String url) {
79 | if (TextUtils.isEmpty(url)){
80 | return null;
81 | }
82 | Uri uri = Uri.parse(url);
83 | return downloadImage(uri);
84 | }
85 |
86 | public static byte[] downloadImage(Uri uri) {
87 | if (!UriParser.isNetworkUri(uri)){
88 | return null;
89 | }
90 |
91 | HttpURLConnection connection = obtainHttpURLConnection(uri, MAX_REDIRECTS);
92 | InputStream is = null;
93 |
94 | if (connection == null){
95 | return null;
96 | }
97 | try {
98 | is = connection.getInputStream();
99 | return transformToByteArray(is);
100 | } catch (IOException e) {
101 | e.printStackTrace();
102 | } catch (Exception e) {
103 | e.printStackTrace();
104 | } finally {
105 | if (is != null) {
106 | try {
107 | is.close();
108 | } catch (IOException e) {
109 | e.printStackTrace();
110 | }
111 | }
112 | if (connection != null) {
113 | connection.disconnect();
114 | }
115 | }
116 | return null;
117 | }
118 |
119 | private static HttpURLConnection obtainHttpURLConnection(Uri uri, int maxRedirects) {
120 | if (uri == null){
121 | return null;
122 | }
123 | HttpURLConnection connection = null;
124 | try {
125 | URL url = new URL(uri.toString());
126 | connection = (HttpURLConnection) url.openConnection();
127 | connection.setConnectTimeout(TIMEOUT);
128 | connection.setReadTimeout(TIMEOUT);
129 | connection.connect();
130 | int responseCode = connection.getResponseCode();
131 | if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < HttpURLConnection.HTTP_MULT_CHOICE){
132 | return connection;
133 | }
134 |
135 | if (isHttpRedirect(responseCode)) {
136 | String nextUriString = connection.getHeaderField("Location");
137 | connection.disconnect();
138 | Uri nextUri = nextUriString == null ? null : Uri.parse(nextUriString);
139 | String originalScheme = uri.getScheme();
140 | if (maxRedirects > 0 && nextUri != null && !nextUri.getScheme().equals(originalScheme)) {
141 | return obtainHttpURLConnection(nextUri, maxRedirects - 1);
142 | } else {
143 | String message = maxRedirects == 0
144 | ? "URL %s follows too many redirects, uri:" + uri.toString()
145 | : "URL %s returned %d without a valid redirect, uri:" + uri.toString() + ", responseCode:" + responseCode;
146 | throw new RuntimeException(message);
147 | }
148 | } else {
149 | connection.disconnect();
150 | connection = null;
151 | }
152 |
153 | } catch (MalformedURLException e) {
154 | connection = null;
155 | e.printStackTrace();
156 | } catch (IOException e) {
157 | connection = null;
158 | e.printStackTrace();
159 | } catch (Exception e) {
160 | connection = null;
161 | e.printStackTrace();
162 | }
163 | return connection;
164 | }
165 |
166 | private static boolean isHttpRedirect(int responseCode) {
167 | switch (responseCode) {
168 | case HttpURLConnection.HTTP_MULT_CHOICE:
169 | case HttpURLConnection.HTTP_MOVED_PERM:
170 | case HttpURLConnection.HTTP_MOVED_TEMP:
171 | case HttpURLConnection.HTTP_SEE_OTHER:
172 | case HTTP_TEMPORARY_REDIRECT:
173 | case HTTP_PERMANENT_REDIRECT:
174 | return true;
175 | default:
176 | return false;
177 | }
178 | }
179 |
180 |
181 | public static byte[] transformToByteArray(InputStream is) {
182 | if (is == null)
183 | return new byte[0];
184 | ByteArrayOutputStream bos = new ByteArrayOutputStream();
185 | byte[] buffer = new byte[4096];
186 | int len = -1;
187 | try {
188 | while ((len = is.read(buffer)) != -1) {
189 | bos.write(buffer, 0, len);
190 | }
191 | } catch (Exception e) {
192 | e.printStackTrace();
193 | return new byte[0];
194 | } finally {
195 | try {
196 | bos.close();
197 | } catch (IOException e) {
198 | e.printStackTrace();
199 | }
200 | }
201 | return bos.toByteArray();
202 | }
203 |
204 | }
205 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/cache/CacheKey.java:
--------------------------------------------------------------------------------
1 | package com.light.core.cache;
2 |
3 | import java.security.MessageDigest;
4 | import java.security.NoSuchAlgorithmException;
5 |
6 | public class CacheKey {
7 |
8 | public static String hashKeyForDisk(String key) {
9 | String cacheKey;
10 | try {
11 | final MessageDigest mDigest = MessageDigest.getInstance("MD5");
12 | mDigest.update(key.getBytes());
13 | cacheKey = bytesToHexString(mDigest.digest());
14 | } catch (NoSuchAlgorithmException e) {
15 | cacheKey = String.valueOf(key.hashCode());
16 | }
17 | return cacheKey;
18 | }
19 |
20 | private static String bytesToHexString(byte[] bytes) {
21 | StringBuilder sb = new StringBuilder();
22 | for (int i = 0; i < bytes.length; i++) {
23 | String hex = Integer.toHexString(0xFF & bytes[i]);
24 | if (hex.length() == 1) {
25 | sb.append('0');
26 | }
27 | sb.append(hex);
28 | }
29 | return sb.toString();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/cache/StrictLineReader.java:
--------------------------------------------------------------------------------
1 | package com.light.core.cache;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.Closeable;
5 | import java.io.EOFException;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.UnsupportedEncodingException;
9 | import java.nio.charset.Charset;
10 |
11 | /**
12 | * Buffers input from an {@link InputStream} for reading lines.
13 | *
14 | * This class is used for buffered reading of lines. For purposes of this class, a line ends
15 | * with "\n" or "\r\n". End of input is reported by throwing {@code EOFException}. Unterminated
16 | * line at end of input is invalid and will be ignored, the caller may use {@code
17 | * hasUnterminatedLine()} to detect it after catching the {@code EOFException}.
18 | *
19 | *
This class is intended for reading input that strictly consists of lines, such as line-based
20 | * cache entries or cache journal. Unlike the {@link java.io.BufferedReader} which in conjunction
21 | * with {@link java.io.InputStreamReader} provides similar functionality, this class uses different
22 | * end-of-input reporting and a more restrictive definition of a line.
23 | *
24 | *
This class supports only charsets that encode '\r' and '\n' as a single byte with value 13
25 | * and 10, respectively, and the representation of no other character contains these values.
26 | * We currently check in constructor that the charset is one of US-ASCII, UTF-8 and ISO-8859-1.
27 | * The default charset is US_ASCII.
28 | */
29 | class StrictLineReader implements Closeable {
30 | private static final byte CR = (byte) '\r';
31 | private static final byte LF = (byte) '\n';
32 |
33 | private final InputStream in;
34 | private final Charset charset;
35 |
36 | /*
37 | * Buffered data is stored in {@code buf}. As long as no exception occurs, 0 <= pos <= end
38 | * and the data in the range [pos, end) is buffered for reading. At end of input, if there is
39 | * an unterminated line, we set end == -1, otherwise end == pos. If the underlying
40 | * {@code InputStream} throws an {@code IOException}, end may remain as either pos or -1.
41 | */
42 | private byte[] buf;
43 | private int pos;
44 | private int end;
45 |
46 | /**
47 | * Constructs a new {@code LineReader} with the specified charset and the default capacity.
48 | *
49 | * @param in the {@code InputStream} to read data from.
50 | * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
51 | * supported.
52 | * @throws NullPointerException if {@code in} or {@code charset} is null.
53 | * @throws IllegalArgumentException if the specified charset is not supported.
54 | */
55 | public StrictLineReader(InputStream in, Charset charset) {
56 | this(in, 8192, charset);
57 | }
58 |
59 | /**
60 | * Constructs a new {@code LineReader} with the specified capacity and charset.
61 | *
62 | * @param in the {@code InputStream} to read data from.
63 | * @param capacity the capacity of the buffer.
64 | * @param charset the charset used to decode data. Only US-ASCII, UTF-8 and ISO-8859-1 are
65 | * supported.
66 | * @throws NullPointerException if {@code in} or {@code charset} is null.
67 | * @throws IllegalArgumentException if {@code capacity} is negative or zero
68 | * or the specified charset is not supported.
69 | */
70 | public StrictLineReader(InputStream in, int capacity, Charset charset) {
71 | if (in == null || charset == null) {
72 | throw new NullPointerException();
73 | }
74 | if (capacity < 0) {
75 | throw new IllegalArgumentException("capacity <= 0");
76 | }
77 | if (!(charset.equals(Util.US_ASCII))) {
78 | throw new IllegalArgumentException("Unsupported encoding");
79 | }
80 |
81 | this.in = in;
82 | this.charset = charset;
83 | buf = new byte[capacity];
84 | }
85 |
86 | /**
87 | * Closes the reader by closing the underlying {@code InputStream} and
88 | * marking this reader as closed.
89 | *
90 | * @throws IOException for errors when closing the underlying {@code InputStream}.
91 | */
92 | public void close() throws IOException {
93 | synchronized (in) {
94 | if (buf != null) {
95 | buf = null;
96 | in.close();
97 | }
98 | }
99 | }
100 |
101 | /**
102 | * Reads the next line. A line ends with {@code "\n"} or {@code "\r\n"},
103 | * this end of line marker is not included in the result.
104 | *
105 | * @return the next line from the input.
106 | * @throws IOException for underlying {@code InputStream} errors.
107 | * @throws EOFException for the end of source stream.
108 | */
109 | public String readLine() throws IOException {
110 | synchronized (in) {
111 | if (buf == null) {
112 | throw new IOException("LineReader is closed");
113 | }
114 |
115 | // Read more data if we are at the end of the buffered data.
116 | // Though it's an error to read after an exception, we will let {@code fillBuf()}
117 | // throw again if that happens; thus we need to handle end == -1 as well as end == pos.
118 | if (pos >= end) {
119 | fillBuf();
120 | }
121 | // Try to find LF in the buffered data and return the line if successful.
122 | for (int i = pos; i != end; ++i) {
123 | if (buf[i] == LF) {
124 | int lineEnd = (i != pos && buf[i - 1] == CR) ? i - 1 : i;
125 | String res = new String(buf, pos, lineEnd - pos, charset.name());
126 | pos = i + 1;
127 | return res;
128 | }
129 | }
130 |
131 | // Let's anticipate up to 80 characters on top of those already read.
132 | ByteArrayOutputStream out = new ByteArrayOutputStream(end - pos + 80) {
133 | @Override
134 | public String toString() {
135 | int length = (count > 0 && buf[count - 1] == CR) ? count - 1 : count;
136 | try {
137 | return new String(buf, 0, length, charset.name());
138 | } catch (UnsupportedEncodingException e) {
139 | throw new AssertionError(e); // Since we control the charset this will never happen.
140 | }
141 | }
142 | };
143 |
144 | while (true) {
145 | out.write(buf, pos, end - pos);
146 | // Mark unterminated line in case fillBuf throws EOFException or IOException.
147 | end = -1;
148 | fillBuf();
149 | // Try to find LF in the buffered data and return the line if successful.
150 | for (int i = pos; i != end; ++i) {
151 | if (buf[i] == LF) {
152 | if (i != pos) {
153 | out.write(buf, pos, i - pos);
154 | }
155 | pos = i + 1;
156 | return out.toString();
157 | }
158 | }
159 | }
160 | }
161 | }
162 |
163 | public boolean hasUnterminatedLine() {
164 | return end == -1;
165 | }
166 |
167 | /**
168 | * Reads new input data into the buffer. Call only with pos == end or end == -1,
169 | * depending on the desired outcome if the function throws.
170 | */
171 | private void fillBuf() throws IOException {
172 | int result = in.read(buf, 0, buf.length);
173 | if (result == -1) {
174 | throw new EOFException();
175 | }
176 | pos = 0;
177 | end = result;
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/cache/Util.java:
--------------------------------------------------------------------------------
1 | package com.light.core.cache;
2 |
3 | import android.support.annotation.NonNull;
4 |
5 | import java.io.Closeable;
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.io.Reader;
9 | import java.io.StringWriter;
10 | import java.nio.charset.Charset;
11 |
12 | /** Junk drawer of utility methods. */
13 | public final class Util {
14 | static final Charset US_ASCII = Charset.forName("US-ASCII");
15 | static final Charset UTF_8 = Charset.forName("UTF-8");
16 |
17 | private Util() {
18 | }
19 |
20 | static String readFully(Reader reader) throws IOException {
21 | try {
22 | StringWriter writer = new StringWriter();
23 | char[] buffer = new char[1024];
24 | int count;
25 | while ((count = reader.read(buffer)) != -1) {
26 | writer.write(buffer, 0, count);
27 | }
28 | return writer.toString();
29 | } finally {
30 | reader.close();
31 | }
32 | }
33 |
34 | /**
35 | * Deletes the contents of {@code dir}. Throws an IOException if any file
36 | * could not be deleted, or if {@code dir} is not a readable directory.
37 | */
38 | static void deleteContents(File dir) throws IOException {
39 | File[] files = dir.listFiles();
40 | if (files == null) {
41 | throw new IOException("not a readable directory: " + dir);
42 | }
43 | for (File file : files) {
44 | if (file.isDirectory()) {
45 | deleteContents(file);
46 | }
47 | if (!file.delete()) {
48 | throw new IOException("failed to delete file: " + file);
49 | }
50 | }
51 | }
52 |
53 | static void closeQuietly(/*Auto*/Closeable closeable) {
54 | if (closeable != null) {
55 | try {
56 | closeable.close();
57 | } catch (RuntimeException rethrown) {
58 | throw rethrown;
59 | } catch (Exception ignored) {
60 | }
61 | }
62 | }
63 |
64 | private static final char[] HEX_CHAR_ARRAY = "0123456789abcdef".toCharArray();
65 | private static final char[] SHA_256_CHARS = new char[64];
66 |
67 | public static String sha256BytesToHex(@NonNull byte[] bytes) {
68 | synchronized (SHA_256_CHARS) {
69 | return bytesToHex(bytes, SHA_256_CHARS);
70 | }
71 | }
72 |
73 | private static String bytesToHex(@NonNull byte[] bytes, @NonNull char[] hexChars) {
74 | int v;
75 | for (int j = 0; j < bytes.length; j++) {
76 | v = bytes[j] & 0xFF;
77 | hexChars[j * 2] = HEX_CHAR_ARRAY[v >>> 4];
78 | hexChars[j * 2 + 1] = HEX_CHAR_ARRAY[v & 0x0F];
79 | }
80 | return new String(hexChars);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/listener/ICompressEngine.java:
--------------------------------------------------------------------------------
1 | package com.light.core.listener;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 |
6 | import java.util.List;
7 |
8 | /**
9 | * Created by xiaoqi on 2017/11/22
10 | */
11 |
12 | public interface ICompressEngine {
13 |
14 | Bitmap compress2Bitmap(Bitmap bitmap, int width, int height, Bitmap.Config config);
15 |
16 | Bitmap compress2Bitmap(String imagePath, int width, int height, Bitmap.Config config);
17 |
18 | Bitmap compress2Bitmap(int resId, int width, int height, Bitmap.Config config);
19 |
20 | Bitmap compress2Bitmap(byte[] bytes, int width, int height, Bitmap.Config config);
21 |
22 | boolean compress2File(Bitmap bitmap, String outputPath, int quality);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/listener/ICompressProxy.java:
--------------------------------------------------------------------------------
1 | package com.light.core.listener;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | /**
6 | * Created by xiaoqi on 2017/11/25
7 | */
8 |
9 | public interface ICompressProxy {
10 |
11 | boolean compress(String outPath);
12 |
13 | Bitmap compress();
14 | }
15 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/listener/OnAsyncCompressFinishListener.java:
--------------------------------------------------------------------------------
1 | package com.light.core.listener;
2 |
3 | /**
4 | * Created by xiaoqi on 2017/11/24
5 | */
6 |
7 | public interface OnAsyncCompressFinishListener {
8 |
9 | void onFinish(boolean result);
10 | }
11 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/core/listener/OnCompressFinishListener.java:
--------------------------------------------------------------------------------
1 | package com.light.core.listener;
2 |
3 | /**
4 | * Created by xiaoqi on 2017/11/24
5 | */
6 |
7 | public interface OnCompressFinishListener {
8 |
9 | void onFinish(byte[] bytes);
10 |
11 | void onError(Throwable throwable);
12 | }
13 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/proxy/BitmapCompressProxy.java:
--------------------------------------------------------------------------------
1 | package com.light.proxy;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.light.body.CompressArgs;
6 | import com.light.body.Light;
7 | import com.light.body.LightConfig;
8 | import com.light.core.LightCompressEngine;
9 | import com.light.core.Utils.MatrixUtil;
10 | import com.light.core.listener.ICompressEngine;
11 | import com.light.core.listener.ICompressProxy;
12 |
13 | /**
14 | * Created by xiaoqi on 2017/11/25
15 | */
16 |
17 | public class BitmapCompressProxy implements ICompressProxy {
18 |
19 | private Bitmap bitmap;
20 | private LightConfig lightConfig;
21 | private ICompressEngine compressEngine;
22 | private CompressArgs compressArgs;
23 |
24 | private BitmapCompressProxy() {
25 | lightConfig = Light.getInstance().getConfig();
26 | compressEngine = new LightCompressEngine();
27 | }
28 |
29 | @Override
30 | public boolean compress(String outPath) {
31 | int quality = compressArgs.getQuality();
32 | if(quality <= 0 || quality > 100){
33 | quality = lightConfig.getDefaultQuality();
34 | }
35 | if(outPath == null){
36 | outPath = lightConfig.getOutputRootDir();
37 | }
38 | return compressEngine.compress2File(compress(), outPath, quality);
39 | }
40 |
41 | @Override
42 | public Bitmap compress() {
43 | int resultWidth;
44 | int resultHeight;
45 | if(!compressArgs.isIgnoreSize() && compressArgs.getWidth() > 0 && compressArgs.getHeight() >0){
46 | resultWidth = compressArgs.getWidth();
47 | resultHeight = compressArgs.getHeight();
48 | }else if(!compressArgs.isIgnoreSize()){
49 | resultWidth = Math.min(lightConfig.getMaxWidth(), bitmap.getWidth());
50 | resultHeight = Math.min(lightConfig.getMaxHeight(), bitmap.getHeight());
51 | }else {
52 | resultWidth = bitmap.getWidth();
53 | resultHeight = bitmap.getHeight();
54 | }
55 | Bitmap result = compressEngine.compress2Bitmap(bitmap, resultWidth, resultHeight, compressArgs.getConfig());
56 | if(compressArgs.isAutoRecycle()){
57 | bitmap.recycle();
58 | }
59 | float scaleSize = MatrixUtil.getScale(resultWidth, resultHeight, result.getWidth(), result.getHeight());
60 | if(scaleSize < 1){
61 | return new MatrixUtil.Build().scale(scaleSize, scaleSize).bitmap(result).build();
62 | }
63 | return result;
64 | }
65 |
66 | public static class Builder {
67 | private Bitmap bitmap;
68 | private CompressArgs compressArgs;
69 |
70 | public Builder bitmap(Bitmap bitmap) {
71 | this.bitmap = bitmap;
72 | return this;
73 | }
74 |
75 | public Builder compressArgs(CompressArgs compressArgs) {
76 | this.compressArgs = compressArgs;
77 | return this;
78 | }
79 |
80 | public BitmapCompressProxy build(){
81 | if(bitmap == null){
82 | throw new RuntimeException("bitmap is empty");
83 | }
84 | BitmapCompressProxy proxy = new BitmapCompressProxy();
85 | proxy.bitmap = bitmap;
86 | if(compressArgs == null){
87 | proxy.compressArgs = CompressArgs.getDefaultArgs();
88 | }else {
89 | proxy.compressArgs = compressArgs;
90 | }
91 | return proxy;
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/proxy/BytesCompressProxy.java:
--------------------------------------------------------------------------------
1 | package com.light.proxy;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 |
6 | import com.light.body.CompressArgs;
7 | import com.light.body.Light;
8 | import com.light.body.LightConfig;
9 | import com.light.core.LightCompressEngine;
10 | import com.light.core.Utils.MatrixUtil;
11 | import com.light.core.listener.ICompressEngine;
12 | import com.light.core.listener.ICompressProxy;
13 |
14 | import java.io.ByteArrayInputStream;
15 | import java.io.IOException;
16 | import java.io.InputStream;
17 |
18 | /**
19 | * Created by xiaoqi on 2017/11/25
20 | */
21 |
22 | public class BytesCompressProxy implements ICompressProxy {
23 | private byte[] bytes;
24 | private LightConfig lightConfig;
25 | private ICompressEngine compressEngine;
26 | private CompressArgs compressArgs;
27 |
28 | private BytesCompressProxy() {
29 | lightConfig = Light.getInstance().getConfig();
30 | compressEngine = new LightCompressEngine();
31 | }
32 |
33 | @Override
34 | public boolean compress(String outPath) {
35 | int quality = compressArgs.getQuality();
36 | if(quality <= 0 || quality > 100){
37 | quality = lightConfig.getDefaultQuality();
38 | }
39 | if(outPath == null){
40 | outPath = lightConfig.getOutputRootDir();
41 | }
42 | Bitmap bitmap = compress();
43 | try {
44 | return compressEngine.compress2File(bitmap, outPath, quality);
45 | }finally {
46 | if(bitmap != null && !bitmap.isRecycled()){
47 | bitmap.recycle();
48 | }
49 | }
50 | }
51 |
52 | @Override
53 | public Bitmap compress() {
54 | int resultWidth;
55 | int resultHeight;
56 | if(!compressArgs.isIgnoreSize() && compressArgs.getWidth() > 0 && compressArgs.getHeight() >0){
57 | resultWidth = compressArgs.getWidth();
58 | resultHeight = compressArgs.getHeight();
59 | }else {
60 | InputStream input = null;
61 | try {
62 | input = new ByteArrayInputStream(bytes);
63 | BitmapFactory.Options options = new BitmapFactory.Options();
64 | options.inJustDecodeBounds = true;
65 | BitmapFactory.decodeStream(input, null, options);
66 | if(compressArgs.isIgnoreSize()){
67 | resultWidth = options.outWidth;
68 | resultHeight = options.outHeight;
69 | }else {
70 | resultWidth = Math.min(lightConfig.getMaxWidth(), options.outWidth);
71 | resultHeight = Math.min(lightConfig.getMaxHeight(), options.outHeight);
72 | }
73 |
74 | }finally {
75 | if(input != null){
76 | try {
77 | input.close();
78 | } catch (IOException e) {
79 | e.printStackTrace();
80 | }
81 | }
82 | }
83 | }
84 | Bitmap result = compressEngine.compress2Bitmap(bytes, resultWidth, resultHeight, compressArgs.getConfig());
85 | if(compressArgs.isAutoRecycle()){
86 | bytes = null;
87 | }
88 | float scaleSize = MatrixUtil.getScale(resultWidth, resultHeight, result.getWidth(), result.getHeight());
89 | if(scaleSize < 1){
90 | return new MatrixUtil.Build().scale(scaleSize, scaleSize).bitmap(result).build();
91 | }
92 | return result;
93 | }
94 |
95 | public static class Builder {
96 | private byte[] bytes;
97 | private CompressArgs compressArgs;
98 |
99 | public Builder bytes(byte[] bytes) {
100 | this.bytes = bytes;
101 | return this;
102 | }
103 |
104 | public Builder compressArgs(CompressArgs compressArgs) {
105 | this.compressArgs = compressArgs;
106 | return this;
107 | }
108 |
109 | public BytesCompressProxy build(){
110 | if(bytes == null || bytes.length == 0){
111 | throw new RuntimeException("bytes is empty");
112 | }
113 | BytesCompressProxy proxy = new BytesCompressProxy();
114 | proxy.bytes = bytes;
115 | if(compressArgs == null){
116 | proxy.compressArgs = CompressArgs.getDefaultArgs();
117 | }else {
118 | proxy.compressArgs = compressArgs;
119 | }
120 | return proxy;
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/proxy/CompressFactory.java:
--------------------------------------------------------------------------------
1 | package com.light.proxy;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.drawable.Drawable;
5 | import android.net.Uri;
6 |
7 | import com.light.body.CompressArgs;
8 | import com.light.core.listener.ICompressProxy;
9 |
10 | /**
11 | * Created by xiaoqi on 2018/1/9
12 | */
13 |
14 | public class CompressFactory {
15 |
16 | public enum Compress {
17 | Bitmap, Bytes, File, Resource, Uri
18 | }
19 |
20 | public static ICompressProxy createCompress(Compress compressCategory, CompressArgs compressArgs, Object object) {
21 | ICompressProxy proxy;
22 | switch (compressCategory){
23 | case Uri:
24 | proxy = new UriCompressProxy.Builder().compressArgs(compressArgs).uri((Uri) object).build();
25 | break;
26 | case File:
27 | proxy = new FileCompressProxy.Builder().compressArgs(compressArgs).path((String) object).build();
28 | break;
29 | case Bytes:
30 | proxy = new BytesCompressProxy.Builder().compressArgs(compressArgs).bytes((byte[]) object).build();
31 | break;
32 | case Bitmap:
33 | proxy = new BitmapCompressProxy.Builder().compressArgs(compressArgs).bitmap((Bitmap) object).build();
34 | break;
35 | case Resource:
36 | ResourcesCompressProxy.Builder builder = new ResourcesCompressProxy.Builder();
37 | if(object instanceof Drawable){
38 | builder.drawable((Drawable) object);
39 | }else {
40 | builder.resource((int) object);
41 | }
42 | proxy = builder.compressArgs(compressArgs).build();
43 | break;
44 | default:
45 | proxy = null;
46 | }
47 | return proxy;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/proxy/FileCompressProxy.java:
--------------------------------------------------------------------------------
1 | package com.light.proxy;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.os.Looper;
6 |
7 | import com.light.body.CompressArgs;
8 | import com.light.body.Light;
9 | import com.light.body.LightConfig;
10 | import com.light.core.LightCompressEngine;
11 | import com.light.core.Utils.DegreeHelper;
12 | import com.light.core.Utils.FileUtils;
13 | import com.light.core.Utils.L;
14 | import com.light.core.Utils.MatrixUtil;
15 | import com.light.core.Utils.http.HttpDownLoader;
16 | import com.light.core.listener.ICompressEngine;
17 | import com.light.core.listener.ICompressProxy;
18 | import com.light.core.listener.OnCompressFinishListener;
19 |
20 | import java.io.File;
21 | import java.io.IOException;
22 | import java.nio.file.Files;
23 |
24 | /**
25 | * Created by xiaoqi on 2017/11/25
26 | */
27 |
28 | public class FileCompressProxy implements ICompressProxy {
29 |
30 | private String path;
31 | private LightConfig lightConfig;
32 | private ICompressEngine compressEngine;
33 | private CompressArgs compressArgs;
34 |
35 | public FileCompressProxy(){
36 | lightConfig = Light.getInstance().getConfig();
37 | compressEngine = new LightCompressEngine();
38 | }
39 |
40 | @Override
41 | public boolean compress(String outPath) {
42 | int quality = compressArgs.getQuality();
43 | if(quality <= 0 || quality > 100){
44 | quality = lightConfig.getDefaultQuality();
45 | }
46 | if(outPath == null){
47 | outPath = lightConfig.getOutputRootDir();
48 | }
49 | int compressFileSize = lightConfig.getCompressFileSize();
50 | if(compressArgs.getCompressFileSize() > 0){
51 | compressFileSize = compressArgs.getCompressFileSize();
52 | }
53 |
54 | if(compressFileSize > 0 && new File(path).length() / 1024 < compressFileSize){
55 | try {
56 | L.d("copyFile");
57 | return FileUtils.copyFile(new File(path), new File(outPath));
58 | } catch (IOException e) {
59 | e.printStackTrace();
60 | }
61 | }
62 | // gif格式不压缩
63 | if(FileUtils.getCompressFormat(new File(path)) == null){
64 | try {
65 | L.d("copyFile");
66 | return FileUtils.copyFile(new File(path), new File(outPath));
67 | } catch (IOException e) {
68 | e.printStackTrace();
69 | }
70 | }
71 | Bitmap bitmap = compress();
72 | try {
73 | return compressEngine.compress2File(bitmap, outPath, quality);
74 | }finally {
75 | if(bitmap != null && !bitmap.isRecycled()){
76 | bitmap.recycle();
77 | }
78 | }
79 |
80 | }
81 |
82 | @Override
83 | public Bitmap compress() {
84 | int resultWidth;
85 | int resultHeight;
86 | if(!compressArgs.isIgnoreSize() && compressArgs.getWidth() > 0 && compressArgs.getHeight() >0){
87 | resultWidth = compressArgs.getWidth();
88 | resultHeight = compressArgs.getHeight();
89 | }else {
90 | BitmapFactory.Options options = new BitmapFactory.Options();
91 | options.inJustDecodeBounds = true;
92 | BitmapFactory.decodeFile(path, options);
93 | if(compressArgs.isIgnoreSize()){
94 | resultWidth = options.outWidth;
95 | resultHeight = options.outHeight;
96 | }else {
97 | resultWidth = Math.min(lightConfig.getMaxWidth(), options.outWidth);
98 | resultHeight = Math.min(lightConfig.getMaxHeight(), options.outHeight);
99 | }
100 |
101 | }
102 | Bitmap result = compressEngine.compress2Bitmap(path, resultWidth, resultHeight, compressArgs.getConfig());
103 | float scaleSize = MatrixUtil.getScale(resultWidth, resultHeight, result.getWidth(), result.getHeight());
104 | if(scaleSize < 1){
105 | MatrixUtil.Build build = new MatrixUtil.Build().scale(scaleSize, scaleSize).bitmap(result);
106 | if(compressArgs.isAutoRotation()){
107 | int degree = DegreeHelper.getBitmapDegree(path);
108 | if(degree != 0){
109 | build.preRotate(degree);
110 | }
111 | }
112 | return build.build();
113 | }
114 | if(compressArgs.isAutoRotation()){
115 | int degree = DegreeHelper.getBitmapDegree(path);
116 | if(degree != 0){
117 | return new MatrixUtil.Build().preRotate(degree).bitmap(result).build();
118 | }
119 | }
120 | return result;
121 | }
122 |
123 | public void compressFromHttp(boolean openDiskCache, OnCompressFinishListener compressFinishListener) {
124 | if (Looper.getMainLooper() == Looper.myLooper()) {
125 | throw new RuntimeException("network uri can't compressed on UI Thread");
126 | }
127 | if (compressFinishListener != null) {
128 | HttpDownLoader.downloadImage(openDiskCache, path, compressFinishListener);
129 | }
130 | }
131 |
132 | public static class Builder {
133 | private String path;
134 | private CompressArgs compressArgs;
135 |
136 | public Builder path(String path) {
137 | this.path = path;
138 | return this;
139 | }
140 |
141 | public Builder compressArgs(CompressArgs compressArgs) {
142 | this.compressArgs = compressArgs;
143 | return this;
144 | }
145 |
146 | public FileCompressProxy build(){
147 | if(path == null){
148 | throw new RuntimeException("This path does not exist.");
149 | }
150 | FileCompressProxy proxy = new FileCompressProxy();
151 | proxy.path = path;
152 | if(compressArgs == null){
153 | proxy.compressArgs = CompressArgs.getDefaultArgs();
154 | }else {
155 | proxy.compressArgs = compressArgs;
156 | }
157 | return proxy;
158 | }
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/proxy/ResourcesCompressProxy.java:
--------------------------------------------------------------------------------
1 | package com.light.proxy;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.drawable.Drawable;
6 |
7 | import com.light.body.CompressArgs;
8 | import com.light.body.Light;
9 | import com.light.body.LightConfig;
10 | import com.light.core.LightCompressEngine;
11 | import com.light.core.Utils.L;
12 | import com.light.core.Utils.MatrixUtil;
13 | import com.light.core.listener.ICompressEngine;
14 | import com.light.core.listener.ICompressProxy;
15 |
16 |
17 | /**
18 | * Created by xiaoqi on 2017/11/25
19 | */
20 |
21 | public class ResourcesCompressProxy implements ICompressProxy {
22 | private final static String TAG = Light.TAG + "-ResourcesCompressProxy";
23 | private int resId;
24 | private Drawable drawable;
25 | private LightConfig lightConfig;
26 | private ICompressEngine compressEngine;
27 | private CompressArgs compressArgs;
28 |
29 | private ResourcesCompressProxy() {
30 | lightConfig = Light.getInstance().getConfig();
31 | compressEngine = new LightCompressEngine();
32 | }
33 |
34 | @Override
35 | public boolean compress(String outPath) {
36 | Bitmap result = compress();
37 | if(outPath == null){
38 | outPath = lightConfig.getOutputRootDir();
39 | }
40 | return compressEngine.compress2File(result, outPath, lightConfig.getDefaultQuality());
41 | }
42 |
43 | @Override
44 | public Bitmap compress() {
45 | int resultWidth;
46 | int resultHeight;
47 | if(!compressArgs.isIgnoreSize() && compressArgs.getWidth() > 0 && compressArgs.getHeight() >0){
48 | resultWidth = compressArgs.getWidth();
49 | resultHeight = compressArgs.getHeight();
50 | }else {
51 | if(drawable != null){
52 | if(compressArgs.isIgnoreSize()){
53 | resultWidth = drawable.getIntrinsicWidth();
54 | resultHeight = drawable.getIntrinsicHeight();
55 | }else {
56 | resultWidth = Math.min(lightConfig.getMaxWidth(), drawable.getIntrinsicWidth());
57 | resultHeight = Math.min(lightConfig.getMaxHeight(), drawable.getIntrinsicHeight());
58 | }
59 | }else {
60 | BitmapFactory.Options options = new BitmapFactory.Options();
61 | options.inJustDecodeBounds = true;
62 | BitmapFactory.decodeResource(Light.getInstance().getResources(), resId, options);
63 | if(compressArgs.isIgnoreSize()){
64 | resultWidth = options.outWidth;
65 | resultHeight = options.outHeight;
66 | }else {
67 | resultWidth = Math.min(lightConfig.getMaxWidth(), options.outWidth);
68 | resultHeight = Math.min(lightConfig.getMaxHeight(), options.outHeight);
69 | }
70 |
71 | }
72 | }
73 | L.i(TAG, "finalWidth:"+resultWidth+" finalHeight:"+resultHeight);
74 | Bitmap result = compressEngine.compress2Bitmap(resId, resultWidth, resultHeight, compressArgs.getConfig());
75 | float scaleSize = MatrixUtil.getScale(resultWidth, resultHeight, result.getWidth(), result.getHeight());
76 | if(scaleSize < 1){
77 | return new MatrixUtil.Build().scale(scaleSize, scaleSize).bitmap(result).build();
78 | }
79 | return result;
80 | }
81 |
82 | public static class Builder {
83 | private int resId;
84 | private Drawable drawable;
85 | private CompressArgs compressArgs;
86 |
87 | public Builder resource(int resId) {
88 | this.resId = resId;
89 | return this;
90 | }
91 |
92 | public Builder drawable(Drawable drawable) {
93 | this.drawable = drawable;
94 | return this;
95 | }
96 |
97 | public Builder compressArgs(CompressArgs compressArgs) {
98 | this.compressArgs = compressArgs;
99 | return this;
100 | }
101 |
102 | public ResourcesCompressProxy build(){
103 | if(resId == 0 && drawable == null){
104 | throw new RuntimeException("resource is not exists");
105 | }
106 | ResourcesCompressProxy proxy = new ResourcesCompressProxy();
107 | proxy.resId = resId;
108 | proxy.drawable = drawable;
109 | if(compressArgs == null){
110 | proxy.compressArgs = CompressArgs.getDefaultArgs();
111 | }else {
112 | proxy.compressArgs = compressArgs;
113 | }
114 | return proxy;
115 | }
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/light/src/main/java/com/light/proxy/UriCompressProxy.java:
--------------------------------------------------------------------------------
1 | package com.light.proxy;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.net.Uri;
6 | import android.os.Looper;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.light.body.CompressArgs;
10 | import com.light.body.Light;
11 | import com.light.core.Utils.UriParser;
12 | import com.light.core.Utils.http.HttpDownLoader;
13 | import com.light.core.listener.ICompressProxy;
14 | import com.light.core.listener.OnCompressFinishListener;
15 |
16 | import java.io.FileNotFoundException;
17 | import java.io.InputStream;
18 |
19 | /**
20 | * Created by xiaoqi on 2017/11/25
21 | */
22 |
23 | public class UriCompressProxy implements ICompressProxy {
24 |
25 | private Uri uri;
26 | private ICompressProxy compressProxy = null;
27 | private OnCompressFinishListener compressFinishListener = null;
28 | private CompressArgs compressArgs;
29 |
30 | @Override
31 | public boolean compress(String outPath) {
32 | if(UriParser.isLocalFileUri(uri)){
33 | String filePath = UriParser.getPathFromFileUri(uri);
34 | compressProxy = new FileCompressProxy.Builder().compressArgs(compressArgs).path(filePath).build();
35 | }else if(UriParser.isLocalContentUri(uri)){
36 | String filePath = UriParser.getPathFromContentUri(uri);
37 | compressProxy = new FileCompressProxy.Builder().compressArgs(compressArgs).path(filePath).build();
38 | }else if(UriParser.isLocalAnroidResourceUri(uri)){
39 | try {
40 | InputStream input = Light.getInstance().getContext().getContentResolver().openInputStream(uri);
41 | Bitmap bitmap = BitmapFactory.decodeStream(input);
42 | compressProxy = new BitmapCompressProxy.Builder().compressArgs(compressArgs).bitmap(bitmap).build();
43 | } catch (FileNotFoundException e) {
44 | e.printStackTrace();
45 | }
46 | }else if(UriParser.isNetworkUri(uri)){
47 | throw new RuntimeException("please use method of 'Light.getInstance().compressFromHttp()'");
48 |
49 | }else {
50 | return false;
51 | }
52 | return compressProxy.compress(outPath);
53 | }
54 |
55 | public void compressFromHttp(boolean openDiskCache, OnCompressFinishListener compressFinishListener) {
56 | if(UriParser.isNetworkUri(uri)) {
57 | if (Looper.getMainLooper() == Looper.myLooper()) {
58 | throw new RuntimeException("network uri can't compressed on UI Thread");
59 | }
60 | if(compressFinishListener != null){
61 | HttpDownLoader.downloadImage(openDiskCache, uri, compressFinishListener);
62 | }
63 | }
64 | }
65 |
66 | @Nullable
67 | @Override
68 | public Bitmap compress() {
69 |
70 | if(UriParser.isLocalFileUri(uri)){
71 | String filePath = UriParser.getPathFromFileUri(uri);
72 | compressProxy = new FileCompressProxy.Builder().compressArgs(compressArgs).path(filePath).build();
73 | }else if(UriParser.isLocalContentUri(uri)){
74 | String filePath = UriParser.getPathFromContentUri(uri);
75 | compressProxy = new FileCompressProxy.Builder().compressArgs(compressArgs).path(filePath).build();
76 | }else if(UriParser.isLocalAnroidResourceUri(uri)){
77 | try {
78 | InputStream input = Light.getInstance().getContext().getContentResolver().openInputStream(uri);
79 | Bitmap bitmap = BitmapFactory.decodeStream(input);
80 | compressProxy = new BitmapCompressProxy.Builder().compressArgs(compressArgs).bitmap(bitmap).build();
81 | } catch (FileNotFoundException e) {
82 | e.printStackTrace();
83 | }
84 | }else if(UriParser.isNetworkUri(uri)){
85 | if(Looper.getMainLooper() == Looper.myLooper()){
86 | throw new RuntimeException("network uri can't compressed on UI Thread");
87 | }
88 | // compressProxy = new FileCompressProxy.Builder().width(width).height(height).path().build();
89 | }else {
90 | return null;
91 | }
92 |
93 | return compressProxy.compress();
94 | }
95 |
96 | public static class Builder {
97 | private Uri uri;
98 | private CompressArgs compressArgs;
99 | private OnCompressFinishListener compressFinishListener;
100 |
101 | public Builder uri(Uri uri) {
102 | this.uri = uri;
103 | return this;
104 | }
105 |
106 | public Builder compressArgs(CompressArgs compressArgs) {
107 | this.compressArgs = compressArgs;
108 | return this;
109 | }
110 |
111 | public Builder compressListener(OnCompressFinishListener compressFinishListener) {
112 | this.compressFinishListener = compressFinishListener;
113 | return this;
114 | }
115 |
116 | public UriCompressProxy build(){
117 | if(uri == null){
118 | throw new RuntimeException("resId is not exists");
119 | }
120 | UriCompressProxy proxy = new UriCompressProxy();
121 | proxy.uri = uri;
122 | if(compressArgs == null){
123 | proxy.compressArgs = CompressArgs.getDefaultArgs();
124 | }else {
125 | proxy.compressArgs = compressArgs;
126 | }
127 | proxy.compressFinishListener = compressFinishListener;
128 | return proxy;
129 | }
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/light/src/main/jni/Android.mk:
--------------------------------------------------------------------------------
1 | # Copyright (C) 2009 The Android Open Source Project
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | #
15 |
16 |
17 | # Copyright 2014 http://Bither.net
18 | #
19 | # Licensed under the Apache License, Version 2.0 (the "License");
20 | # you may not use this file except in compliance with the License.
21 | # You may obtain a copy of the License at
22 | #
23 | # http://www.apache.org/licenses/LICENSE-2.0
24 | #
25 | # Unless required by applicable law or agreed to in writing, software
26 | # distributed under the License is distributed on an "AS IS" BASIS,
27 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 | # See the License for the specific language governing permissions and
29 | # limitations under the License.
30 |
31 | LOCAL_PATH := $(call my-dir)
32 |
33 |
34 | #jpeg-turbo
35 | include $(CLEAR_VARS)
36 | LOCAL_MODULE := libjpegbither
37 | LOCAL_SRC_FILES := libjpegbither.so
38 | include $(PREBUILT_SHARED_LIBRARY)
39 |
40 |
41 | include $(CLEAR_VARS)
42 | LOCAL_MODULE := light
43 | LOCAL_SRC_FILES := bitherlibjni.c
44 | LOCAL_SHARED_LIBRARIES := libjpegbither
45 | LOCAL_LDLIBS := -ljnigraphics -llog
46 | LOCAL_C_INCLUDES := $(LOCAL_PATH) \
47 | $(LOCAL_PATH)/libjpeg-turbo \
48 | $(LOCAL_PATH)/libjpeg-turbo/android
49 | include $(BUILD_SHARED_LIBRARY)
--------------------------------------------------------------------------------
/light/src/main/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_ABI := armeabi armeabi-v7a
--------------------------------------------------------------------------------
/light/src/main/jni/README.md:
--------------------------------------------------------------------------------
1 | Buid libjpeg-turbo-android-lib
2 | ==================
3 |
4 | 1.To get started, ensure you have the latest NDK
5 | You must configure the path of JDK and Android SDK.
6 |
7 | echo "export ANDROID_HOME='Your android ndk path'" >> ~/.bash_profile
8 |
9 | source ~/.bash_profile
10 |
11 |
12 | 2.Build libjpeg-turbo.so
13 |
14 | cd ../libjpeg-turbo-android/libjpeg-turbo/jni
15 |
16 | ndk-buld
17 |
18 | 3.You can get libjpegpi.so in
19 |
20 | ../libjpeg-turbo-android/libjpeg-turbo/libs/armeabi
21 |
22 |
23 | 4.Copy libjpegpi.so to ../bither-android-lib/libjpeg-turbo-android/use-libjpeg-trubo-adnroid/jni
24 |
25 | cd ../bither-android-lib/libjpeg-turbo-android/use-libjpeg-trubo-adnroid/jni
26 |
27 | ndk-build
28 |
29 | 5.You can get libjpegpi.so and libpijni.so
30 |
31 |
32 | 6.Use libjpeg-turbo in java
33 |
34 | static {
35 |
36 | System.loadLibrary("jpegpi");
37 |
38 | System.loadLibrary("pijni");
39 |
40 | }
41 | and you must use class of "com.pi.common.util.NativeUtil"
42 |
--------------------------------------------------------------------------------
/light/src/main/jni/bitherlibjni.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 http://Bither.net
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include "jpeglib.h"
27 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
28 | #include "jversion.h" /* for version message */
29 | #include "config.h"
30 |
31 | #define LOG_TAG "jni"
32 | #define LOGW(...) __android_log_write(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
33 | #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
34 | #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
35 |
36 | #define true 1
37 | #define false 0
38 |
39 | typedef uint8_t BYTE;
40 |
41 | char *error;
42 | struct my_error_mgr {
43 | struct jpeg_error_mgr pub;
44 | jmp_buf setjmp_buffer;
45 | };
46 |
47 | typedef struct my_error_mgr * my_error_ptr;
48 |
49 | METHODDEF(void)
50 | my_error_exit (j_common_ptr cinfo)
51 | {
52 | my_error_ptr myerr = (my_error_ptr) cinfo->err;
53 | (*cinfo->err->output_message) (cinfo);
54 | error=myerr->pub.jpeg_message_table[myerr->pub.msg_code];
55 | LOGE("jpeg_message_table[%d]:%s", myerr->pub.msg_code,myerr->pub.jpeg_message_table[myerr->pub.msg_code]);
56 | // LOGE("addon_message_table:%s", myerr->pub.addon_message_table);
57 | // LOGE("SIZEOF:%d",myerr->pub.msg_parm.i[0]);
58 | // LOGE("sizeof:%d",myerr->pub.msg_parm.i[1]);
59 | longjmp(myerr->setjmp_buffer, 1);
60 | }
61 |
62 | int generateJPEG(BYTE* data, int w, int h, int quality,
63 | const char* outfilename, jboolean optimize) {
64 | int nComponent = 3;
65 |
66 | struct jpeg_compress_struct jcs;
67 |
68 | struct my_error_mgr jem;
69 |
70 | jcs.err = jpeg_std_error(&jem.pub);
71 | jem.pub.error_exit = my_error_exit;
72 | if (setjmp(jem.setjmp_buffer)) {
73 | return 0;
74 | }
75 | jpeg_create_compress(&jcs);
76 | FILE* f = fopen(outfilename, "wb");
77 |
78 | if (f == NULL) {
79 | return 0;
80 | }
81 | jpeg_stdio_dest(&jcs, f);
82 | jcs.image_width = w;
83 | jcs.image_height = h;
84 | // if (optimize) {
85 | // LOGI("optimize==ture");
86 | // } else {
87 | // LOGI("optimize==false");
88 | // }
89 |
90 | jcs.arith_code = false;
91 | jcs.input_components = nComponent;
92 | if (nComponent == 1)
93 | jcs.in_color_space = JCS_GRAYSCALE;
94 | else
95 | jcs.in_color_space = JCS_RGB;
96 |
97 | jpeg_set_defaults(&jcs);
98 | jcs.optimize_coding = optimize;
99 | jpeg_set_quality(&jcs, quality, true);
100 |
101 | jpeg_start_compress(&jcs, TRUE);
102 |
103 | JSAMPROW row_pointer[1];
104 | int row_stride;
105 | row_stride = jcs.image_width * nComponent;
106 | while (jcs.next_scanline < jcs.image_height) {
107 | row_pointer[0] = &data[jcs.next_scanline * row_stride];
108 |
109 | jpeg_write_scanlines(&jcs, row_pointer, 1);
110 | }
111 |
112 | // if (jcs.optimize_coding) {
113 | // LOGI("optimize==ture");
114 | // } else {
115 | // LOGI("optimize==false");
116 | // }
117 | jpeg_finish_compress(&jcs);
118 | jpeg_destroy_compress(&jcs);
119 | fclose(f);
120 |
121 | return 1;
122 | }
123 |
124 | typedef struct {
125 | uint8_t r;
126 | uint8_t g;
127 | uint8_t b;
128 | } rgb;
129 |
130 | char* jstrinTostring(JNIEnv* env, jbyteArray barr) {
131 | char* rtn = NULL;
132 | jsize alen = (*env)->GetArrayLength(env, barr);
133 | jbyte* ba = (*env)->GetByteArrayElements(env, barr, 0);
134 | if (alen > 0) {
135 | rtn = (char*) malloc(alen + 1);
136 | memcpy(rtn, ba, alen);
137 | rtn[alen] = 0;
138 | }
139 | (*env)->ReleaseByteArrayElements(env, barr, ba, 0);
140 | return rtn;
141 | }
142 |
143 | jbyteArray stoJstring(JNIEnv* env, const char* pat,int len) {
144 | jbyteArray bytes = (*env)->NewByteArray(env, len);
145 | (*env)->SetByteArrayRegion(env, bytes, 0, len, pat);
146 | jsize alen = (*env)->GetArrayLength(env, bytes);
147 | return bytes;
148 | }
149 |
150 | jboolean Java_com_light_compress_LightCompressCore_compressBitmap(JNIEnv* env,
151 | jobject thiz, jobject bitmapcolor, int w, int h, int quality,
152 | jbyteArray fileNameStr, jboolean optimize) {
153 | AndroidBitmapInfo infocolor;
154 | BYTE* pixelscolor;
155 | int ret;
156 | BYTE * data;
157 | BYTE *tmpdata;
158 | char * fileName = jstrinTostring(env, fileNameStr);
159 | if ((ret = AndroidBitmap_getInfo(env, bitmapcolor, &infocolor)) < 0) {
160 | LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret);
161 | return (*env)->NewStringUTF(env, "0");;
162 | }
163 | if ((ret = AndroidBitmap_lockPixels(env, bitmapcolor, &pixelscolor)) < 0) {
164 | LOGE("AndroidBitmap_lockPixels() failed ! error=%d", ret);
165 | }
166 | BYTE r, g, b;
167 | data = NULL;
168 | data = malloc(w * h * 3);
169 | tmpdata = data;
170 | int j = 0, i = 0;
171 | int color;
172 | for (i = 0; i < h; i++) {
173 | for (j = 0; j < w; j++) {
174 | color = *((int *) pixelscolor);
175 | r = ((color & 0x00FF0000) >> 16);
176 | g = ((color & 0x0000FF00) >> 8);
177 | b = color & 0x000000FF;
178 | *data = b;
179 | *(data + 1) = g;
180 | *(data + 2) = r;
181 | data = data + 3;
182 | pixelscolor += 4;
183 |
184 | }
185 |
186 | }
187 | AndroidBitmap_unlockPixels(env, bitmapcolor);
188 | int resultCode= generateJPEG(tmpdata, w, h, quality, fileName, optimize);
189 | free(tmpdata);
190 | if(resultCode==0){
191 | jstring result=(*env)->NewStringUTF(env, error);
192 | error=NULL;
193 | return false;
194 | }
195 | return true; //success
196 | }
197 |
198 |
199 | void jstringTostring(JNIEnv* env, jstring jstr, char * output, int * de_len) {
200 | *output = NULL;
201 | jclass clsstring = (*env)->FindClass(env, "java/lang/String");
202 | jstring strencode = (*env)->NewStringUTF(env, "utf-8");
203 | jmethodID mid = (*env)->GetMethodID(env, clsstring, "getBytes",
204 | "(Ljava/lang/String;)[B");
205 | jbyteArray barr = (jbyteArray)(*env)->CallObjectMethod(env, jstr, mid,
206 | strencode);
207 | jsize alen = (*env)->GetArrayLength(env, barr);
208 | *de_len = alen;
209 | jbyte* ba = (*env)->GetByteArrayElements(env, barr, JNI_FALSE);
210 | if (alen > 0) {
211 | output = (char*) malloc(alen + 1);
212 | memcpy(output, ba, alen);
213 | output[alen] = 0;
214 | }
215 | (*env)->ReleaseByteArrayElements(env, barr, ba, 0);
216 | }
217 |
218 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpeg-turbo/android/config.h:
--------------------------------------------------------------------------------
1 | /* config.h. Generated from config.h.in by configure. */
2 | /* config.h.in. Generated from configure.ac by autoheader. */
3 |
4 | /* Build number */
5 | #define BUILD "20110829"
6 |
7 | /* Support arithmetic encoding */
8 | #define C_ARITH_CODING_SUPPORTED 1
9 |
10 | /* Support arithmetic decoding */
11 | #define D_ARITH_CODING_SUPPORTED 1
12 |
13 | /* Define to 1 if you have the header file. */
14 | #define HAVE_DLFCN_H 1
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_INTTYPES_H 1
18 |
19 | /* Define to 1 if you have the header file. */
20 | /* #undef HAVE_JNI_H */
21 |
22 | /* Define to 1 if you have the `memcpy' function. */
23 | #define HAVE_MEMCPY 1
24 |
25 | /* Define to 1 if you have the header file. */
26 | #define HAVE_MEMORY_H 1
27 |
28 | /* Define to 1 if you have the `memset' function. */
29 | #define HAVE_MEMSET 1
30 |
31 | /* Define if your compiler supports prototypes */
32 | #define HAVE_PROTOTYPES 1
33 |
34 | /* Define to 1 if you have the header file. */
35 | #define HAVE_STDDEF_H 1
36 |
37 | /* Define to 1 if you have the header file. */
38 | #define HAVE_STDINT_H 1
39 |
40 | /* Define to 1 if you have the header file. */
41 | #define HAVE_STDLIB_H 1
42 |
43 | /* Define to 1 if you have the header file. */
44 | #define HAVE_STRINGS_H 1
45 |
46 | /* Define to 1 if you have the header file. */
47 | #define HAVE_STRING_H 1
48 |
49 | /* Define to 1 if you have the header file. */
50 | #define HAVE_SYS_STAT_H 1
51 |
52 | /* Define to 1 if you have the header file. */
53 | #define HAVE_SYS_TYPES_H 1
54 |
55 | /* Define to 1 if you have the header file. */
56 | #define HAVE_UNISTD_H 1
57 |
58 | /* Define to 1 if the system has the type `unsigned char'. */
59 | #define HAVE_UNSIGNED_CHAR 1
60 |
61 | /* Define to 1 if the system has the type `unsigned short'. */
62 | #define HAVE_UNSIGNED_SHORT 1
63 |
64 | /* Compiler does not support pointers to undefined structures. */
65 | /* #undef INCOMPLETE_TYPES_BROKEN */
66 |
67 | /* libjpeg API version */
68 | #define JPEG_LIB_VERSION 62
69 |
70 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
71 | */
72 | #define LT_OBJDIR ".libs/"
73 |
74 | /* Define if you have BSD-like bzero and bcopy */
75 | /* #undef NEED_BSD_STRINGS */
76 |
77 | /* Define if you need short function names */
78 | /* #undef NEED_SHORT_EXTERNAL_NAMES */
79 |
80 | /* Define if you have sys/types.h */
81 | #define NEED_SYS_TYPES_H 1
82 |
83 | /* Name of package */
84 | #define PACKAGE "libjpeg-turbo"
85 |
86 | /* Define to the address where bug reports for this package should be sent. */
87 | #define PACKAGE_BUGREPORT ""
88 |
89 | /* Define to the full name of this package. */
90 | #define PACKAGE_NAME "libjpeg-turbo"
91 |
92 | /* Define to the full name and version of this package. */
93 | #define PACKAGE_STRING "libjpeg-turbo 1.1.90"
94 |
95 | /* Define to the one symbol short name of this package. */
96 | #define PACKAGE_TARNAME "libjpeg-turbo"
97 |
98 | /* Define to the home page for this package. */
99 | #define PACKAGE_URL ""
100 |
101 | /* Define to the version of this package. */
102 | #define PACKAGE_VERSION "1.1.90"
103 |
104 | /* Define if shift is unsigned */
105 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */
106 |
107 | /* Define to 1 if you have the ANSI C header files. */
108 | #define STDC_HEADERS 1
109 |
110 | /* Version number of package */
111 | #define VERSION "1.1.90"
112 |
113 | /* Use accelerated SIMD routines. */
114 | #define WITH_SIMD 1
115 |
116 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */
117 | #ifndef __CHAR_UNSIGNED__
118 | /* # undef __CHAR_UNSIGNED__ */
119 | #endif
120 |
121 | /* Define to empty if `const' does not conform to ANSI C. */
122 | /* #undef const */
123 |
124 | /* Define to `__inline__' or `__inline' if that's what the C compiler
125 | calls it, or to nothing if 'inline' is not supported under any name. */
126 | #ifndef __cplusplus
127 | /* #undef inline */
128 | #endif
129 |
130 | /* Define to `unsigned int' if does not define. */
131 | /* #undef size_t */
132 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpeg-turbo/android/jconfig.h:
--------------------------------------------------------------------------------
1 | /* jconfig.h. Generated from jconfig.h.in by configure. */
2 | /* Version ID for the JPEG library.
3 | * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
4 | */
5 | #define JPEG_LIB_VERSION 62
6 |
7 | /* Support arithmetic encoding */
8 | #define C_ARITH_CODING_SUPPORTED 1
9 |
10 | /* Support arithmetic decoding */
11 | #define D_ARITH_CODING_SUPPORTED 1
12 |
13 | /* Define if your compiler supports prototypes */
14 | #define HAVE_PROTOTYPES 1
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_STDDEF_H 1
18 |
19 | /* Define to 1 if you have the header file. */
20 | #define HAVE_STDLIB_H 1
21 |
22 | /* Define to 1 if the system has the type `unsigned char'. */
23 | #define HAVE_UNSIGNED_CHAR 1
24 |
25 | /* Define to 1 if the system has the type `unsigned short'. */
26 | #define HAVE_UNSIGNED_SHORT 1
27 |
28 | /* Define if you want use complete types */
29 | /* #undef INCOMPLETE_TYPES_BROKEN */
30 |
31 | /* Define if you have BSD-like bzero and bcopy */
32 | /* #undef NEED_BSD_STRINGS */
33 |
34 | /* Define if you need short function names */
35 | /* #undef NEED_SHORT_EXTERNAL_NAMES */
36 |
37 | /* Define if you have sys/types.h */
38 | #define NEED_SYS_TYPES_H 1
39 |
40 | /* Define if shift is unsigned */
41 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */
42 |
43 | /* Use accelerated SIMD routines. */
44 | #define WITH_SIMD 1
45 |
46 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */
47 | #ifndef __CHAR_UNSIGNED__
48 | /* # undef __CHAR_UNSIGNED__ */
49 | #endif
50 |
51 | /* Define to empty if `const' does not conform to ANSI C. */
52 | /* #undef const */
53 |
54 | /* Define to `__inline__' or `__inline' if that's what the C compiler
55 | calls it, or to nothing if 'inline' is not supported under any name. */
56 | #ifndef __cplusplus
57 | /* #undef inline */
58 | #endif
59 |
60 | /* Define to `unsigned int' if does not define. */
61 | /* #undef size_t */
62 |
63 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpeg-turbo/cderror.h:
--------------------------------------------------------------------------------
1 | /*
2 | * cderror.h
3 | *
4 | * Copyright (C) 1994-1997, Thomas G. Lane.
5 | * Modified 2009 by Guido Vollbeding.
6 | * This file is part of the Independent JPEG Group's software.
7 | * For conditions of distribution and use, see the accompanying README file.
8 | *
9 | * This file defines the error and message codes for the cjpeg/djpeg
10 | * applications. These strings are not needed as part of the JPEG library
11 | * proper.
12 | * Edit this file to add new codes, or to translate the message strings to
13 | * some other language.
14 | */
15 |
16 | /*
17 | * To define the enum list of message codes, include this file without
18 | * defining macro JMESSAGE. To create a message string table, include it
19 | * again with a suitable JMESSAGE definition (see jerror.c for an example).
20 | */
21 | #ifndef JMESSAGE
22 | #ifndef CDERROR_H
23 | #define CDERROR_H
24 | /* First time through, define the enum list */
25 | #define JMAKE_ENUM_LIST
26 | #else
27 | /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
28 | #define JMESSAGE(code,string)
29 | #endif /* CDERROR_H */
30 | #endif /* JMESSAGE */
31 |
32 | #ifdef JMAKE_ENUM_LIST
33 |
34 | typedef enum {
35 |
36 | #define JMESSAGE(code,string) code ,
37 |
38 | #endif /* JMAKE_ENUM_LIST */
39 |
40 | JMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */
41 |
42 | #ifdef BMP_SUPPORTED
43 | JMESSAGE(JERR_BMP_BADCMAP, "Unsupported BMP colormap format")
44 | JMESSAGE(JERR_BMP_BADDEPTH, "Only 8- and 24-bit BMP files are supported")
45 | JMESSAGE(JERR_BMP_BADHEADER, "Invalid BMP file: bad header length")
46 | JMESSAGE(JERR_BMP_BADPLANES, "Invalid BMP file: biPlanes not equal to 1")
47 | JMESSAGE(JERR_BMP_COLORSPACE, "BMP output must be grayscale or RGB")
48 | JMESSAGE(JERR_BMP_COMPRESSED, "Sorry, compressed BMPs not yet supported")
49 | JMESSAGE(JERR_BMP_EMPTY, "Empty BMP image")
50 | JMESSAGE(JERR_BMP_NOT, "Not a BMP file - does not start with BM")
51 | JMESSAGE(JTRC_BMP, "%ux%u 24-bit BMP image")
52 | JMESSAGE(JTRC_BMP_MAPPED, "%ux%u 8-bit colormapped BMP image")
53 | JMESSAGE(JTRC_BMP_OS2, "%ux%u 24-bit OS2 BMP image")
54 | JMESSAGE(JTRC_BMP_OS2_MAPPED, "%ux%u 8-bit colormapped OS2 BMP image")
55 | #endif /* BMP_SUPPORTED */
56 |
57 | #ifdef GIF_SUPPORTED
58 | JMESSAGE(JERR_GIF_BUG, "GIF output got confused")
59 | JMESSAGE(JERR_GIF_CODESIZE, "Bogus GIF codesize %d")
60 | JMESSAGE(JERR_GIF_COLORSPACE, "GIF output must be grayscale or RGB")
61 | JMESSAGE(JERR_GIF_IMAGENOTFOUND, "Too few images in GIF file")
62 | JMESSAGE(JERR_GIF_NOT, "Not a GIF file")
63 | JMESSAGE(JTRC_GIF, "%ux%ux%d GIF image")
64 | JMESSAGE(JTRC_GIF_BADVERSION,
65 | "Warning: unexpected GIF version number '%c%c%c'")
66 | JMESSAGE(JTRC_GIF_EXTENSION, "Ignoring GIF extension block of type 0x%02x")
67 | JMESSAGE(JTRC_GIF_NONSQUARE, "Caution: nonsquare pixels in input")
68 | JMESSAGE(JWRN_GIF_BADDATA, "Corrupt data in GIF file")
69 | JMESSAGE(JWRN_GIF_CHAR, "Bogus char 0x%02x in GIF file, ignoring")
70 | JMESSAGE(JWRN_GIF_ENDCODE, "Premature end of GIF image")
71 | JMESSAGE(JWRN_GIF_NOMOREDATA, "Ran out of GIF bits")
72 | #endif /* GIF_SUPPORTED */
73 |
74 | #ifdef PPM_SUPPORTED
75 | JMESSAGE(JERR_PPM_COLORSPACE, "PPM output must be grayscale or RGB")
76 | JMESSAGE(JERR_PPM_NONNUMERIC, "Nonnumeric data in PPM file")
77 | JMESSAGE(JERR_PPM_NOT, "Not a PPM/PGM file")
78 | JMESSAGE(JTRC_PGM, "%ux%u PGM image")
79 | JMESSAGE(JTRC_PGM_TEXT, "%ux%u text PGM image")
80 | JMESSAGE(JTRC_PPM, "%ux%u PPM image")
81 | JMESSAGE(JTRC_PPM_TEXT, "%ux%u text PPM image")
82 | #endif /* PPM_SUPPORTED */
83 |
84 | #ifdef RLE_SUPPORTED
85 | JMESSAGE(JERR_RLE_BADERROR, "Bogus error code from RLE library")
86 | JMESSAGE(JERR_RLE_COLORSPACE, "RLE output must be grayscale or RGB")
87 | JMESSAGE(JERR_RLE_DIMENSIONS, "Image dimensions (%ux%u) too large for RLE")
88 | JMESSAGE(JERR_RLE_EMPTY, "Empty RLE file")
89 | JMESSAGE(JERR_RLE_EOF, "Premature EOF in RLE header")
90 | JMESSAGE(JERR_RLE_MEM, "Insufficient memory for RLE header")
91 | JMESSAGE(JERR_RLE_NOT, "Not an RLE file")
92 | JMESSAGE(JERR_RLE_TOOMANYCHANNELS, "Cannot handle %d output channels for RLE")
93 | JMESSAGE(JERR_RLE_UNSUPPORTED, "Cannot handle this RLE setup")
94 | JMESSAGE(JTRC_RLE, "%ux%u full-color RLE file")
95 | JMESSAGE(JTRC_RLE_FULLMAP, "%ux%u full-color RLE file with map of length %d")
96 | JMESSAGE(JTRC_RLE_GRAY, "%ux%u grayscale RLE file")
97 | JMESSAGE(JTRC_RLE_MAPGRAY, "%ux%u grayscale RLE file with map of length %d")
98 | JMESSAGE(JTRC_RLE_MAPPED, "%ux%u colormapped RLE file with map of length %d")
99 | #endif /* RLE_SUPPORTED */
100 |
101 | #ifdef TARGA_SUPPORTED
102 | JMESSAGE(JERR_TGA_BADCMAP, "Unsupported Targa colormap format")
103 | JMESSAGE(JERR_TGA_BADPARMS, "Invalid or unsupported Targa file")
104 | JMESSAGE(JERR_TGA_COLORSPACE, "Targa output must be grayscale or RGB")
105 | JMESSAGE(JTRC_TGA, "%ux%u RGB Targa image")
106 | JMESSAGE(JTRC_TGA_GRAY, "%ux%u grayscale Targa image")
107 | JMESSAGE(JTRC_TGA_MAPPED, "%ux%u colormapped Targa image")
108 | #else
109 | JMESSAGE(JERR_TGA_NOTCOMP, "Targa support was not compiled")
110 | #endif /* TARGA_SUPPORTED */
111 |
112 | JMESSAGE(JERR_BAD_CMAP_FILE,
113 | "Color map file is invalid or of unsupported format")
114 | JMESSAGE(JERR_TOO_MANY_COLORS,
115 | "Output file format cannot handle %d colormap entries")
116 | JMESSAGE(JERR_UNGETC_FAILED, "ungetc failed")
117 | #ifdef TARGA_SUPPORTED
118 | JMESSAGE(JERR_UNKNOWN_FORMAT,
119 | "Unrecognized input file format --- perhaps you need -targa")
120 | #else
121 | JMESSAGE(JERR_UNKNOWN_FORMAT, "Unrecognized input file format")
122 | #endif
123 | JMESSAGE(JERR_UNSUPPORTED_FORMAT, "Unsupported output file format")
124 |
125 | #ifdef JMAKE_ENUM_LIST
126 |
127 | JMSG_LASTADDONCODE
128 | } ADDON_MESSAGE_CODE;
129 |
130 | #undef JMAKE_ENUM_LIST
131 | #endif /* JMAKE_ENUM_LIST */
132 |
133 | /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
134 | #undef JMESSAGE
135 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpeg-turbo/cdjpeg.h:
--------------------------------------------------------------------------------
1 | /*
2 | * cdjpeg.h
3 | *
4 | * Copyright (C) 1994-1997, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file contains common declarations for the sample applications
9 | * cjpeg and djpeg. It is NOT used by the core JPEG library.
10 | */
11 |
12 | #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
13 | #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
14 | #include "jinclude.h"
15 | #include "jpeglib.h"
16 | #include "jerror.h" /* get library error codes too */
17 | #include "cderror.h" /* get application-specific error codes */
18 |
19 |
20 | /*
21 | * Object interface for cjpeg's source file decoding modules
22 | */
23 |
24 | typedef struct cjpeg_source_struct * cjpeg_source_ptr;
25 |
26 | struct cjpeg_source_struct {
27 | JMETHOD(void, start_input, (j_compress_ptr cinfo,
28 | cjpeg_source_ptr sinfo));
29 | JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
30 | cjpeg_source_ptr sinfo));
31 | JMETHOD(void, finish_input, (j_compress_ptr cinfo,
32 | cjpeg_source_ptr sinfo));
33 |
34 | FILE *input_file;
35 |
36 | JSAMPARRAY buffer;
37 | JDIMENSION buffer_height;
38 | };
39 |
40 |
41 | /*
42 | * Object interface for djpeg's output file encoding modules
43 | */
44 |
45 | typedef struct djpeg_dest_struct * djpeg_dest_ptr;
46 |
47 | struct djpeg_dest_struct {
48 | /* start_output is called after jpeg_start_decompress finishes.
49 | * The color map will be ready at this time, if one is needed.
50 | */
51 | JMETHOD(void, start_output, (j_decompress_ptr cinfo,
52 | djpeg_dest_ptr dinfo));
53 | /* Emit the specified number of pixel rows from the buffer. */
54 | JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
55 | djpeg_dest_ptr dinfo,
56 | JDIMENSION rows_supplied));
57 | /* Finish up at the end of the image. */
58 | JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
59 | djpeg_dest_ptr dinfo));
60 |
61 | /* Target file spec; filled in by djpeg.c after object is created. */
62 | FILE * output_file;
63 |
64 | /* Output pixel-row buffer. Created by module init or start_output.
65 | * Width is cinfo->output_width * cinfo->output_components;
66 | * height is buffer_height.
67 | */
68 | JSAMPARRAY buffer;
69 | JDIMENSION buffer_height;
70 | };
71 |
72 |
73 | /*
74 | * cjpeg/djpeg may need to perform extra passes to convert to or from
75 | * the source/destination file format. The JPEG library does not know
76 | * about these passes, but we'd like them to be counted by the progress
77 | * monitor. We use an expanded progress monitor object to hold the
78 | * additional pass count.
79 | */
80 |
81 | struct cdjpeg_progress_mgr {
82 | struct jpeg_progress_mgr pub; /* fields known to JPEG library */
83 | int completed_extra_passes; /* extra passes completed */
84 | int total_extra_passes; /* total extra */
85 | /* last printed percentage stored here to avoid multiple printouts */
86 | int percent_done;
87 | };
88 |
89 | typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
90 |
91 |
92 | /* Short forms of external names for systems with brain-damaged linkers. */
93 |
94 | #ifdef NEED_SHORT_EXTERNAL_NAMES
95 | #define jinit_read_bmp jIRdBMP
96 | #define jinit_write_bmp jIWrBMP
97 | #define jinit_read_gif jIRdGIF
98 | #define jinit_write_gif jIWrGIF
99 | #define jinit_read_ppm jIRdPPM
100 | #define jinit_write_ppm jIWrPPM
101 | #define jinit_read_rle jIRdRLE
102 | #define jinit_write_rle jIWrRLE
103 | #define jinit_read_targa jIRdTarga
104 | #define jinit_write_targa jIWrTarga
105 | #define read_quant_tables RdQTables
106 | #define read_scan_script RdScnScript
107 | #define set_quality_ratings SetQRates
108 | #define set_quant_slots SetQSlots
109 | #define set_sample_factors SetSFacts
110 | #define read_color_map RdCMap
111 | #define enable_signal_catcher EnSigCatcher
112 | #define start_progress_monitor StProgMon
113 | #define end_progress_monitor EnProgMon
114 | #define read_stdin RdStdin
115 | #define write_stdout WrStdout
116 | #endif /* NEED_SHORT_EXTERNAL_NAMES */
117 |
118 | /* Module selection routines for I/O modules. */
119 |
120 | EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
121 | EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
122 | boolean is_os2));
123 | EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
124 | EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
125 | EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
126 | EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
127 | EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
128 | EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
129 | EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
130 | EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
131 |
132 | /* cjpeg support routines (in rdswitch.c) */
133 |
134 | EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
135 | boolean force_baseline));
136 | EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
137 | EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg,
138 | boolean force_baseline));
139 | EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
140 | EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
141 |
142 | /* djpeg support routines (in rdcolmap.c) */
143 |
144 | EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
145 |
146 | /* common support routines (in cdjpeg.c) */
147 |
148 | EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
149 | EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
150 | cd_progress_ptr progress));
151 | EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
152 | EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
153 | EXTERN(FILE *) read_stdin JPP((void));
154 | EXTERN(FILE *) write_stdout JPP((void));
155 |
156 | /* miscellaneous useful macros */
157 |
158 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
159 | #define READ_BINARY "r"
160 | #define WRITE_BINARY "w"
161 | #else
162 | #ifdef VMS /* VMS is very nonstandard */
163 | #define READ_BINARY "rb", "ctx=stm"
164 | #define WRITE_BINARY "wb", "ctx=stm"
165 | #else /* standard ANSI-compliant case */
166 | #define READ_BINARY "rb"
167 | #define WRITE_BINARY "wb"
168 | #endif
169 | #endif
170 |
171 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */
172 | #define EXIT_FAILURE 1
173 | #endif
174 | #ifndef EXIT_SUCCESS
175 | #ifdef VMS
176 | #define EXIT_SUCCESS 1 /* VMS is very nonstandard */
177 | #else
178 | #define EXIT_SUCCESS 0
179 | #endif
180 | #endif
181 | #ifndef EXIT_WARNING
182 | #ifdef VMS
183 | #define EXIT_WARNING 1 /* VMS is very nonstandard */
184 | #else
185 | #define EXIT_WARNING 2
186 | #endif
187 | #endif
188 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpeg-turbo/jconfig.h:
--------------------------------------------------------------------------------
1 | /* jconfig.h. Generated from jconfig.h.in by configure. */
2 | /* Version ID for the JPEG library.
3 | * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
4 | */
5 | #define JPEG_LIB_VERSION 62
6 |
7 | /* Support arithmetic encoding */
8 | #define C_ARITH_CODING_SUPPORTED 1
9 |
10 | /* Support arithmetic decoding */
11 | #define D_ARITH_CODING_SUPPORTED 1
12 |
13 | /* Define if your compiler supports prototypes */
14 | #define HAVE_PROTOTYPES 1
15 |
16 | /* Define to 1 if you have the header file. */
17 | #define HAVE_STDDEF_H 1
18 |
19 | /* Define to 1 if you have the header file. */
20 | #define HAVE_STDLIB_H 1
21 |
22 | /* Define to 1 if the system has the type `unsigned char'. */
23 | #define HAVE_UNSIGNED_CHAR 1
24 |
25 | /* Define to 1 if the system has the type `unsigned short'. */
26 | #define HAVE_UNSIGNED_SHORT 1
27 |
28 | /* Define if you want use complete types */
29 | /* #undef INCOMPLETE_TYPES_BROKEN */
30 |
31 | /* Define if you have BSD-like bzero and bcopy */
32 | /* #undef NEED_BSD_STRINGS */
33 |
34 | /* Define if you need short function names */
35 | /* #undef NEED_SHORT_EXTERNAL_NAMES */
36 |
37 | /* Define if you have sys/types.h */
38 | #define NEED_SYS_TYPES_H 1
39 |
40 | /* Define if shift is unsigned */
41 | /* #undef RIGHT_SHIFT_IS_UNSIGNED */
42 |
43 | /* Use accelerated SIMD routines. */
44 | #define WITH_SIMD 1
45 |
46 | /* Define to 1 if type `char' is unsigned and you are not using gcc. */
47 | #ifndef __CHAR_UNSIGNED__
48 | /* # undef __CHAR_UNSIGNED__ */
49 | #endif
50 |
51 | /* Define to empty if `const' does not conform to ANSI C. */
52 | /* #undef const */
53 |
54 | /* Define to `__inline__' or `__inline' if that's what the C compiler
55 | calls it, or to nothing if 'inline' is not supported under any name. */
56 | #ifndef __cplusplus
57 | /* #undef inline */
58 | #endif
59 |
60 | #define INLINE inline
61 |
62 | /* Define to `unsigned int' if does not define. */
63 | /* #undef size_t */
64 |
65 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpeg-turbo/jinclude.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jinclude.h
3 | *
4 | * Copyright (C) 1991-1994, Thomas G. Lane.
5 | * This file is part of the Independent JPEG Group's software.
6 | * For conditions of distribution and use, see the accompanying README file.
7 | *
8 | * This file exists to provide a single place to fix any problems with
9 | * including the wrong system include files. (Common problems are taken
10 | * care of by the standard jconfig symbols, but on really weird systems
11 | * you may have to edit this file.)
12 | *
13 | * NOTE: this file is NOT intended to be included by applications using the
14 | * JPEG library. Most applications need only include jpeglib.h.
15 | */
16 |
17 |
18 | /* Include auto-config file to find out which system include files we need. */
19 |
20 | #include "jconfig.h" /* auto configuration options */
21 | #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
22 |
23 | /*
24 | * We need the NULL macro and size_t typedef.
25 | * On an ANSI-conforming system it is sufficient to include .
26 | * Otherwise, we get them from or ; we may have to
27 | * pull in as well.
28 | * Note that the core JPEG library does not require ;
29 | * only the default error handler and data source/destination modules do.
30 | * But we must pull it in because of the references to FILE in jpeglib.h.
31 | * You can remove those references if you want to compile without .
32 | */
33 |
34 | #ifdef HAVE_STDDEF_H
35 | #include
36 | #endif
37 |
38 | #ifdef HAVE_STDLIB_H
39 | #include
40 | #endif
41 |
42 | #ifdef NEED_SYS_TYPES_H
43 | #include
44 | #endif
45 |
46 | #include
47 |
48 | /*
49 | * We need memory copying and zeroing functions, plus strncpy().
50 | * ANSI and System V implementations declare these in .
51 | * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().
52 | * Some systems may declare memset and memcpy in .
53 | *
54 | * NOTE: we assume the size parameters to these functions are of type size_t.
55 | * Change the casts in these macros if not!
56 | */
57 |
58 | #ifdef NEED_BSD_STRINGS
59 |
60 | #include
61 | #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
62 | #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
63 |
64 | #else /* not BSD, assume ANSI/SysV string lib */
65 |
66 | #include
67 | #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
68 | #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
69 |
70 | #endif
71 |
72 | /*
73 | * In ANSI C, and indeed any rational implementation, size_t is also the
74 | * type returned by sizeof(). However, it seems there are some irrational
75 | * implementations out there, in which sizeof() returns an int even though
76 | * size_t is defined as long or unsigned long. To ensure consistent results
77 | * we always use this SIZEOF() macro in place of using sizeof() directly.
78 | */
79 |
80 | #define SIZEOF(object) ((size_t) sizeof(object))
81 |
82 | /*
83 | * The modules that use fread() and fwrite() always invoke them through
84 | * these macros. On some systems you may need to twiddle the argument casts.
85 | * CAUTION: argument order is different from underlying functions!
86 | */
87 |
88 | #define JFREAD(file,buf,sizeofbuf) \
89 | ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
90 | #define JFWRITE(file,buf,sizeofbuf) \
91 | ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
92 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpeg-turbo/jversion.h:
--------------------------------------------------------------------------------
1 | /*
2 | * jversion.h
3 | *
4 | * Copyright (C) 1991-2010, Thomas G. Lane, Guido Vollbeding.
5 | * Copyright (C) 2010, D. R. Commander.
6 | * This file is part of the Independent JPEG Group's software.
7 | * For conditions of distribution and use, see the accompanying README file.
8 | *
9 | * This file contains software version identification.
10 | */
11 |
12 |
13 | #if JPEG_LIB_VERSION >= 80
14 |
15 | #define JVERSION "8b 16-May-2010"
16 |
17 | #define JCOPYRIGHT "Copyright (C) 2010, Thomas G. Lane, Guido Vollbeding"
18 |
19 | #elif JPEG_LIB_VERSION >= 70
20 |
21 | #define JVERSION "7 27-Jun-2009"
22 |
23 | #define JCOPYRIGHT "Copyright (C) 2009, Thomas G. Lane, Guido Vollbeding"
24 |
25 | #else
26 |
27 | #define JVERSION "6b 27-Mar-1998"
28 |
29 | #define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane"
30 |
31 | #endif
32 |
33 | #define LJTCOPYRIGHT "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
34 | "Copyright (C) 2009 Pierre Ossman for Cendio AB\n" \
35 | "Copyright (C) 2009-2011 D. R. Commander\n" \
36 | "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)"
37 |
--------------------------------------------------------------------------------
/light/src/main/jni/libjpegbither.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/light/src/main/jni/libjpegbither.so
--------------------------------------------------------------------------------
/light/src/main/libs/armeabi-v7a/libjpegbither.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/light/src/main/libs/armeabi-v7a/libjpegbither.so
--------------------------------------------------------------------------------
/light/src/main/libs/armeabi-v7a/liblight.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/light/src/main/libs/armeabi-v7a/liblight.so
--------------------------------------------------------------------------------
/light/src/main/libs/armeabi/libjpegbither.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/light/src/main/libs/armeabi/libjpegbither.so
--------------------------------------------------------------------------------
/light/src/main/libs/armeabi/liblight.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/light/src/main/libs/armeabi/liblight.so
--------------------------------------------------------------------------------
/light/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Light
3 |
4 |
--------------------------------------------------------------------------------
/light/src/test/java/com/light/core/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.light.core;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/pic1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/pic1.jpg
--------------------------------------------------------------------------------
/pic2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/pic2.jpg
--------------------------------------------------------------------------------
/pic3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JavaNoober/Light/542685d74227d325241eacbaeac99a7759e0ff3e/pic3.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':light'
2 |
--------------------------------------------------------------------------------