OSDN Git Service

LVとシャッター制御確認中。
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / camera / canon / wrapper / liveview / CanonLiveViewImageReceiver.java
1 package net.osdn.gokigen.a01d.camera.canon.wrapper.liveview;
2
3 import android.util.Log;
4
5 import androidx.annotation.NonNull;
6 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
7
8 import java.util.Arrays;
9
10 /**
11  *   Canonサムネイル画像の受信
12  *
13  *
14  */
15 public class CanonLiveViewImageReceiver implements IPtpIpCommandCallback
16 {
17     private final String TAG = toString();
18     private final ICanonLiveViewImageCallback callback;
19
20     CanonLiveViewImageReceiver(@NonNull ICanonLiveViewImageCallback callback)
21     {
22         this.callback = callback;
23     }
24
25     @Override
26     public void receivedMessage(int id, byte[] rx_body)
27     {
28         try
29         {
30             if (rx_body == null)
31             {
32                 Log.v(TAG, " BITMAP IS NONE...");
33                 callback.onCompleted(null, null);
34                 return;
35             }
36
37             /////// 受信データから、サムネイルの先頭(0xff 0xd8)を検索する  /////
38             int offset = rx_body.length - 22;
39             //byte[] thumbnail0 = Arrays.copyOfRange(rx_body, 0, rx_body.length);
40             while (offset > 32)
41             {
42                 if ((rx_body[offset] == (byte) 0xff)&&((rx_body[offset + 1] == (byte) 0xd8)))
43                 {
44                     break;
45                 }
46                 offset--;
47             }
48             byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length);
49             callback.onCompleted(thumbnail, null);
50         }
51         catch (Exception e)
52         {
53             e.printStackTrace();
54             {
55                 callback.onErrorOccurred(e);
56             }
57         }
58     }
59
60     @Override
61     public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
62     {
63         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
64     }
65
66     @Override
67     public boolean isReceiveMulti()
68     {
69         return (false);
70     }
71 }