@@ -1407,66 +1407,77 @@ static inline uint16_t
1407
1407
ptp_unpack_EOS_ImageFormat (PTPParams * params , const unsigned char * * data )
1408
1408
{
1409
1409
/*
1410
- EOS ImageFormat entries (of at least the 5DM2 and the 400D) look like this:
1411
- uint32: number of entries / generated files (1 or 2)
1412
- uint32: size of this entry in bytes (most likely always 0x10)
1413
- uint32: image type (1 == JPG, 6 == RAW)
1414
- uint32: image size (0 == Large, 1 == Medium, 2 == Small, 0xe == S1, 0xf == S2, 0x10 == S3)
1415
- uint32: image compression (2 == Standard/JPG, 3 == Fine/JPG, 4 == Lossles/RAW)
1416
- If the number of entries is 2 the last 4 uint32 repeat.
1417
-
1418
- example:
1419
- 0: 0x 1
1420
- 1: 0x 10
1421
- 2: 0x 6
1422
- 3: 0x 1
1423
- 4: 0x 4
1410
+ EOS ImageFormat entries look are a sequence of u32 values:
1411
+ 0: number of entries / generated files (1 or 2)
1412
+ 1: size of this entry in bytes (most likely always 0x10 = 4 x u32)
1413
+ 2: image type:
1414
+ 1 == JPG
1415
+ 6 == RAW
1416
+ 3: image size:
1417
+ 0 == L
1418
+ 1 == M
1419
+ 2 == S
1420
+ 5 == M1 (e.g. 5Ds)
1421
+ 6 == M2
1422
+ e == S1 (e.g. 5Dm3)
1423
+ f == S2
1424
+ 10 == S3
1425
+ 4: image compression:
1426
+ 0 == user: JPG (e.g. 1DX, R5m2)
1427
+ 1 == ???: JPG (e.g. 1DXm2, 1DXm3)
1428
+ 2 == coarse: JPG (all)
1429
+ 3 == fine: JPG/cRAW (all)
1430
+ 4 == lossless: RAW (all)
1431
+
1432
+ If the number of entries is 2 the values 1-4 repeat
1433
+
1434
+ example (cRAW + coarse S1 JPEG): 2 10 6 0 3 10 1 e 2
1424
1435
1425
1436
The idea is to simply 'condense' these values to just one uint16 to be able to conveniently
1426
- use the available enumeration facilities (look-up table). The image size and compression
1427
- values used to fully describe the image format, but at least since EOS M50 (with cRAW)
1428
- it is no longer true - we need to store RAW flag (8).
1429
- Hence we generate a uint16 with the four nibles set as follows:
1437
+ use the available enumeration facilities (look-up table).
1438
+ Hence we generate a u16 value with the four nibles set as follows:
1430
1439
1431
- entry 1 size | entry 1 compression & RAW flag | entry 2 size | entry 2 compression & RAW flag .
1440
+ entry 1 size | entry 1 type + compression | entry 2 size | entry 2 type + compression .
1432
1441
1433
- The above example would result in the value 0x1400.
1442
+ * The S3 value (0xf) would overflow the nible, hence we decrease all S1,S2,S3 values by 1.
1443
+ * The to encode the type RAW, we set the 4th bit in the compression nible to 1 (|= 8).
1444
+ * To distinguish an "empty" second entry from the "custom L JPEG", we set it to 0xff.
1434
1445
1435
- The EOS 5D Mark III (and possibly other high-end EOS as well) added the extra fancy S1, S2
1436
- and S3 JPEG options. S1 replaces the old Small. -1 the S1/S2/S3 to prevent the 0x10 overflow.
1437
- */
1446
+ The above example would result in the value 0x0bd2.
1447
+ */
1438
1448
1439
- const unsigned char * d = * data ;
1440
- uint32_t n = dtoh32a ( d );
1449
+ const uint8_t * d = * data ;
1450
+ uint32_t offset = 0 ;
1451
+ uint32_t n = dtoh32o (d , offset );
1441
1452
uint32_t l , t1 , s1 , c1 , t2 = 0 , s2 = 0 , c2 = 0 ;
1442
1453
1443
1454
if (n != 1 && n != 2 ) {
1444
1455
ptp_debug (params , "parsing EOS ImageFormat property failed (n != 1 && n != 2: %d)" , n );
1445
1456
return 0 ;
1446
1457
}
1447
1458
1448
- l = dtoh32a ( d += 4 );
1459
+ l = dtoh32o ( d , offset );
1449
1460
if (l != 0x10 ) {
1450
1461
ptp_debug (params , "parsing EOS ImageFormat property failed (l != 0x10: 0x%x)" , l );
1451
1462
return 0 ;
1452
1463
}
1453
1464
1454
- t1 = dtoh32a ( d += 4 );
1455
- s1 = dtoh32a ( d += 4 );
1456
- c1 = dtoh32a ( d += 4 );
1465
+ t1 = dtoh32o ( d , offset );
1466
+ s1 = dtoh32o ( d , offset );
1467
+ c1 = dtoh32o ( d , offset );
1457
1468
1458
1469
if (n == 2 ) {
1459
- l = dtoh32a ( d += 4 );
1470
+ l = dtoh32o ( d , offset );
1460
1471
if (l != 0x10 ) {
1461
1472
ptp_debug (params , "parsing EOS ImageFormat property failed (l != 0x10: 0x%x)" , l );
1462
1473
return 0 ;
1463
1474
}
1464
- t2 = dtoh32a ( d += 4 );
1465
- s2 = dtoh32a ( d += 4 );
1466
- c2 = dtoh32a ( d += 4 );
1475
+ t2 = dtoh32o ( d , offset );
1476
+ s2 = dtoh32o ( d , offset );
1477
+ c2 = dtoh32o ( d , offset );
1467
1478
}
1468
1479
1469
- * data = ( unsigned char * ) d + 4 ;
1480
+ * data += offset ;
1470
1481
1471
1482
/* deal with S1/S2/S3 JPEG sizes, see above. */
1472
1483
if ( s1 >= 0xe )
@@ -1478,31 +1489,35 @@ ptp_unpack_EOS_ImageFormat (PTPParams* params, const unsigned char** data )
1478
1489
c1 |= (t1 == 6 ) ? 8 : 0 ;
1479
1490
c2 |= (t2 == 6 ) ? 8 : 0 ;
1480
1491
1492
+ if (s2 == 0 && c2 == 0 )
1493
+ s2 = c2 = 0xF ;
1494
+
1481
1495
return ((s1 & 0xF ) << 12 ) | ((c1 & 0xF ) << 8 ) | ((s2 & 0xF ) << 4 ) | ((c2 & 0xF ) << 0 );
1482
1496
}
1483
1497
1484
1498
static inline uint32_t
1485
1499
ptp_pack_EOS_ImageFormat (PTPParams * params , unsigned char * data , uint16_t value )
1486
1500
{
1487
- uint32_t n = (value & 0xFF ) ? 2 : 1 ;
1501
+ uint32_t n = (value & 0xFF ) == 0xFF ? 1 : 2 ;
1488
1502
uint32_t s = 4 + 0x10 * n ;
1489
1503
1490
1504
if ( !data )
1491
1505
return s ;
1492
1506
1493
- #define PACK_5DM3_SMALL_JPEG_SIZE ( X ) (X) >= 0xd ? (X)+1 : (X)
1507
+ #define PACK_EOS_S123_JPEG_SIZE ( X ) (X) >= 0xd ? (X)+1 : (X)
1494
1508
1495
1509
htod32a (data += 0 , n );
1510
+
1496
1511
htod32a (data += 4 , 0x10 );
1497
- htod32a (data += 4 , ((( value >> 8 ) & 0xF ) >> 3 ) ? 6 : 1 );
1498
- htod32a (data += 4 , PACK_5DM3_SMALL_JPEG_SIZE ((value >> 12 ) & 0xF ));
1499
- htod32a (data += 4 , (( value >> 8 ) & 0xF ) & ~ 8 );
1512
+ htod32a (data += 4 , value & 0x0800 ? 6 : 1 );
1513
+ htod32a (data += 4 , PACK_EOS_S123_JPEG_SIZE ((value >> 12 ) & 0xF ));
1514
+ htod32a (data += 4 , (value >> 8 ) & 0x7 );
1500
1515
1501
1516
if (n == 2 ) {
1502
1517
htod32a (data += 4 , 0x10 );
1503
- htod32a (data += 4 , ((( value >> 0 ) & 0xF ) >> 3 ) ? 6 : 1 );
1504
- htod32a (data += 4 , PACK_5DM3_SMALL_JPEG_SIZE ((value >> 4 ) & 0xF ));
1505
- htod32a (data += 4 , (( value >> 0 ) & 0xF ) & ~ 8 );
1518
+ htod32a (data += 4 , value & 0x08 ? 6 : 1 );
1519
+ htod32a (data += 4 , PACK_EOS_S123_JPEG_SIZE ((value >> 4 ) & 0xF ));
1520
+ htod32a (data += 4 , (value >> 0 ) & 0x7 );
1506
1521
}
1507
1522
1508
1523
#undef PACK_5DM3_SMALL_JPEG_SIZE
0 commit comments