OSDN Git Service

PowerShotZoomでスモール画像が取得できないので、標準画像を取得するような設定を用意。(スモール画像取得シーケンス TYPE2対応)
[gokigen/PKRemote.git] / app / src / main / java / net / osdn / gokigen / pkremote / camera / vendor / ptpip / wrapper / playback / CanonImageContentInfo.java
1 package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
2
3 import android.util.Log;
4
5 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
6
7 import java.util.Arrays;
8 import java.util.Date;
9 import java.util.TimeZone;
10
11 public class CanonImageContentInfo implements ICameraContent
12 {
13     private final String TAG = toString();
14     private final int indexNumber;
15     private final String contentPath;
16     private boolean isDateValid;
17     private Date date;
18     private final byte[] rx_body;
19
20     public CanonImageContentInfo(int indexNumber, String contentPath, byte[] binaryData, int offset, int length)
21     {
22         this.indexNumber = indexNumber;
23         this.contentPath = contentPath;
24         this.rx_body = Arrays.copyOfRange(binaryData, offset, offset + length);
25         try
26         {
27             //  撮影日時を解析
28             if (rx_body.length >= 0x33)
29             {
30                 long objectDate = (rx_body[0x30] & 0xff) + ((rx_body[0x31] & 0xff) << 8);
31                 objectDate = objectDate + ((rx_body[0x32] & 0xff) << 16) + ((rx_body[0x33] & 0xff) << 24);
32
33                 //  UTC から 端末のタイムゾーンに変換する(オフセット時間をとる)
34                 TimeZone tz = TimeZone.getDefault();
35                 Date now = new Date();
36                 long offsetFromUtc = tz.getOffset(now.getTime());
37
38                 date = new Date(objectDate * 1000 - offsetFromUtc);
39                 isDateValid = true;
40                 return;
41             }
42         }
43         catch (Exception e)
44         {
45             e.printStackTrace();
46         }
47         date = new Date();
48         isDateValid = false;
49         Log.v(TAG, "  > CONTENT : " + date + " ");
50     }
51
52     @Override
53     public String getCameraId()
54     {
55         return ("Canon");
56     }
57
58     @Override
59     public String getCardId()
60     {
61         return ("sd1");
62     }
63
64     @Override
65     public String getContentPath()
66     {
67         return (contentPath);
68     }
69
70     @Override
71     public String getContentName()
72     {
73         try
74         {
75             if (rx_body.length > 0x20)
76             {
77                 int copySize = (rx_body.length < (0x20 + 8 + 3)) ? rx_body.length : (0x20 + 8 + 1 + 3);
78                 byte[] fileNameArray = Arrays.copyOfRange(rx_body, 0x20, copySize);
79                 return (new String(fileNameArray));
80             }
81         }
82         catch (Exception e)
83         {
84             e.printStackTrace();
85         }
86         Log.v(TAG, "    > File Name : " + indexNumber + ".JPG");
87         return ("" + indexNumber + ".JPG");
88     }
89
90     @Override
91     public String getOriginalName()
92     {
93         return (getContentName());
94     }
95
96     @Override
97     public boolean isRaw()
98     {
99         try
100         {
101             String target = getContentName().toLowerCase();
102             return ((target.endsWith("crw")) || (target.endsWith("cr2")) || (target.endsWith("cr3")));
103         }
104         catch (Exception e)
105         {
106             e.printStackTrace();
107         }
108         return (false);
109     }
110
111     @Override
112     public boolean isMovie()
113     {
114         try
115         {
116             String target = getContentName().toLowerCase();
117             return ((target.endsWith("mov")) || (target.endsWith("mp4")));
118         }
119         catch (Exception e)
120         {
121             e.printStackTrace();
122         }
123         return (false);
124     }
125
126     @Override
127     public boolean isDateValid()
128     {
129         return (isDateValid);
130     }
131
132     @Override
133     public boolean isContentNameValid()
134     {
135         return (true);
136     }
137
138     @Override
139     public Date getCapturedDate()
140     {
141         return (date);
142     }
143
144     @Override
145     public void setCapturedDate(Date date)
146     {
147         try
148         {
149             this.date = date;
150             isDateValid = true;
151         }
152         catch (Exception e)
153         {
154             e.printStackTrace();
155         }
156     }
157
158     public int getId()
159     {
160         return (indexNumber);
161     }
162
163     public int getOriginalSize()
164     {
165         try
166         {
167             return((rx_body[0x14] & 0xff) + ((rx_body[0x15] & 0xff) << 8) +
168                     ((rx_body[0x16] & 0xff) << 16) + ((rx_body[0x17] & 0xff) << 24));
169         }
170         catch (Exception e)
171         {
172             e.printStackTrace();
173         }
174         // ちょっと大きめサイズを返す
175         return (0x02800000);
176     }
177
178     int getStorageId()
179     {
180         try
181         {
182             return ((rx_body[4] & 0xff) + ((rx_body[5] & 0xff) << 8) +
183                      ((rx_body[6] & 0xff) << 16) + ((rx_body[7] & 0xff) << 24));
184         }
185         catch (Exception e)
186         {
187             e.printStackTrace();
188         }
189         return (0x00010001);
190     }
191 }