1 //+----------------------------------------------------------------------------
3 // File: dc210photo.cpp
11 // Created: 15 Jan 2000
13 //+----------------------------------------------------------------------------
21 #include "dc210photo.h"
24 CKodakDC210Photo::CKodakDC210Photo(int iPictureNumber, CKodakDC210 *pCamera)
26 _fInitialized = false;
31 if (!_pCamera->SendCommand(DC210_PICTURE_INFO,
32 (((iPictureNumber - 1) & 0xFF00) >> 8),
33 (iPictureNumber - 1) & 0x00FF,
37 Trace("CKodakDC210Photo: Could not send command to camera.\n");
42 if (!_pCamera->ReadPacket(_bRawPictureData, 256))
45 // if this failes it means we have a bad picture -- the asked for
46 // a number that is not in the camera right now.
52 if (!_pCamera->CommandComplete())
54 Trace("CKodakDC210Photo: Did not get command complete signal.\n");
59 memcpy(_szFilename, &(_bRawPictureData[32]), 12);
61 _iNumber = iPictureNumber;
67 Trace("I should take a picture!\n\n");
75 CKodakDC210Photo::~CKodakDC210Photo(void)
77 _fInitialized = false;
82 DC210_COMPRESSION_STATE CKodakDC210Photo::GetCompression(void)
84 switch (_bRawPictureData[4])
87 return(compression_none);
90 return(compression_low);
93 return(compression_medium);
96 return(compression_high);
99 Trace("GetCompression: Illegal compression value.\n");
101 return(compression_none);
106 PICTURE_FORMAT CKodakDC210Photo::GetFormat(void)
108 if (2 == _bRawPictureData[2])
110 return(pictureformat_raw);
112 else if (3 == _bRawPictureData[2])
114 return(pictureformat_jpeg);
116 else if (4 == _bRawPictureData[2])
118 return(pictureformat_flashpix);
122 Trace("GetFormat: Illegal file format value.\n");
124 return(pictureformat_unknown);
129 int CKodakDC210Photo::GetSize(void)
131 return(_bRawPictureData[11] |
132 (_bRawPictureData[10] << 8) |
133 (_bRawPictureData[9] << 16) |
134 (_bRawPictureData[8] << 24));
137 int CKodakDC210Photo::GetTimeStamp(void)
139 return(_bRawPictureData[15] |
140 (_bRawPictureData[14] << 8) |
141 (_bRawPictureData[13] << 16) |
142 (_bRawPictureData[12] << 24));
145 bool CKodakDC210Photo::GetResolution(int *piWidth, int *piHeight)
147 if (0 == _bRawPictureData[3])
152 else if (1 == _bRawPictureData[3])
159 Trace("GetResolution: Illegal resolution setting.\n");
160 *piWidth = *piHeight = 0;
171 bool CKodakDC210Photo::WasFlashUsed(void)
173 return(_bRawPictureData[16]);
176 DC210_FLASH_STATE CKodakDC210Photo::GetFlashMode(void)
178 switch(_bRawPictureData[17])
190 return(flash_auto_redeye);
193 return(flash_fill_redeye);
196 Trace("GetFlashMode: Bad flash setting.\n");
198 return(flash_unknown);
202 int CKodakDC210Photo::GetLightValueData(void)
204 return(_bRawPictureData[18]);
208 float CKodakDC210Photo::GetCalculatedLightValue(void)
210 return ((6.5 + (0.125 * ((float)_bRawPictureData[18]))));
213 DC210_ZOOM_STATE CKodakDC210Photo::GetZoomPosition(void)
215 switch (_bRawPictureData[21])
218 return(zoom_fully_zoomed);
230 return(zoom_wideangle);
233 return(zoom_closeup);
236 Trace("GetZoomPosition: Illegal zoom setting.\n");
238 return(zoom_unknown);
242 int CKodakDC210Photo::GetExposureValue(void)
244 return(_bRawPictureData[23]);
247 int CKodakDC210Photo::GetApertureValue(void)
249 return(_bRawPictureData[26]);
252 int CKodakDC210Photo::GetExposureTimeMs(void)
254 return ((_bRawPictureData[31] |
255 (_bRawPictureData[30] << 8) |
256 (_bRawPictureData[29] << 16) |
257 (_bRawPictureData[28] << 24)) * 10);
260 float CKodakDC210Photo::GetExposureCompensationValue(void)
264 if (_bRawPictureData[46] & 0x40)
273 x *= (_bRawPictureData[46] * 0.5);
279 bool CKodakDC210Photo::GetData(BYTE **ppData, int *piLength)
285 BYTE *pbWritePos = NULL;
288 // Figure out how big the image is (in bytes).
290 if (0 == (iSize = GetSize()))
292 Trace("GetData: picture has no size?\n");
297 // Allocate the buffer
299 buf = (BYTE *) malloc(1024 * ((iSize / 1024) + 1));
302 Trace("GetData: Out of memory.\n");
308 // Ask the camera to send the image.
310 bMsb = ((_iNumber - 1) & 0xff00) >> 8;
311 bLsb = (_iNumber - 1) & 0x00ff;
312 if (!_pCamera->SendCommand(DC210_PICTURE_DOWNLOAD, bMsb, bLsb, 0, 0))
314 Trace("GetData: failed to send command.\n");
319 printf("Downloading: \n\n");
321 while (iBytesRead < iSize)
323 printf("%d / %d\n", iBytesRead, iSize);
324 if (!_pCamera->ReadPacket(pbWritePos, 1024))
326 Trace("GetData: error reading data packets from camera.\n");
334 buf = (BYTE *) realloc(buf, iSize);
337 Trace("GetData: Out of memory in realloc\n");
342 // Wait for the camera's command complete code.
344 if (!_pCamera->CommandComplete())
346 Trace("GetData: Did not receive command completion signal.\n");
359 bool CKodakDC210Photo::WriteData(void)
364 int iBytesWritten = 0;
370 if (!GetImageName(szFileName))
376 // Open a file to write this data to.
378 iFd = open(szFileName, O_WRONLY | O_APPEND | O_CREAT | O_TRUNC | O_EXLOCK);
381 Trace("GetData: can't open file.\n");
384 fchmod(iFd, S_IRWXU);
387 // Figure out how big the image is (in bytes).
389 if ((!GetSize(&iSize)) || (iSize <= 0))
391 Trace("GetData: picture has no size?\n");
396 // Ask the camera to send the image.
398 bMsb = (m_iNumber - 1) & 0xff00;
399 bLsb = (m_iNumber - 1) & 0x00ff;
400 if (!s_pCamera->SendCommand(DC210_PICTURE_DOWNLOAD, bMsb, bLsb, 0, 0))
402 Trace("GetData: failed to send command.\n");
406 printf("Downloading: \n\n");
408 while (iBytesRead < iSize)
410 printf("%d / %d\n", iBytesRead, iSize);
411 if (!s_pCamera->ReadPacket(buf, 1024))
413 Trace("GetData: error reading data packets from camera.\n");
419 // This was the last packet, only get the part we need...
421 if (iBytesRead > iSize)
423 iAmountNeeded = (1024 - (iBytesRead - iSize));
424 iBytesWritten = write(iFd, buf, iAmountNeeded);
425 if (iBytesWritten != iAmountNeeded)
427 Trace("GetData: write error.\n");
434 iBytesWritten = write(iFd, buf, 1024);
435 if (iBytesWritten != 1024)
437 Trace("GetData: write error.\n");
444 // Wait for the camera's command complete code.
446 if (!s_pCamera->CommandComplete())
448 Trace("GetData: Did not receive command completion signal.\n");
459 bool CDC210Picture::Delete(void)