lv2 fixes, dcraw upgrade, arch/libdv
[goodguy/history.git] / cinelerra-5.1 / cinelerra / dcraw.C
index 5a6f54210e5e67e99aeee454240a2fcb76223bc7..1913d982997569c181a857f109c9c5a055f56469 100644 (file)
@@ -1,6 +1,6 @@
 /*
    dcraw.c -- Dave Coffin's raw photo decoder
-   Copyright 1997-2016 by Dave Coffin, dcoffin a cybercom o net
+   Copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net
 
    This is a command-line ANSI C program to convert raw photos from
    any digital camera on any computer running any operating system.
    *If you have not modified dcraw.c in any way, a link to my
    homepage qualifies as "full source code".
 
-   $Revision: 1.477 $
-   $Date: 2016/05/10 21:30:43 $
+   $Revision: 1.478 $
+   $Date: 2018/06/01 20:36:25 $
  */
 
-#define DCRAW_VERSION "9.27"
+#define DCRAW_VERSION "9.28"
 
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
@@ -102,8 +102,9 @@ const float DCRaw_data::d65_white[3] = {
 
 /*
    All global variables are defined here, and all functions that
-   access them are prefixed with "CLASS".  Note that a thread-safe
-   C++ class cannot have non-const static local variables.
+   access them are prefixed with "CLASS".  For thread-safety, all
+   non-const static local variables except cbrt[] must be declared
+   "thread_local".
  */
 
 #define FORC(cnt) for (c=0; c < cnt; c++)
@@ -319,11 +320,22 @@ double CLASS getreal (int type)
   }
 }
 
+static void swabb(const void *bfrom, void *bto, ssize_t n)
+{
+  const char *from = (const char *) bfrom;
+  char *to = (char *) bto;
+  n &= ~((ssize_t) 1);
+  while (n > 1) {
+    const char b0 = from[--n], b1 = from[--n];
+    to[n] = b0;  to[n + 1] = b1;
+  }
+}
+
 void CLASS read_shorts (ushort *pixel, int count)
 {
   if (fread (pixel, 2, count, ifp) < count) derror();
   if ((order == 0x4949) == (ntohs(0x1234) == 0x1234))
-    swab (pixel, pixel, count*2);
+    swabb(pixel, pixel, count*2);
 }
 
 void CLASS cubic_spline (const int *x_, const int *y_, const int len)
@@ -1601,7 +1613,7 @@ void CLASS phase_one_correct()
            for (col = (qc ? ph1.split_col : 0);
                 col < (qc ? raw_width : ph1.split_col); col++)
              RAW(row,col) = curve[RAW(row,col)];
-        }
+       }
       }
       qmult_applied = 1;
       qlin_applied = 1;
@@ -1886,10 +1898,10 @@ void CLASS packed_load_raw()
   UINT64 bitbuf=0;
 
   bwide = raw_width * tiff_bps / 8;
-  bwide += bwide & load_flags >> 7;
+  bwide += bwide & load_flags >> 9;
   rbits = bwide * 8 - raw_width * tiff_bps;
   if (load_flags & 1) bwide = bwide * 16 / 15;
-  bite = 8 + (load_flags & 24);
+  bite = 8 + (load_flags & 56);
   half = (raw_height+1) >> 1;
   for (irow=0; irow < raw_height; irow++) {
     row = irow;
@@ -1907,10 +1919,10 @@ void CLASS packed_load_raw()
       for (vbits -= tiff_bps; vbits < 0; vbits += bite) {
        bitbuf <<= bite;
        for (i=0; i < bite; i+=8)
-         bitbuf |= (unsigned) (fgetc(ifp) << i);
+         bitbuf |= ((UINT64) fgetc(ifp) << i);
       }
       val = bitbuf << (64-tiff_bps-vbits) >> (64-tiff_bps);
-      RAW(row,col ^ (load_flags >> 6 & 1)) = val;
+      RAW(row,col ^ (load_flags >> 6 & 3)) = val;
       if (load_flags & 1 && (col % 10) == 9 && fgetc(ifp) &&
        row < height+top_margin && col < width+left_margin) derror();
     }
@@ -2048,6 +2060,14 @@ void CLASS olympus_load_raw()
   }
 }
 
+void CLASS canon_crx_load_raw()
+{
+}
+
+void CLASS fuji_xtrans_load_raw()
+{
+}
+
 void CLASS minolta_rd175_load_raw()
 {
   uchar pixel[768];
@@ -2262,7 +2282,7 @@ fill_input_buffer (j_decompress_ptr cinfo)
   size_t nbytes;
 
   nbytes = fread (jpeg_buffer, 1, 4096, ifp);
-  swab (jpeg_buffer, jpeg_buffer, nbytes);
+  swabb(jpeg_buffer, jpeg_buffer, nbytes);
   cinfo->src->next_input_byte = jpeg_buffer;
   cinfo->src->bytes_in_buffer = nbytes;
   return TRUE;
@@ -2727,7 +2747,7 @@ void CLASS samsung_load_raw()
       }
       for (c=0; c < 16; c+=2) {
        i = len[((c & 1) << 1) | (c >> 3)];
-        RAW(row,col+c) = ((signed) ph1_bits(i) << (32-i) >> (32-i)) +
+       RAW(row,col+c) = ((signed) ph1_bits(i) << (32-i) >> (32-i)) +
          (dir ? RAW(row+(~c | -2),col+c) : col ? RAW(row,col+(c | -2)) : 128);
        if (c == 14) c = -1;
       }
@@ -3755,7 +3775,7 @@ void CLASS crop_masked_pixels()
       load_raw == &CLASS sony_load_raw ||
      (load_raw == &CLASS eight_bit_load_raw && strncmp(model,"DC2",3)) ||
       load_raw == &CLASS kodak_262_load_raw ||
-     (load_raw == &CLASS packed_load_raw && (load_flags & 32))) {
+     (load_raw == &CLASS packed_load_raw && (load_flags & 256))) {
 sides:
     mask[0][0] = mask[1][0] = top_margin;
     mask[0][2] = mask[1][2] = top_margin+height;
@@ -5190,7 +5210,7 @@ void CLASS parse_makernote (int base, int uptag)
     offset = get4();
     fseek (ifp, offset-8, SEEK_CUR);
   } else if (!strcmp (buf,"OLYMPUS") ||
-             !strcmp (buf,"PENTAX ")) {
+            !strcmp (buf,"PENTAX ")) {
     base = ftell(ifp)-10;
     fseek (ifp, -2, SEEK_CUR);
     order = get2();
@@ -5712,14 +5732,13 @@ int CLASS parse_tiff_ifd (int base)
       case 258:                                /* BitsPerSample */
       case 61443:
        tiff_ifd[ifd].samples = len & 7;
-       tiff_ifd[ifd].bps = getint(type);
+       if ((tiff_ifd[ifd].bps = getint(type)) > 32)
+            tiff_ifd[ifd].bps = 8;
        if (tiff_bps < tiff_ifd[ifd].bps)
            tiff_bps = tiff_ifd[ifd].bps;
        break;
       case 61446:
        raw_height = 0;
-       if (tiff_ifd[ifd].bps > 12) break;
-       load_raw = &CLASS packed_load_raw;
        load_flags = get4() ? 24:80;
        break;
       case 259:                                /* Compression */
@@ -6007,7 +6026,7 @@ int CLASS parse_tiff_ifd (int base)
       case 50708:                      /* UniqueCameraModel */
        if (model[0]) break;
        fgets (make, 64, ifp);
-        if ((cp = strchr(make,' '))) {
+       if ((cp = strchr(make,' '))) {
          strcpy(model,cp+1);
          *cp = 0;
        }
@@ -6098,7 +6117,7 @@ guess_cfa_pc:
        width = getint(type) - left_margin;
        break;
       case 50830:                      /* MaskedAreas */
-        for (i=0; i < len && i < 32; i++)
+       for (i=0; i < len && i < 32; i++)
          ((int *)mask)[i] = getint(type);
        black = 0;
        break;
@@ -6220,6 +6239,7 @@ void CLASS apply_tiff()
       case 32767:
        if (tiff_ifd[raw].bytes == raw_width*raw_height) {
          tiff_bps = 12;
+         maximum = 4095;
          load_raw = &CLASS sony_arw2_load_raw;                 break;
        }
        if (tiff_ifd[raw].bytes*8 != raw_width*raw_height*tiff_bps) {
@@ -6235,6 +6255,9 @@ void CLASS apply_tiff()
        if (!strncmp(make,"OLYMPUS",7) &&
                tiff_ifd[raw].bytes*2 == raw_width*raw_height*3)
          load_flags = 24;
+       if (!strcmp(make,"SONY") && tiff_bps < 14 &&
+               tiff_ifd[raw].bytes == raw_width*raw_height*2)
+           tiff_bps = 14;
        if (tiff_ifd[raw].bytes*5 == raw_width*raw_height*8) {
          load_flags = 81;
          tiff_bps = 12;
@@ -6244,12 +6267,16 @@ void CLASS apply_tiff()
          case 12: if (tiff_ifd[raw].phint == 2)
                     load_flags = 6;
                   load_raw = &CLASS packed_load_raw;           break;
-         case 14: load_flags = 0;
+         case 14: load_raw = &CLASS packed_load_raw;
+                  if (tiff_ifd[raw].bytes*4 == raw_width*raw_height*7) break;
+                  load_flags = 0;
          case 16: load_raw = &CLASS unpacked_load_raw;
                   if (!strncmp(make,"OLYMPUS",7) &&
                        tiff_ifd[raw].bytes*7 > raw_width*raw_height)
                     load_raw = &CLASS olympus_load_raw;
        }
+       if (filters == 9 && tiff_ifd[raw].bytes*8 < raw_width*raw_height*tiff_bps)
+         load_raw = &CLASS fuji_xtrans_load_raw;
        break;
       case 6:  case 7:  case 99:
        load_raw = &CLASS lossless_jpeg_load_raw;               break;
@@ -6707,7 +6734,7 @@ void CLASS parse_fuji (int offset)
       FORC(36) xtrans_abs[0][35-c] = fgetc(ifp) & 3;
     } else if (tag == 0x2ff0) {
       FORC4 cam_mul[c ^ 1] = get2();
-    } else if (tag == 0xc000) {
+    } else if (tag == 0xc000 && len > 20000) {
       c = order;
       order = 0x4949;
       while ((tag = get4()) > raw_width);
@@ -6787,6 +6814,72 @@ void CLASS parse_riff()
     fseek (ifp, size, SEEK_CUR);
 }
 
+void CLASS parse_crx (int end)
+{
+  unsigned i, save, size, tag, base;
+  static int index=0, wide, high, off, len;
+
+  order = 0x4d4d;
+  while (ftell(ifp)+7 < end) {
+    save = ftell(ifp);
+    if ((size = get4()) < 8) break;
+    switch (tag = get4()) {
+      case 0x6d6f6f76:                         /* moov */
+      case 0x7472616b:                         /* trak */
+      case 0x6d646961:                         /* mdia */
+      case 0x6d696e66:                         /* minf */
+      case 0x7374626c:                         /* stbl */
+       parse_crx (save+size);
+       break;
+      case 0x75756964:                         /* uuid */
+       switch (i=get4()) {
+         case 0xeaf42b5e: fseek (ifp,  8, SEEK_CUR);
+         case 0x85c0b687: fseek (ifp, 12, SEEK_CUR);
+           parse_crx (save+size);
+       }
+       break;
+      case 0x434d5431:                         /* CMT1 */
+      case 0x434d5432:                         /* CMT2 */
+       base = ftell(ifp);
+       order = get2();
+       fseek (ifp, 6, SEEK_CUR);
+       tag & 1 ? (void)parse_tiff_ifd (base) : parse_exif (base);
+       order = 0x4d4d;
+       break;
+      case 0x746b6864:                         /* tkhd */
+       fseek (ifp, 12, SEEK_CUR);
+       index = get4();
+       fseek (ifp, 58, SEEK_CUR);
+       wide = get4();
+       high = get4();
+       break;
+      case 0x7374737a:                         /* stsz */
+       len = (get4(),get4());
+       break;
+      case 0x636f3634:                         /* co64 */
+       fseek (ifp, 12, SEEK_CUR);
+       off = get4();
+       switch (index) {
+         case 1:                       /* 1 = full size, 2 = 27% size */
+           thumb_width  = wide;
+           thumb_height = high;
+           thumb_length = len;
+           thumb_offset = off;
+           break;
+         case 3:
+           raw_width  = wide;
+           raw_height = high;
+           data_offset = off;
+           load_raw = &CLASS canon_crx_load_raw;
+       }
+       break;
+      case 0x50525657:                         /* PRVW */
+       fseek (ifp, 6, SEEK_CUR);
+    }
+    fseek (ifp, save+size, SEEK_SET);
+  }
+}
+
 void CLASS parse_qt (int end)
 {
   unsigned save, size;
@@ -7028,12 +7121,16 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6188,-1341,-890,-7168,14489,2937,-2640,3228,8483 } },
     { "Canon EOS 5DS", 0, 0x3c96,
        { 6250,-711,-808,-5153,12794,2636,-1249,2198,5610 } },
+    { "Canon EOS 5D Mark IV", 0, 0,
+       { 6446,-366,-864,-4436,12204,2513,-952,2496,6348 } },
     { "Canon EOS 5D Mark III", 0, 0x3c80,
        { 6722,-635,-963,-4287,12460,2028,-908,2162,5668 } },
     { "Canon EOS 5D Mark II", 0, 0x3cf0,
        { 4716,603,-830,-7798,15474,2480,-1496,1937,6651 } },
     { "Canon EOS 5D", 0, 0xe6c,
        { 6347,-479,-972,-8297,15954,2480,-1968,2131,7649 } },
+    { "Canon EOS 6D Mark II", 0, 0,
+       { 6875,-970,-932,-4691,12459,2501,-874,1953,5809 } },
     { "Canon EOS 6D", 0, 0x3c82,
        { 7034,-804,-1014,-4420,12564,2058,-851,1994,5758 } },
     { "Canon EOS 7D Mark II", 0, 0x3510,
@@ -7056,10 +7153,14 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6719,-994,-925,-4408,12426,2211,-887,2129,6051 } },
     { "Canon EOS 70D", 0, 0x3bc7,
        { 7034,-804,-1014,-4420,12564,2058,-851,1994,5758 } },
+    { "Canon EOS 77D", 0, 0,
+       { 7377,-742,-998,-4235,11981,2549,-673,1918,5538 } },
     { "Canon EOS 80D", 0, 0,
        { 7457,-671,-937,-4849,12495,2643,-1213,2354,5492 } },
     { "Canon EOS 100D", 0, 0x350f,
        { 6602,-841,-939,-4472,12458,2247,-975,2039,6148 } },
+    { "Canon EOS 200D", 0, 0,
+       { 7377,-742,-998,-4235,11981,2549,-673,1918,5538 } },
     { "Canon EOS 300D", 0, 0xfa0,
        { 8197,-2000,-1118,-6714,14335,2592,-2536,3178,8266 } },
     { "Canon EOS 350D", 0, 0xfff,
@@ -7082,6 +7183,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6362,-823,-847,-4426,12109,2616,-743,1857,5635 } },
     { "Canon EOS 760D", 0, 0x350f,
        { 6362,-823,-847,-4426,12109,2616,-743,1857,5635 } },
+    { "Canon EOS 800D", 0, 0,
+       { 6970,-512,-968,-4425,12161,2553,-739,1982,5601 } },
     { "Canon EOS 1000D", 0, 0xe43,
        { 6771,-1139,-977,-7818,15123,2928,-1244,1437,7533 } },
     { "Canon EOS 1100D", 0, 0x3510,
@@ -7090,8 +7193,18 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6461,-907,-882,-4300,12184,2378,-819,1944,5931 } },
     { "Canon EOS 1300D", 0, 0x3510,
        { 6939,-1016,-866,-4428,12473,2177,-1175,2178,6162 } },
+    { "Canon EOS 1500D", 0, 0,
+       { 8532,-701,-1167,-4095,11879,2508,-797,2424,7010 } },
+    { "Canon EOS 3000D", 0, 0,
+       { 6939,-1016,-866,-4428,12473,2177,-1175,2178,6162 } },
+    { "Canon EOS M6", 0, 0,
+       { 8532,-701,-1167,-4095,11879,2508,-797,2424,7010 } },
+    { "Canon EOS M5", 0, 0,    /* also M50 */
+       { 8532,-701,-1167,-4095,11879,2508,-797,2424,7010 } },
     { "Canon EOS M3", 0, 0,
        { 6362,-823,-847,-4426,12109,2616,-743,1857,5635 } },
+    { "Canon EOS M100", 0, 0,
+       { 8532,-701,-1167,-4095,11879,2508,-797,2424,7010 } },
     { "Canon EOS M10", 0, 0,
        { 6400,-480,-888,-5294,13416,2047,-1296,2203,6137 } },
     { "Canon EOS M", 0, 0,
@@ -7136,6 +7249,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 7474,-2301,-567,-4056,11456,2975,-222,716,4181 } },
     { "Canon PowerShot G16", 0, 0,
        { 8020,-2687,-682,-3704,11879,2052,-965,1921,5556 } },
+    { "Canon PowerShot G1 X Mark III", 0, 0,
+       { 8532,-701,-1167,-4095,11879,2508,-797,2424,7010 } },
     { "Canon PowerShot G1 X", 0, 0,
        { 7378,-1255,-1043,-4088,12251,2048,-876,1946,5805 } },
     { "Canon PowerShot G1", 0, 0,
@@ -7154,6 +7269,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 9877,-3775,-871,-7613,14807,3072,-1448,1305,7485 } },
     { "Canon PowerShot G7 X", 0, 0,
        { 9602,-3823,-937,-2984,11495,1675,-407,1415,5049 } },
+    { "Canon PowerShot G9 X Mark II", 0, 0,
+       { 10056,-4131,-944,-2576,11143,1625,-238,1294,5179 } },
     { "Canon PowerShot G9 X", 0, 0,
        { 9602,-3823,-937,-2984,11495,1675,-407,1415,5049 } },
     { "Canon PowerShot G9", 0, 0,
@@ -7248,6 +7365,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } },
     { "Fujifilm F8", 0, 0,
        { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } },
+    { "Fujifilm GFX 50S", 0, 0,
+       { 11756,-4754,-874,-3056,11045,2305,-381,1457,6006 } },
     { "Fujifilm S100FS", 514, 0,
        { 11521,-4355,-1065,-6524,13767,3058,-1466,1984,6045 } },
     { "Fujifilm S1", 0, 0,
@@ -7256,9 +7375,9 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 10004,-3219,-1201,-7036,15047,2107,-1863,2565,7736 } },
     { "Fujifilm S20", 512, 0x3fff,
        { 11401,-4498,-1312,-5088,12751,2613,-838,1568,5941 } },
-    { "Fujifilm S2Pro", 128, 0,
+    { "Fujifilm S2Pro", 128, 0xf15,
        { 12492,-4690,-1402,-7033,15423,1647,-1507,2111,7697 } },
-    { "Fujifilm S3Pro", 0, 0,
+    { "Fujifilm S3Pro", 0, 0x3dff,
        { 11807,-4612,-1294,-8927,16968,1988,-2120,2741,8006 } },
     { "Fujifilm S5Pro", 0, 0,
        { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } },
@@ -7292,7 +7411,7 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 12300,-5110,-1304,-9117,17143,1998,-1947,2448,8100 } },
     { "Fujifilm HS10 HS11", 0, 0xf68,
        { 12440,-3954,-1183,-1123,9674,1708,-83,1614,4086 } },
-    { "Fujifilm HS2", 0, 0,
+    { "Fujifilm HS2", 0, 0xfef,
        { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } },
     { "Fujifilm HS3", 0, 0,
        { 13690,-5358,-1474,-3369,11600,1998,-132,1554,4395 } },
@@ -7300,6 +7419,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 12085,-4727,-953,-3257,11489,2002,-511,2046,4592 } },
     { "Fujifilm F900EXR", 0, 0,
        { 12085,-4727,-953,-3257,11489,2002,-511,2046,4592 } },
+    { "Fujifilm X100F", 0, 0,
+       { 11434,-4948,-1210,-3746,12042,1903,-666,1479,5235 } },
     { "Fujifilm X100S", 0, 0,
        { 10592,-4262,-1008,-3514,11355,2465,-870,2025,6386 } },
     { "Fujifilm X100T", 0, 0,
@@ -7318,26 +7439,42 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 10413,-3996,-993,-3721,11640,2361,-733,1540,6011 } },
     { "Fujifilm X-Pro2", 0, 0,
        { 11434,-4948,-1210,-3746,12042,1903,-666,1479,5235 } },
+    { "Fujifilm X-A10", 0, 0,
+       { 11540,-4999,-991,-2949,10963,2278,-382,1049,5605 } },
+    { "Fujifilm X-A20", 0, 0,
+       { 11540,-4999,-991,-2949,10963,2278,-382,1049,5605 } },
     { "Fujifilm X-A1", 0, 0,
        { 11086,-4555,-839,-3512,11310,2517,-815,1341,5940 } },
     { "Fujifilm X-A2", 0, 0,
        { 10763,-4560,-917,-3346,11311,2322,-475,1135,5843 } },
+    { "Fujifilm X-A3", 0, 0,
+       { 12407,-5222,-1086,-2971,11116,2120,-294,1029,5284 } },
+    { "Fujifilm X-A5", 0, 0,
+       { 11673,-4760,-1041,-3988,12058,2166,-771,1417,5569 } },
     { "Fujifilm X-E1", 0, 0,
        { 10413,-3996,-993,-3721,11640,2361,-733,1540,6011 } },
     { "Fujifilm X-E2S", 0, 0,
        { 11562,-5118,-961,-3022,11007,2311,-525,1569,6097 } },
     { "Fujifilm X-E2", 0, 0,
        { 8458,-2451,-855,-4597,12447,2407,-1475,2482,6526 } },
+    { "Fujifilm X-E3", 0, 0,
+       { 11434,-4948,-1210,-3746,12042,1903,-666,1479,5235 } },
+    { "Fujifilm X-H1", 0, 0,
+       { 11434,-4948,-1210,-3746,12042,1903,-666,1479,5235 } },
     { "Fujifilm X-M1", 0, 0,
        { 10413,-3996,-993,-3721,11640,2361,-733,1540,6011 } },
     { "Fujifilm X-S1", 0, 0,
        { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } },
     { "Fujifilm X-T1", 0, 0,   /* also X-T10 */
        { 8458,-2451,-855,-4597,12447,2407,-1475,2482,6526 } },
+    { "Fujifilm X-T2", 0, 0,   /* also X-T20 */
+       { 11434,-4948,-1210,-3746,12042,1903,-666,1479,5235 } },
     { "Fujifilm XF1", 0, 0,
        { 13509,-6199,-1254,-4430,12733,1865,-331,1441,5022 } },
     { "Fujifilm XQ", 0, 0,     /* XQ1 and XQ2 */
        { 9252,-2704,-1064,-5893,14265,1717,-1101,2341,4349 } },
+    { "GoPro HERO5 Black", 0, 0,
+       { 10344,-4210,-620,-2315,10625,1948,93,1058,5541 } },
     { "Imacon Ixpress", 0, 0,          /* DJC */
        { 7025,-1415,-704,-5188,13765,1424,-1248,2742,6038 } },
     { "Kodak NC2000", 0, 0,
@@ -7450,6 +7587,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 7013,-1408,-635,-5268,12902,2640,-1470,2801,7379 } },
     { "Nikon D3300", 0, 0,
        { 6988,-1384,-714,-5631,13410,2447,-1485,2204,7318 } },
+    { "Nikon D3400", 0, 0,
+       { 6988,-1384,-714,-5631,13410,2447,-1485,2204,7318 } },
     { "Nikon D300", 0, 0,
        { 9030,-1992,-715,-8465,16302,2255,-2689,3217,8069 } },
     { "Nikon D3X", 0, 0,
@@ -7478,6 +7617,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6988,-1384,-714,-5631,13410,2447,-1485,2204,7318 } },
     { "Nikon D5500", 0, 0,
        { 8821,-2938,-785,-4178,12142,2287,-824,1651,6860 } },
+    { "Nikon D5600", 0, 0,
+       { 8821,-2938,-785,-4178,12142,2287,-824,1651,6860 } },
     { "Nikon D500", 0, 0,
        { 8813,-3210,-1036,-4703,12868,2021,-1054,1940,6129 } },
     { "Nikon D50", 0, 0,
@@ -7496,12 +7637,16 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 8322,-3112,-1047,-6367,14342,2179,-988,1638,6394 } },
     { "Nikon D7200", 0, 0,
        { 8322,-3112,-1047,-6367,14342,2179,-988,1638,6394 } },
+    { "Nikon D7500", 0, 0,
+       { 8813,-3210,-1036,-4703,12868,2021,-1054,1940,6129 } },
     { "Nikon D750", 0, 0,
        { 9020,-2890,-715,-4535,12436,2348,-934,1919,7086 } },
     { "Nikon D700", 0, 0,
        { 8139,-2171,-663,-8747,16541,2295,-1925,2008,8093 } },
     { "Nikon D70", 0, 0,
        { 7732,-2422,-789,-8238,15884,2498,-859,783,7330 } },
+    { "Nikon D850", 0, 0,
+       { 10405,-3755,-1270,-5461,13787,1793,-1040,2015,6785 } },
     { "Nikon D810", 0, 0,
        { 9369,-3195,-791,-4488,12430,2301,-893,1796,6872 } },
     { "Nikon D800", 0, 0,
@@ -7542,6 +7687,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 7971,-2314,-913,-8451,15762,2894,-1442,1520,7610 } },
     { "Nikon COOLPIX A", 0, 0,
        { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } },
+    { "Nikon COOLPIX B700", 200, 0,
+       { 14387,-6014,-1299,-1357,9975,1616,467,1047,4744 } },
     { "Nikon COOLPIX P330", 200, 0,
        { 10321,-3920,-931,-2750,11146,1824,-442,1545,5539 } },
     { "Nikon COOLPIX P340", 200, 0,
@@ -7640,12 +7787,18 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } },
     { "Olympus E-PL7", 0, 0,
        { 9197,-3190,-659,-2606,10830,2039,-458,1250,5458 } },
+    { "Olympus E-PL8", 0, 0,
+       { 9197,-3190,-659,-2606,10830,2039,-458,1250,5458 } },
+    { "Olympus E-PL9", 0, 0,
+       { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } },
     { "Olympus E-PM1", 0, 0,
        { 7575,-2159,-571,-3722,11341,2725,-1434,2819,6271 } },
     { "Olympus E-PM2", 0, 0,
        { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } },
-    { "Olympus E-M10", 0, 0,   /* also E-M10 Mark II */
+    { "Olympus E-M10", 0, 0,   /* also E-M10 Mark II & III */
        { 8380,-2630,-639,-2887,10725,2496,-627,1427,5438 } },
+    { "Olympus E-M1Mark II", 0, 0,
+       { 9383,-3170,-763,-2457,10702,2020,-384,1236,5552 } },
     { "Olympus E-M1", 0, 0,
        { 7687,-1984,-606,-4327,11928,2721,-1381,2339,6452 } },
     { "Olympus E-M5MarkII", 0, 0,
@@ -7674,6 +7827,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 8360,-2420,-880,-3928,12353,1739,-1381,2416,5173 } },
     { "Olympus TG-4", 0, 0,
        { 11426,-4159,-1126,-2066,10678,1593,-120,1327,4998 } },
+    { "Olympus TG-5", 0, 0,
+       { 10899,-3833,-1082,-2112,10736,1575,-267,1452,5269 } },
     { "Olympus XZ-10", 0, 0,
        { 9777,-3483,-925,-2886,11297,1800,-602,1663,5134 } },
     { "Olympus XZ-1", 0, 0,
@@ -7709,7 +7864,7 @@ void CLASS adobe_coeff (const char *make, const char *model)
     { "Pentax K-r", 0, 0,
        { 9895,-3077,-850,-5304,13035,2521,-883,1768,6936 } },
     { "Pentax K-1", 0, 0,
-       { 8566,-2746,-1201,-3612,12204,1550,-893,1680,6264 } },
+       { 8596,-2981,-639,-4202,12046,2431,-685,1424,6122 } },
     { "Pentax K-30", 0, 0,
        { 8710,-2632,-1167,-3995,12301,1881,-981,1719,6535 } },
     { "Pentax K-3 II", 0, 0,
@@ -7720,37 +7875,45 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 8170,-2725,-639,-4440,12017,2744,-771,1465,6599 } },
     { "Pentax K-5", 0, 0,
        { 8713,-2833,-743,-4342,11900,2772,-722,1543,6247 } },
+    { "Pentax K-70", 0, 0,
+       { 8270,-2117,-1299,-4359,12953,1515,-1078,1933,5975 } },
     { "Pentax K-7", 0, 0,
        { 9142,-2947,-678,-8648,16967,1663,-2224,2898,8615 } },
     { "Pentax K-S1", 0, 0,
        { 8512,-3211,-787,-4167,11966,2487,-638,1288,6054 } },
     { "Pentax K-S2", 0, 0,
        { 8662,-3280,-798,-3928,11771,2444,-586,1232,6054 } },
+    { "Pentax KP", 0, 0,
+       { 8617,-3228,-1034,-4674,12821,2044,-803,1577,5728 } },
     { "Pentax Q-S1", 0, 0,
        { 12995,-5593,-1107,-1879,10139,2027,-64,1233,4919 } },
     { "Pentax 645D", 0, 0x3e00,
        { 10646,-3593,-1158,-3329,11699,1831,-667,2874,6287 } },
     { "Panasonic DMC-CM1", 15, 0,
        { 8770,-3194,-820,-2871,11281,1803,-513,1552,4434 } },
+    { "Panasonic DC-FZ80", 0, 0,
+       { 8550,-2908,-842,-3195,11529,1881,-338,1603,4631 } },
     { "Panasonic DMC-FZ8", 0, 0xf7f,
        { 8986,-2755,-802,-6341,13575,3077,-1476,2144,6379 } },
     { "Panasonic DMC-FZ18", 0, 0,
        { 9932,-3060,-935,-5809,13331,2753,-1267,2155,5575 } },
     { "Panasonic DMC-FZ28", 15, 0xf96,
        { 10109,-3488,-993,-5412,12812,2916,-1305,2140,5543 } },
+    { "Panasonic DMC-FZ2500", 15, 0,
+       { 7386,-2443,-743,-3437,11864,1757,-608,1660,4766 } },
     { "Panasonic DMC-FZ330", 15, 0,
        { 8378,-2798,-769,-3068,11410,1877,-538,1792,4623 } },
     { "Panasonic DMC-FZ300", 15, 0,
        { 8378,-2798,-769,-3068,11410,1877,-538,1792,4623 } },
     { "Panasonic DMC-FZ30", 0, 0xf94,
        { 10976,-4029,-1141,-7918,15491,2600,-1670,2071,8246 } },
-    { "Panasonic DMC-FZ3", 15, 0,
+    { "Panasonic DMC-FZ3", 15, 0,      /* FZ35, FZ38 */
        { 9938,-2780,-890,-4604,12393,2480,-1117,2304,4620 } },
-    { "Panasonic DMC-FZ4", 15, 0,
+    { "Panasonic DMC-FZ4", 15, 0,      /* FZ40, FZ45 */
        { 13639,-5535,-1371,-1698,9633,2430,316,1152,4108 } },
     { "Panasonic DMC-FZ50", 0, 0,
        { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } },
-    { "Panasonic DMC-FZ7", 15, 0,
+    { "Panasonic DMC-FZ7", 15, 0,      /* FZ70, FZ72 */
        { 11532,-4324,-1066,-2375,10847,1749,-564,1699,4351 } },
     { "Leica V-LUX1", 0, 0,
        { 7906,-2709,-594,-6231,13351,3220,-1922,2631,6537 } },
@@ -7792,6 +7955,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 10148,-3743,-991,-2837,11366,1659,-701,1893,4899 } },
     { "Leica D-LUX 6", 15, 0,
        { 10148,-3743,-991,-2837,11366,1659,-701,1893,4899 } },
+    { "Panasonic DMC-LX9", 15, 0,
+       { 7790,-2736,-755,-3452,11870,1769,-628,1647,4898 } },
     { "Panasonic DMC-FZ1000", 15, 0,
        { 7830,-2696,-763,-3325,11667,1866,-641,1712,4824 } },
     { "Leica V-LUX (Typ 114)", 15, 0,
@@ -7824,6 +7989,10 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 8294,-2891,-651,-3869,11590,2595,-1183,2267,5352 } },
     { "Panasonic DMC-G7", 15, 0xfff,
        { 7610,-2780,-576,-4614,12195,2733,-1375,2393,6490 } },
+    { "Panasonic DMC-G8", 15, 0xfff,   /* G8, G80, G81, G85 */
+       { 7610,-2780,-576,-4614,12195,2733,-1375,2393,6490 } },
+    { "Panasonic DC-G9", 15, 0xfff,
+       { 7685,-2375,-634,-3687,11700,2249,-748,1546,5111 } },
     { "Panasonic DMC-GF1", 15, 0xf92,
        { 7888,-1902,-1011,-8106,16085,2099,-2353,2866,7330 } },
     { "Panasonic DMC-GF2", 15, 0xfff,
@@ -7838,6 +8007,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 7610,-2780,-576,-4614,12195,2733,-1375,2393,6490 } },
     { "Panasonic DMC-GF8", 15, 0,
        { 7610,-2780,-576,-4614,12195,2733,-1375,2393,6490 } },
+    { "Panasonic DC-GF9", 15, 0,
+       { 7610,-2780,-576,-4614,12195,2733,-1375,2393,6490 } },
     { "Panasonic DMC-GH1", 15, 0xf92,
        { 6299,-1466,-532,-6535,13852,2969,-2331,3112,5984 } },
     { "Panasonic DMC-GH2", 15, 0xf95,
@@ -7846,6 +8017,10 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6559,-1752,-491,-3672,11407,2586,-962,1875,5130 } },
     { "Panasonic DMC-GH4", 15, 0,
        { 7122,-2108,-512,-3155,11201,2231,-541,1423,5045 } },
+    { "Panasonic DC-GH5S", 15, 0,
+       { 6929,-2355,-708,-4192,12534,1828,-1097,1989,5195 } },
+    { "Panasonic DC-GH5", 15, 0,
+       { 7641,-2336,-605,-3218,11299,2187,-485,1338,5121 } },
     { "Panasonic DMC-GM1", 15, 0,
        { 6770,-1895,-744,-5232,13145,2303,-1664,2691,5703 } },
     { "Panasonic DMC-GM5", 15, 0,
@@ -7854,24 +8029,26 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6763,-1919,-863,-3868,11515,2684,-1216,2387,5879 } },
     { "Panasonic DMC-GX7", 15, 0,
        { 7610,-2780,-576,-4614,12195,2733,-1375,2393,6490 } },
+    { "Panasonic DMC-GX85", 15, 0,
+       { 7771,-3020,-629,-4029,11950,2345,-821,1977,6119 } },
     { "Panasonic DMC-GX8", 15, 0,
        { 7564,-2263,-606,-3148,11239,2177,-540,1435,4853 } },
-    { "Panasonic DMC-TZ1", 15, 0,
+    { "Panasonic DC-GX9", 15, 0,
+       { 7564,-2263,-606,-3148,11239,2177,-540,1435,4853 } },
+    { "Panasonic DMC-ZS100", 15, 0,
        { 7790,-2736,-755,-3452,11870,1769,-628,1647,4898 } },
-    { "Panasonic DMC-ZS1", 15, 0,
+    { "Panasonic DC-ZS200", 15, 0,
        { 7790,-2736,-755,-3452,11870,1769,-628,1647,4898 } },
-    { "Panasonic DMC-TZ6", 15, 0,
-       { 8607,-2822,-808,-3755,11930,2049,-820,2060,5224 } },
-    { "Panasonic DMC-ZS4", 15, 0,
+    { "Panasonic DMC-ZS40", 15, 0,
        { 8607,-2822,-808,-3755,11930,2049,-820,2060,5224 } },
-    { "Panasonic DMC-TZ7", 15, 0,
+    { "Panasonic DMC-ZS50", 15, 0,
        { 8802,-3135,-789,-3151,11468,1904,-550,1745,4810 } },
-    { "Panasonic DMC-ZS5", 15, 0,
-       { 8802,-3135,-789,-3151,11468,1904,-550,1745,4810 } },
-    { "Panasonic DMC-TZ8", 15, 0,
+    { "Panasonic DMC-TZ82", 15, 0,
        { 8550,-2908,-842,-3195,11529,1881,-338,1603,4631 } },
     { "Panasonic DMC-ZS6", 15, 0,
        { 8550,-2908,-842,-3195,11529,1881,-338,1603,4631 } },
+    { "Panasonic DMC-ZS70", 15, 0,
+       { 9052,-3117,-883,-3045,11346,1927,-205,1520,4730 } },
     { "Leica S (Typ 007)", 0, 0,
        { 6063,-2234,-231,-5210,13787,1500,-1043,2866,6997 } },
     { "Leica X", 0, 0,         /* X and X-U, both (Typ 113) */
@@ -7881,7 +8058,15 @@ void CLASS adobe_coeff (const char *make, const char *model)
     { "Leica M (Typ 262)", 0, 0,
        { 6653,-1486,-611,-4221,13303,929,-881,2416,7226 } },
     { "Leica SL (Typ 601)", 0, 0,
-       { 11865,-4523,-1441,-5423,14458,935,-1587,2687,4830} },
+       { 11865,-4523,-1441,-5423,14458,935,-1587,2687,4830 } },
+    { "Leica TL2", 0, 0,
+       { 5836,-1626,-647,-5384,13326,2261,-1207,2129,5861 } },
+    { "Leica TL", 0, 0,
+       { 5463,-988,-364,-4634,12036,2946,-766,1389,6522 } },
+    { "Leica CL", 0, 0,
+       { 7414,-2393,-840,-5127,13180,2138,-1585,2468,5064 } },
+    { "Leica M10", 0, 0,
+       { 8249,-2849,-620,-5415,14756,565,-957,3074,6517 } },
     { "Phase One H 20", 0, 0,          /* DJC */
        { 1313,1855,-109,-6715,15908,808,-327,1840,6020 } },
     { "Phase One H 25", 0, 0,
@@ -7952,16 +8137,20 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 8512,-2641,-694,-8042,15670,2526,-1821,2117,7414 } },
     { "Sony DSC-V3", 0, 0,
        { 7511,-2571,-692,-7894,15088,3060,-948,1111,8128 } },
-    { "Sony DSC-RX100M", 0, 0,         /* M2, M3, and M4 */
+    { "Sony DSC-RX100M", 0, 0,         /* M2, M3, M4, and M5 */
        { 6596,-2079,-562,-4782,13016,1933,-970,1581,5181 } },
     { "Sony DSC-RX100", 0, 0,
        { 8651,-2754,-1057,-3464,12207,1373,-568,1398,4434 } },
-    { "Sony DSC-RX10", 0, 0,           /* also RX10M2 */
+    { "Sony DSC-RX10M4", 0, 0,
+       { 7699,-2566,-629,-2967,11270,1928,-378,1286,4807 } },
+    { "Sony DSC-RX10", 0, 0,           /* also RX10M2, RX10M3 */
        { 6679,-1825,-745,-5047,13256,1953,-1580,2422,5183 } },
     { "Sony DSC-RX1RM2", 0, 0,
        { 6629,-1900,-483,-4618,12349,2550,-622,1381,6514 } },
     { "Sony DSC-RX1", 0, 0,
        { 6344,-1612,-462,-4863,12477,2681,-865,1786,6899 } },
+    { "Sony DSC-RX0", 200, 0,
+       { 9396,-3507,-843,-2497,11111,1572,-343,1355,5089 } },
     { "Sony DSLR-A100", 0, 0xfeb,
        { 9437,-2811,-774,-8405,16215,2290,-710,596,7181 } },
     { "Sony DSLR-A290", 0, 0,
@@ -7996,18 +8185,26 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 6435,-1903,-536,-4722,12449,2550,-663,1363,6517 } },
     { "Sony ILCA-77M2", 0, 0,
        { 5991,-1732,-443,-4100,11989,2381,-704,1467,5992 } },
-    { "Sony ILCE-6300", 0, 0,
+    { "Sony ILCA-99M2", 0, 0,
+       { 6660,-1918,-471,-4613,12398,2485,-649,1433,6447 } },
+    { "Sony ILCE-6", 0, 0,             /* 6300, 6500 */
        { 5973,-1695,-419,-3826,11797,2293,-639,1398,5789 } },
     { "Sony ILCE-7M2", 0, 0,
        { 5271,-712,-347,-6153,13653,2763,-1601,2366,7242 } },
+    { "Sony ILCE-7M3", 0, 0,
+       { 7374,-2389,-551,-5435,13162,2519,-1006,1795,6552 } },
     { "Sony ILCE-7S", 0, 0,    /* also ILCE-7SM2 */
        { 5838,-1430,-246,-3497,11477,2297,-748,1885,5778 } },
+    { "Sony ILCE-7RM3", 0, 0,
+       { 6640,-1847,-503,-5238,13010,2474,-993,1673,6527 } },
     { "Sony ILCE-7RM2", 0, 0,
        { 6629,-1900,-483,-4618,12349,2550,-622,1381,6514 } },
     { "Sony ILCE-7R", 0, 0,
        { 4913,-541,-202,-6130,13513,2906,-1564,2151,7183 } },
     { "Sony ILCE-7", 0, 0,
        { 5271,-712,-347,-6153,13653,2763,-1601,2366,7242 } },
+    { "Sony ILCE-9", 0, 0,
+       { 6389,-1703,-378,-4562,12265,2587,-670,1489,6550 } },
     { "Sony ILCE", 0, 0,       /* 3000, 5000, 5100, 6000, and QX1 */
        { 5991,-1456,-455,-4764,12135,2980,-707,1425,6701 } },
     { "Sony NEX-5N", 0, 0,
@@ -8050,6 +8247,8 @@ void CLASS adobe_coeff (const char *make, const char *model)
        { 5491,-1192,-363,-4951,12342,2948,-911,1722,7192 } },
     { "Sony SLT-A99", 0, 0,
        { 6344,-1612,-462,-4863,12477,2681,-865,1786,6899 } },
+    { "YI M1", 0, 0,
+       { 7712,-2059,-653,-3882,11494,2726,-710,1332,5958 } },
   };
   double cam_xyz[4][3];
   char name[130];
@@ -8205,8 +8404,11 @@ void CLASS identify()
     { 5712, 3774,  62, 20, 10,  2 },
     { 5792, 3804, 158, 51,  0,  0 },
     { 5920, 3950, 122, 80,  2,  0 },
+    { 6096, 4051,  76, 35,  0,  0 },
     { 6096, 4056,  72, 34,  0,  0 },
-    { 6288, 4056, 264, 34,  0,  0 },
+    { 6288, 4056, 264, 36,  0,  0 },
+    { 6384, 4224, 120, 44,  0,  0 },
+    { 6880, 4544, 136, 42,  0,  0 },
     { 8896, 5920, 160, 64,  0,  0 },
   };
   static const struct {
@@ -8220,7 +8422,10 @@ void CLASS identify()
     { 0x261, "EOS 50D" },    { 0x281, "EOS-1D Mark IV" },
     { 0x287, "EOS 60D" },    { 0x167, "EOS-1DS" },
     { 0x325, "EOS 70D" },
+    { 0x408, "EOS 77D" },    { 0x331, "EOS M" },
     { 0x350, "EOS 80D" },    { 0x328, "EOS-1D X Mark II" },
+    { 0x346, "EOS 100D" },
+    { 0x417, "EOS 200D" },
     { 0x170, "EOS 300D" },   { 0x188, "EOS-1Ds Mark II" },
     { 0x176, "EOS 450D" },   { 0x215, "EOS-1Ds Mark III" },
     { 0x189, "EOS 350D" },   { 0x324, "EOS-1D C" },
@@ -8231,12 +8436,14 @@ void CLASS identify()
     { 0x301, "EOS 650D" },   { 0x302, "EOS 6D" },
     { 0x326, "EOS 700D" },   { 0x250, "EOS 7D" },
     { 0x393, "EOS 750D" },   { 0x289, "EOS 7D Mark II" },
-    { 0x347, "EOS 760D" },
+    { 0x347, "EOS 760D" },   { 0x406, "EOS 6D Mark II" },
+    { 0x405, "EOS 800D" },   { 0x349, "EOS 5D Mark IV" },
     { 0x254, "EOS 1000D" },
     { 0x288, "EOS 1100D" },
-    { 0x327, "EOS 1200D" },  { 0x382, "Canon EOS 5DS" },
-    { 0x404, "EOS 1300D" },  { 0x401, "Canon EOS 5DS R" },
-    { 0x346, "EOS 100D" },
+    { 0x327, "EOS 1200D" },  { 0x382, "EOS 5DS" },
+    { 0x404, "EOS 1300D" },  { 0x401, "EOS 5DS R" },
+    { 0x422, "EOS 1500D" },
+    { 0x432, "EOS 3000D" },
   }, sonique[] = {
     { 0x002, "DSC-R1" },     { 0x100, "DSLR-A100" },
     { 0x101, "DSLR-A900" },  { 0x102, "DSLR-A700" },
@@ -8266,7 +8473,30 @@ void CLASS identify()
     { 0x155, "DSC-RX100M4" },{ 0x156, "DSC-RX10M2" },
     { 0x158, "DSC-RX1RM2" }, { 0x15a, "ILCE-QX1" },
     { 0x15b, "ILCE-7RM2" },  { 0x15e, "ILCE-7SM2" },
-    { 0x161, "ILCA-68" },    { 0x165, "ILCE-6300" },
+    { 0x161, "ILCA-68" },    { 0x162, "ILCA-99M2" },
+    { 0x163, "DSC-RX10M3" }, { 0x164, "DSC-RX100M5" },
+    { 0x165, "ILCE-6300" },  { 0x166, "ILCE-9" },
+    { 0x168, "ILCE-6500" },  { 0x16a, "ILCE-7RM3" },
+    { 0x16b, "ILCE-7M3" },   { 0x16c, "DSC-RX0" },
+    { 0x16d, "DSC-RX10M4" },
+  };
+  static const char *orig, panalias[][12] = {
+    "@DC-FZ80", "DC-FZ82", "DC-FZ85",
+    "@DC-FZ81", "DC-FZ83",
+    "@DC-GF9", "DC-GX800", "DC-GX850",
+    "@DC-GF10", "DC-GF90",
+    "@DC-GX9", "DC-GX7MK3",
+    "@DC-ZS70", "DC-TZ90", "DC-TZ91", "DC-TZ92", "DC-TZ93",
+    "@DMC-FZ40", "DMC-FZ45",
+    "@DMC-FZ2500", "DMC-FZ2000", "DMC-FZH1",
+    "@DMC-G8", "DMC-G80", "DMC-G81", "DMC-G85",
+    "@DMC-GX85", "DMC-GX80", "DMC-GX7MK2",
+    "@DMC-LX9", "DMC-LX10", "DMC-LX15",
+    "@DMC-ZS40", "DMC-TZ60", "DMC-TZ61",
+    "@DMC-ZS50", "DMC-TZ70", "DMC-TZ71",
+    "@DMC-ZS60", "DMC-TZ80", "DMC-TZ81", "DMC-TZ85",
+    "@DMC-ZS100", "DMC-ZS110", "DMC-TZ100", "DMC-TZ101", "DMC-TZ110", "DMC-TX1",
+    "@DC-ZS200", "DC-TX2", "DC-TZ200", "DC-TZ202", "DC-TZ220", "DC-ZS220",
   };
   static const struct {
     unsigned fsize;
@@ -8286,24 +8516,24 @@ void CLASS identify()
     { 15980544,3264,2448, 0, 0, 0, 0, 8,0x61,0,1,"AgfaPhoto","DC-833m" },
     {  9631728,2532,1902, 0, 0, 0, 0,96,0x61,0,0,"Alcatel","5035D" },
     {  2868726,1384,1036, 0, 0, 0, 0,64,0x49,0,8,"Baumer","TXG14",1078 },
-    {  5298000,2400,1766,12,12,44, 2,40,0x94,0,2,"Canon","PowerShot SD300" },
-    {  6553440,2664,1968, 4, 4,44, 4,40,0x94,0,2,"Canon","PowerShot A460" },
-    {  6573120,2672,1968,12, 8,44, 0,40,0x94,0,2,"Canon","PowerShot A610" },
-    {  6653280,2672,1992,10, 6,42, 2,40,0x94,0,2,"Canon","PowerShot A530" },
-    {  7710960,2888,2136,44, 8, 4, 0,40,0x94,0,2,"Canon","PowerShot S3 IS" },
-    {  9219600,3152,2340,36,12, 4, 0,40,0x94,0,2,"Canon","PowerShot A620" },
-    {  9243240,3152,2346,12, 7,44,13,40,0x49,0,2,"Canon","PowerShot A470" },
-    { 10341600,3336,2480, 6, 5,32, 3,40,0x94,0,2,"Canon","PowerShot A720 IS" },
-    { 10383120,3344,2484,12, 6,44, 6,40,0x94,0,2,"Canon","PowerShot A630" },
-    { 12945240,3736,2772,12, 6,52, 6,40,0x94,0,2,"Canon","PowerShot A640" },
-    { 15636240,4104,3048,48,12,24,12,40,0x94,0,2,"Canon","PowerShot A650" },
-    { 15467760,3720,2772, 6,12,30, 0,40,0x94,0,2,"Canon","PowerShot SX110 IS" },
-    { 15534576,3728,2778,12, 9,44, 9,40,0x94,0,2,"Canon","PowerShot SX120 IS" },
-    { 18653760,4080,3048,24,12,24,12,40,0x94,0,2,"Canon","PowerShot SX20 IS" },
-    { 19131120,4168,3060,92,16, 4, 1,40,0x94,0,2,"Canon","PowerShot SX220 HS" },
-    { 21936096,4464,3276,25,10,73,12,40,0x16,0,2,"Canon","PowerShot SX30 IS" },
-    { 24724224,4704,3504, 8,16,56, 8,40,0x94,0,2,"Canon","PowerShot A3300 IS" },
-    { 30858240,5248,3920, 8,16,56,16,40,0x94,0,2,"Canon","IXUS 160" },
+    {  5298000,2400,1766,12,12,44, 2, 8,0x94,0,2,"Canon","PowerShot SD300" },
+    {  6553440,2664,1968, 4, 4,44, 4, 8,0x94,0,2,"Canon","PowerShot A460" },
+    {  6573120,2672,1968,12, 8,44, 0, 8,0x94,0,2,"Canon","PowerShot A610" },
+    {  6653280,2672,1992,10, 6,42, 2, 8,0x94,0,2,"Canon","PowerShot A530" },
+    {  7710960,2888,2136,44, 8, 4, 0, 8,0x94,0,2,"Canon","PowerShot S3 IS" },
+    {  9219600,3152,2340,36,12, 4, 0, 8,0x94,0,2,"Canon","PowerShot A620" },
+    {  9243240,3152,2346,12, 7,44,13, 8,0x49,0,2,"Canon","PowerShot A470" },
+    { 10341600,3336,2480, 6, 5,32, 3, 8,0x94,0,2,"Canon","PowerShot A720 IS" },
+    { 10383120,3344,2484,12, 6,44, 6, 8,0x94,0,2,"Canon","PowerShot A630" },
+    { 12945240,3736,2772,12, 6,52, 6, 8,0x94,0,2,"Canon","PowerShot A640" },
+    { 15636240,4104,3048,48,12,24,12, 8,0x94,0,2,"Canon","PowerShot A650" },
+    { 15467760,3720,2772, 6,12,30, 0, 8,0x94,0,2,"Canon","PowerShot SX110 IS" },
+    { 15534576,3728,2778,12, 9,44, 9, 8,0x94,0,2,"Canon","PowerShot SX120 IS" },
+    { 18653760,4080,3048,24,12,24,12, 8,0x94,0,2,"Canon","PowerShot SX20 IS" },
+    { 19131120,4168,3060,92,16, 4, 1, 8,0x94,0,2,"Canon","PowerShot SX220 HS" },
+    { 21936096,4464,3276,25,10,73,12, 8,0x16,0,2,"Canon","PowerShot SX30 IS" },
+    { 24724224,4704,3504, 8,16,56, 8, 8,0x94,0,2,"Canon","PowerShot A3300 IS" },
+    { 30858240,5248,3920, 8,16,56,16, 8,0x94,0,2,"Canon","IXUS 160" },
     {  1976352,1632,1211, 0, 2, 0, 1, 0,0x94,0,1,"Casio","QV-2000UX" },
     {  3217760,2080,1547, 0, 0,10, 1, 0,0x94,0,1,"Casio","QV-3*00EX" },
     {  6218368,2585,1924, 0, 0, 9, 0, 0,0x94,0,1,"Casio","QV-5700" },
@@ -8376,12 +8606,13 @@ void CLASS identify()
     { 44390468,4080,5440, 0, 0, 0, 0,33,0x61,0,0,"Sinar","",68 },
     {  1409024,1376,1024, 0, 0, 1, 0, 0,0x49,0,0,"Sony","XCD-SX910CR" },
     {  2818048,1376,1024, 0, 0, 1, 0,97,0x49,0,0,"Sony","XCD-SX910CR" },
+    { 17496000,4320,3240, 0, 0, 0,0,224,0x94,0,0,"Xiro","Xplorer V" },
   };
   static const char *corp[] =
     { "AgfaPhoto", "Canon", "Casio", "Epson", "Fujifilm",
       "Mamiya", "Minolta", "Motorola", "Kodak", "Konica", "Leica",
       "Nikon", "Nokia", "Olympus", "Ricoh", "Pentax", "Phase One",
-      "Samsung", "Sigma", "Sinar", "Sony" };
+      "Samsung", "Sigma", "Sinar", "Sony", "YI" };
   char head[32], *cp;
   int hlen, flen, fsize, zero_fsize=1, i, c;
   struct jhead jh;
@@ -8469,14 +8700,20 @@ void CLASS identify()
       if (is_raw == 2 && shot_select)
        parse_fuji (i);
     }
-    load_raw = &CLASS unpacked_load_raw;
     fseek (ifp, 100+28*(shot_select > 0), SEEK_SET);
     parse_tiff (data_offset = get4());
     parse_tiff (thumb_offset+12);
     apply_tiff();
+    if (!load_raw) {
+      load_raw = &CLASS unpacked_load_raw;
+      tiff_bps = 14;
+    }
   } else if (!memcmp (head,"RIFF",4)) {
     fseek (ifp, 0, SEEK_SET);
     parse_riff();
+  } else if (!memcmp (head+4,"ftypcrx ",8)) {
+    fseek (ifp, 0, SEEK_SET);
+    parse_crx (fsize);
   } else if (!memcmp (head+4,"ftypqt   ",9)) {
     fseek (ifp, 0, SEEK_SET);
     parse_qt (fsize);
@@ -8572,7 +8809,8 @@ void CLASS identify()
          case 8:
            load_raw = &CLASS eight_bit_load_raw;  break;
          case 10: case 12:
-           load_flags |= 128;
+           load_flags |= 512;
+           if (!strcmp(make,"Canon")) load_flags |= 256;
            load_raw = &CLASS packed_load_raw;     break;
          case 16:
            order = 0x4949 | 0x404 * (load_flags & 1);
@@ -8627,17 +8865,25 @@ void CLASS identify()
     { height  = 2616;   width  = 3896; }
   if (height == 3136 && width == 4864)  /* Pentax K20D and Samsung GX20 */
     { height  = 3124;   width  = 4688; filters = 0x16161616; }
-  if (width == 4352 && (!strcmp(model,"K-r") || !strcmp(model,"K-x")))
+  if (raw_height == 2868 && (!strcmp(model,"K-r") || !strcmp(model,"K-x")))
     {                  width  = 4309; filters = 0x16161616; }
-  if (width >= 4960 && !strncmp(model,"K-5",3))
-    { left_margin = 10; width  = 4950; filters = 0x16161616; }
-  if (width == 4736 && !strcmp(model,"K-7"))
+  if (raw_height == 3136 && !strcmp(model,"K-7"))
     { height  = 3122;   width  = 4684; filters = 0x16161616; top_margin = 2; }
-  if (width == 6080 && !strcmp(model,"K-3"))
-    { left_margin = 4;  width  = 6040; }
-  if (width == 7424 && !strcmp(model,"645D"))
-    { height  = 5502;   width  = 7328; filters = 0x61616161; top_margin = 29;
-      left_margin = 48; }
+  if (raw_height == 3284 && !strncmp(model,"K-5",3))
+    { left_margin = 10; width  = 4950; filters = 0x16161616; }
+  if (raw_height == 3300 && !strncmp(model,"K-50",4))
+    { height  = 3288,   width  = 4952;  left_margin = 0;  top_margin = 12; }
+  if (raw_height == 3664 && !strncmp(model,"K-S",3))
+    {                  width  = 5492;  left_margin = 0; }
+  if (raw_height == 4032 && !strcmp(model,"K-3"))
+    { height  = 4032;   width  = 6040;  left_margin = 4; }
+  if (raw_height == 4060 && !strcmp(model,"KP"))
+    { height  = 4032;   width  = 6032;  left_margin = 52; top_margin = 28; }
+  if (raw_height == 4950 && !strcmp(model,"K-1"))
+    { height  = 4932;   width  = 7380;  left_margin = 4;  top_margin = 18; }
+  if (raw_height == 5552 && !strcmp(model,"645D"))
+    { height  = 5502;   width  = 7328;  left_margin = 48; top_margin = 29;
+      filters = 0x61616161; }
   if (height == 3014 && width == 4096) /* Ricoh GX200 */
                        width  = 4014;
   if (dng_version) {
@@ -8682,6 +8928,10 @@ void CLASS identify()
   for (i=0; i < sizeof sonique / sizeof *sonique; i++)
     if (unique_id == sonique[i].id)
       strcpy (model, sonique[i].model);
+  for (i=0; i < sizeof panalias / sizeof *panalias; i++)
+    if (panalias[i][0] == '@') orig = panalias[i]+1;
+    else if (!strcmp(model,panalias[i]))
+      adobe_coeff ("Panasonic", orig);
   if (!strcmp(make,"Nikon")) {
     if (!load_raw)
       load_raw = &CLASS packed_load_raw;
@@ -8749,7 +8999,7 @@ canon_a5:
     colors = 4;
     tiff_bps = 10;
     load_raw = &CLASS packed_load_raw;
-    load_flags = 40;
+    load_flags = 264;
   } else if (!strcmp(model,"PowerShot Pro90 IS") ||
             !strcmp(model,"PowerShot G1")) {
     colors = 4;
@@ -8761,6 +9011,9 @@ canon_a5:
   } else if (!strcmp(model,"EOS D2000C")) {
     filters = 0x61616161;
     black = curve[200];
+  } else if (!strcmp(model,"EOS 80D")) {
+    top_margin -= 2;
+    height += 2;
   } else if (!strcmp(model,"D1")) {
     cam_mul[0] *= 256/527.0;
     cam_mul[2] *= 256/317.0;
@@ -8815,6 +9068,8 @@ canon_a5:
     else width -= 8;
   } else if (!strncmp(model,"D300",4)) {
     width -= 32;
+  } else if (!strncmp(model,"COOLPIX B",9)) {
+    load_flags = 24;
   } else if (!strncmp(model,"COOLPIX P",9) && raw_width != 4032) {
     load_flags = 24;
     filters = 0x94949494;
@@ -8887,12 +9142,11 @@ canon_a5:
       height = 2144;
       width  = 2880;
       flip = 6;
-    } else if (load_raw != &CLASS packed_load_raw)
-      maximum = (is_raw == 2 && shot_select) ? 0x2f00 : 0x3e00;
+    }
     top_margin = (raw_height - height) >> 2 << 1;
     left_margin = (raw_width - width ) >> 2 << 1;
     if (width == 2848 || width == 3664) filters = 0x16161616;
-    if (width == 4032 || width == 4952 || width == 6032) left_margin = 0;
+    if (width == 4032 || width == 4952 || width == 6032 || width == 8280) left_margin = 0;
     if (width == 3328 && (width -= 66)) left_margin = 34;
     if (width == 4936) left_margin = 4;
     if (!strcmp(model,"HS50EXR") ||
@@ -8954,7 +9208,7 @@ konica_400z:
   } else if (!strcmp(make,"Samsung") && raw_width == 4704) {
     height -= top_margin = 8;
     width -= 2 * (left_margin = 8);
-    load_flags = 32;
+    load_flags = 256;
   } else if (!strcmp(make,"Samsung") && raw_height == 3714) {
     height -= top_margin = 18;
     left_margin = raw_width - (width = 5536);
@@ -9024,6 +9278,11 @@ konica_400z:
       top_margin  = 4;
       left_margin = 41;
       filters = 0x61616161;
+    } else if (raw_width == 8384) {
+      height = 6208;
+      width  = 8280;
+      top_margin  = 96;
+      left_margin = 46;
     } else if (raw_width == 9044) {
       height = 6716;
       width  = 8964;
@@ -9137,6 +9396,8 @@ konica_400z:
       thumb_width  = 640;
     } else if (!strcmp(model,"TG-4")) {
       width -= 16;
+    } else if (!strcmp(model,"TG-5")) {
+      width -= 6;
     }
   } else if (!strcmp(model,"N Digital")) {
     height = 2047;
@@ -9182,11 +9443,6 @@ konica_400z:
     width -= 30;
   } else if (!strcmp(make,"Sony") && raw_width == 8000) {
     width -= 32;
-    if (!strncmp(model,"DSC",3)) {
-      tiff_bps = 14;
-      load_raw = &CLASS unpacked_load_raw;
-      black = 512;
-    }
   } else if (!strcmp(model,"DSLR-A100")) {
     if (width == 3880) {
       height--;
@@ -9831,7 +10087,7 @@ void CLASS write_ppm_tiff()
           FORCC ppm [col*colors+c] = curve[image[soff][c]] >> 8;
       else FORCC ppm2[col*colors+c] = curve[image[soff][c]];
     if (output_bps == 16 && !output_tiff && htons(0x55aa) != 0x55aa)
-      swab (ppm2, ppm2, width*colors*2);
+      swabb(ppm2, ppm2, width*colors*2);
     fwrite (ppm, colors*output_bps/8, width, ofp);
   }
   free (ppm);