Fujifilm X Series Remote Control for Android (Prototype)
Fujifilm Xシリーズカメラの遠隔操作アプリ for Android (プロトタイプ)
Revisão | d7bb49e4815de46c59bd335fcd8179dbd307a4cc (tree) |
---|---|
Hora | 2019-05-06 09:20:37 |
Autor | MRSa <mrsa@myad...> |
Commiter | MRSa |
ライブビューデータを拾うために検討中。その5。
@@ -18,10 +18,18 @@ import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder; | ||
18 | 18 | |
19 | 19 | import androidx.annotation.NonNull; |
20 | 20 | |
21 | +import org.opencv.core.Mat; | |
22 | +import org.opencv.imgcodecs.Imgcodecs; | |
23 | + | |
21 | 24 | import java.io.File; |
22 | 25 | import java.io.FileInputStream; |
23 | 26 | import java.io.FileOutputStream; |
24 | 27 | import java.io.FileWriter; |
28 | +import java.nio.ByteBuffer; | |
29 | +import java.util.Arrays; | |
30 | + | |
31 | +import static org.opencv.core.CvType.CV_8UC1; | |
32 | +import static org.opencv.imgcodecs.Imgcodecs.IMREAD_COLOR; | |
25 | 33 | |
26 | 34 | public class CamTest implements View.OnClickListener, ILiveViewImage |
27 | 35 | { |
@@ -160,6 +168,8 @@ public class CamTest implements View.OnClickListener, ILiveViewImage | ||
160 | 168 | outputFile(receivedData); |
161 | 169 | |
162 | 170 | /////// Bitmap画像を作る... ////// |
171 | + final Bitmap imageData = getBitmap(receivedData); | |
172 | +/* | |
163 | 173 | final Bitmap imageData = BitmapFactory.decodeByteArray(dataValue, 18, (dataValue.length - 18)); |
164 | 174 | if (imageData == null) |
165 | 175 | { |
@@ -169,7 +179,7 @@ public class CamTest implements View.OnClickListener, ILiveViewImage | ||
169 | 179 | { |
170 | 180 | Log.v(TAG, "imageData : " + imageData.getByteCount() + " bytes."); |
171 | 181 | } |
172 | - | |
182 | +*/ | |
173 | 183 | ////// 画像を更新する |
174 | 184 | activity.runOnUiThread(new Runnable() { |
175 | 185 | @Override |
@@ -331,4 +341,29 @@ public class CamTest implements View.OnClickListener, ILiveViewImage | ||
331 | 341 | e.printStackTrace(); |
332 | 342 | } |
333 | 343 | } |
344 | + | |
345 | + private Bitmap getBitmap(ReceivedDataHolder receivedData) | |
346 | + { | |
347 | + Bitmap bitmap; | |
348 | + try { | |
349 | + final ByteBuffer dataValue = receivedData.getByteBuffer(); | |
350 | + final int dataLength = receivedData.getLength(); | |
351 | +// final byte[] imageBytes = Arrays.copyOfRange(dataValue, 18, dataValue.length); | |
352 | + | |
353 | + // OpenCVのデータ型に変換 | |
354 | + Mat rawData = new Mat( 1,dataLength, CV_8UC1, dataValue); | |
355 | + Mat decodedImage = Imgcodecs.imdecode(rawData, IMREAD_COLOR); | |
356 | + bitmap = Bitmap.createBitmap(decodedImage.width(), decodedImage.height(), Bitmap.Config.ARGB_8888); | |
357 | + //org.opencv.android.Utils.matToBitmap(decodedImage, bitmap); | |
358 | + | |
359 | + rawData.release(); | |
360 | + decodedImage.release(); | |
361 | + } | |
362 | + catch (Exception e) | |
363 | + { | |
364 | + e.printStackTrace(); | |
365 | + bitmap = null; | |
366 | + } | |
367 | + return (bitmap); | |
368 | + } | |
334 | 369 | } |
@@ -6,13 +6,14 @@ import androidx.annotation.NonNull; | ||
6 | 6 | |
7 | 7 | import java.io.BufferedReader; |
8 | 8 | import java.io.DataOutputStream; |
9 | +import java.io.InputStream; | |
9 | 10 | import java.io.InputStreamReader; |
10 | 11 | import java.net.Socket; |
11 | 12 | |
12 | 13 | class Communication |
13 | 14 | { |
14 | 15 | private final String TAG = toString(); |
15 | - private static final int BUFFER_SIZE = 131072 + 4; | |
16 | + private static final int BUFFER_SIZE = 1024 * 1024 + 8; | |
16 | 17 | |
17 | 18 | private static final int CONTROL_PORT = 55740; |
18 | 19 | private static final int ASYNC_RESPONSE_PORT = 55741; |
@@ -110,6 +111,7 @@ class Communication | ||
110 | 111 | |
111 | 112 | ReceivedDataHolder receive_from_camera() |
112 | 113 | { |
114 | +/* | |
113 | 115 | InputStreamReader isr; |
114 | 116 | char[] char_array = new char[BUFFER_SIZE]; |
115 | 117 | try |
@@ -125,6 +127,23 @@ class Communication | ||
125 | 127 | e.printStackTrace(); |
126 | 128 | } |
127 | 129 | return (new ReceivedDataHolder(char_array, 0)); |
130 | +*/ | |
131 | + try | |
132 | + { | |
133 | + byte[] byte_array = new byte[BUFFER_SIZE]; | |
134 | + InputStream is = socket.getInputStream(); | |
135 | + if (is != null) | |
136 | + { | |
137 | + int read_bytes = is.read(byte_array, 0, BUFFER_SIZE); | |
138 | + Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes."); | |
139 | + return (new ReceivedDataHolder(byte_array, read_bytes)); | |
140 | + } | |
141 | + } | |
142 | + catch (Exception e) | |
143 | + { | |
144 | + e.printStackTrace(); | |
145 | + } | |
146 | + return (new ReceivedDataHolder(new byte[0], 0)); | |
128 | 147 | } |
129 | 148 | |
130 | 149 | private void dump_bytes(String header, byte[] data) |
@@ -12,8 +12,9 @@ import java.util.Arrays; | ||
12 | 12 | public class ReceivedDataHolder |
13 | 13 | { |
14 | 14 | private final byte[] data; |
15 | + private static final int DATA_OFFSET = 18; | |
15 | 16 | |
16 | - public ReceivedDataHolder(byte[] data, int length) | |
17 | + ReceivedDataHolder(byte[] data, int length) | |
17 | 18 | { |
18 | 19 | this.data = Arrays.copyOfRange(data, 0, length); |
19 | 20 | } |
@@ -35,6 +36,18 @@ public class ReceivedDataHolder | ||
35 | 36 | return (data); |
36 | 37 | } |
37 | 38 | |
39 | + public ByteBuffer getByteBuffer() | |
40 | + { | |
41 | + ByteBuffer dataBuffer = ByteBuffer.allocateDirect(data.length - DATA_OFFSET); | |
42 | + dataBuffer.put(Arrays.copyOfRange(data, DATA_OFFSET, (data.length - DATA_OFFSET))); | |
43 | + return (dataBuffer); | |
44 | + } | |
45 | + | |
46 | + public int getLength() | |
47 | + { | |
48 | + return (data.length - DATA_OFFSET); | |
49 | + } | |
50 | + | |
38 | 51 | /** |
39 | 52 | * char[]からbyte[]に変換する |
40 | 53 | * (https://stackoverflow.com/questions/5513144/converting-char-to-byte より) |