Guest User

Experimental 64Byte Lens Name

a guest
Jan 10th, 2018
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/modules/lua/lua_lens.c b/modules/lua/lua_lens.c
  2. --- a/modules/lua/lua_lens.c
  3. +++ b/modules/lua/lua_lens.c
  4. @@ -82,7 +82,7 @@
  5.      if(!strcmp(key, "name"))
  6.      {
  7.          LUA_PARAM_STRING(value, 3);
  8. -        strncpy(lens_info.name, value, 31);
  9. +        strncpy(lens_info.name, value, sizeof(lens_info.name)-1);
  10.      }
  11.      else if(!strcmp(key, "exists"))
  12.      {
  13. diff --git a/modules/mlv_rec/mlv.c b/modules/mlv_rec/mlv.c
  14. --- a/modules/mlv_rec/mlv.c
  15. +++ b/modules/mlv_rec/mlv.c
  16. @@ -55,10 +55,33 @@
  17.      hdr->autofocusMode = af_mode;
  18.      hdr->flags = 0;
  19.  
  20. -    strncpy((char *)hdr->lensName, lens_info.name, 32);
  21. +    char name[33];
  22. +    snprintf(name, 32, "%s", lens_info.name);
  23. +    
  24. +    strncpy((char *)hdr->lensName, name, 32);
  25.      strncpy((char *)hdr->lensSerial, "", 32);
  26.  }
  27.  
  28. +void mlv_fill_elns(mlv_elns_hdr_t *hdr, uint64_t start_timestamp){
  29. +    /* prepare header */
  30. +    mlv_set_type((mlv_hdr_t *)hdr, "ELNS");
  31. +    mlv_set_timestamp((mlv_hdr_t *)hdr, start_timestamp);
  32. +    hdr->blockSize = sizeof(mlv_elns_hdr_t);
  33. +
  34. +    char bufName[65];
  35. +    snprintf(bufName, 64, "%s", lens_info.name);
  36. +
  37. +    strncpy((char *)hdr->lensName, bufName, 64);
  38. +    hdr->focalLengthMin = lens_info.lens_focal_min;
  39. +    hdr->focalLengthMax = lens_info.lens_focal_max;
  40. +    hdr->apertureMin = lens_info.raw_aperture_min;
  41. +    hdr->apertureMax = lens_info.raw_aperture_max;
  42. +    hdr->version = lens_info.lens_version;
  43. +    hdr->extenderInfo = lens_info.lens_extender;
  44. +    hdr->capabilities = lens_info.lens_capabilities;
  45. +    hdr->chipped = lens_info.lens_exists;
  46. +}
  47. +
  48.  void mlv_fill_wbal(mlv_wbal_hdr_t *hdr, uint64_t start_timestamp)
  49.  {
  50.      /* prepare header */
  51. diff --git a/modules/mlv_rec/mlv.h b/modules/mlv_rec/mlv.h
  52. --- a/modules/mlv_rec/mlv.h
  53. +++ b/modules/mlv_rec/mlv.h
  54. @@ -164,6 +164,21 @@
  55.  }  mlv_lens_hdr_t;
  56.  
  57.  typedef struct {
  58. +    uint8_t     blockType[4];    /* ELNS - Extended LENS block with longer lens name and optional fields, depending on camera */
  59. +    uint32_t    blockSize;
  60. +    uint64_t    timestamp;
  61. +    uint16_t    focalLengthMin;  /* shortest focal length in mm                       */
  62. +    uint16_t    focalLengthMax;  /* longest focal length in mm                        */
  63. +    uint16_t    apertureMin;     /* lowest f-number * 100                             */
  64. +    uint16_t    apertureMax;     /* highest f-number * 100                            */
  65. +    uint32_t    version;         /* lens internal version number, if available        */
  66. +    uint8_t     extenderInfo;    /* extender information, if provided by camera       */
  67. +    uint8_t     capabilities;    /* capability information, if provided by camera     */
  68. +    uint8_t     chipped;         /* when not zero, lens is communicating with camera  */
  69. +    uint8_t     lensName[64];     /* full lens string, null terminated                 */
  70. +}  mlv_elns_hdr_t;
  71. +
  72. +typedef struct {
  73.      uint8_t     blockType[4];
  74.      uint32_t    blockSize;    /* total frame size */
  75.      uint64_t    timestamp;    /* hardware counter timestamp for this frame (relative to recording start) */
  76. @@ -286,6 +301,7 @@
  77.  void mlv_fill_rtci(mlv_rtci_hdr_t *hdr, uint64_t start_timestamp);
  78.  void mlv_fill_expo(mlv_expo_hdr_t *hdr, uint64_t start_timestamp);
  79.  void mlv_fill_lens(mlv_lens_hdr_t *hdr, uint64_t start_timestamp);
  80. +void mlv_fill_elns(mlv_elns_hdr_t *hdr, uint64_t start_timestamp);
  81.  void mlv_fill_idnt(mlv_idnt_hdr_t *hdr, uint64_t start_timestamp);
  82.  void mlv_fill_wbal(mlv_wbal_hdr_t *hdr, uint64_t start_timestamp);
  83.  void mlv_fill_styl(mlv_styl_hdr_t *hdr, uint64_t start_timestamp);
  84. diff --git a/modules/mlv_rec/mlv_dump.c b/modules/mlv_rec/mlv_dump.c
  85. --- a/modules/mlv_rec/mlv_dump.c
  86. +++ b/modules/mlv_rec/mlv_dump.c
  87. @@ -1590,6 +1590,7 @@
  88.      lv_rec_file_footer_t lv_rec_footer;
  89.      mlv_file_hdr_t main_header;
  90.      mlv_lens_hdr_t lens_info;
  91. +    mlv_elns_hdr_t elns_info;
  92.      mlv_expo_hdr_t expo_info;
  93.      mlv_idnt_hdr_t idnt_info;
  94.      mlv_wbal_hdr_t wbal_info;
  95. @@ -1600,6 +1601,7 @@
  96.      /* initialize stuff */
  97.      memset(&lv_rec_footer, 0x00, sizeof(lv_rec_file_footer_t));
  98.      memset(&lens_info, 0x00, sizeof(mlv_lens_hdr_t));
  99. +    memset(&elns_info, 0x00, sizeof(mlv_elns_hdr_t));
  100.      memset(&expo_info, 0x00, sizeof(mlv_expo_hdr_t));
  101.      memset(&idnt_info, 0x00, sizeof(mlv_idnt_hdr_t));
  102.      memset(&wbal_info, 0x00, sizeof(mlv_wbal_hdr_t));
  103. @@ -2847,6 +2849,46 @@
  104.                      }
  105.                  }
  106.              }
  107. +            else if(!memcmp(buf.blockType, "ELNS", 4))
  108. +            {
  109. +                uint32_t hdr_size = MIN(sizeof(mlv_elns_hdr_t), buf.blockSize);
  110. +
  111. +                if(fread(&elns_info, hdr_size, 1, in_file) != 1)
  112. +                {
  113. +                    print_msg(MSG_ERROR, "File ends in the middle of a block\n");
  114. +                    goto abort;
  115. +                  }
  116. +
  117. +                /* skip remaining data, if there is any */
  118. +                file_set_pos(in_file, position + elns_info.blockSize, SEEK_SET);
  119. +
  120. +                lua_handle_hdr(lua_state, buf.blockType, &elns_info, sizeof(elns_info));
  121. +
  122. +                if(verbose)
  123. +                {
  124. +                    //TODO:
  125. +                    print_msg(MSG_INFO, "     Name:                '%s'\n", elns_info.lensName);
  126. +                    print_msg(MSG_INFO, "     Focal Length Min:    %d mm\n", elns_info.focalLengthMin);
  127. +                    print_msg(MSG_INFO, "     Focal Length Max:    %d mm\n", elns_info.focalLengthMax);
  128. +                    print_msg(MSG_INFO, "     Aperture Min:        f/%.2f\n", elns_info.apertureMin);
  129. +                    print_msg(MSG_INFO, "     Aperture Max:        f/%.2f\n", elns_info.apertureMax);
  130. +                    print_msg(MSG_INFO, "     Version:             %d\n", elns_info.version);
  131. +                    print_msg(MSG_INFO, "     Extender Info:       0x%02X\n", elns_info.extenderInfo);
  132. +                    print_msg(MSG_INFO, "     Capabilities:        0x%02X\n", elns_info.capabilities);
  133. +                    print_msg(MSG_INFO, "     Chipped:             0x%02X\n", elns_info.chipped);
  134. +                }
  135. +
  136. +                if(mlv_output && !no_metadata_mode && (!extract_block || !strncasecmp(extract_block, (char*)elns_info.blockType, 4)))
  137. +                {
  138. +                    /* correct header size if needed */
  139. +                    elns_info.blockSize = sizeof(mlv_elns_hdr_t);
  140. +                    if(fwrite(&elns_info, elns_info.blockSize, 1, out_file) != 1)
  141. +                    {
  142. +                        print_msg(MSG_ERROR, "Failed writing into .MLV file\n");
  143. +                        goto abort;
  144. +                    }
  145. +                }
  146. +            }
  147.              else if(!memcmp(buf.blockType, "INFO", 4))
  148.              {
  149.                  mlv_info_hdr_t block_hdr;
  150. diff --git a/modules/mlv_rec/mlv_rec.c b/modules/mlv_rec/mlv_rec.c
  151. --- a/modules/mlv_rec/mlv_rec.c
  152. +++ b/modules/mlv_rec/mlv_rec.c
  153. @@ -189,6 +189,7 @@
  154.  
  155.  static mlv_expo_hdr_t last_expo_hdr;
  156.  static mlv_lens_hdr_t last_lens_hdr;
  157. +static mlv_elns_hdr_t last_elns_hdr;
  158.  static mlv_wbal_hdr_t last_wbal_hdr;
  159.  static mlv_styl_hdr_t last_styl_hdr;
  160.  
  161. @@ -1442,14 +1443,17 @@
  162.              trace_write(raw_rec_trace_ctx, "[polling_cbr] queueing INFO blocks");
  163.              mlv_expo_hdr_t *expo_hdr = malloc(sizeof(mlv_expo_hdr_t));
  164.              mlv_lens_hdr_t *lens_hdr = malloc(sizeof(mlv_lens_hdr_t));
  165. +            mlv_elns_hdr_t *elns_hdr = malloc(sizeof(mlv_elns_hdr_t));
  166.              mlv_wbal_hdr_t *wbal_hdr = malloc(sizeof(mlv_wbal_hdr_t));
  167.  
  168.              mlv_fill_expo(expo_hdr, mlv_start_timestamp);
  169.              mlv_fill_lens(lens_hdr, mlv_start_timestamp);
  170. +            mlv_fill_elns(elns_hdr, mlv_start_timestamp);
  171.              mlv_fill_wbal(wbal_hdr, mlv_start_timestamp);
  172.  
  173.              msg_queue_post(mlv_block_queue, (uint32_t) expo_hdr);
  174.              msg_queue_post(mlv_block_queue, (uint32_t) lens_hdr);
  175. +            msg_queue_post(mlv_block_queue, (uint32_t) elns_hdr);
  176.              msg_queue_post(mlv_block_queue, (uint32_t) wbal_hdr);
  177.          }
  178.  
  179. @@ -2562,6 +2566,7 @@
  180.          mlv_rtci_hdr_t rtci_hdr;
  181.          mlv_expo_hdr_t expo_hdr;
  182.          mlv_lens_hdr_t lens_hdr;
  183. +        mlv_elns_hdr_t elns_hdr;
  184.          mlv_idnt_hdr_t idnt_hdr;
  185.          mlv_wbal_hdr_t wbal_hdr;
  186.          mlv_styl_hdr_t styl_hdr;
  187. @@ -2569,6 +2574,7 @@
  188.          mlv_fill_rtci(&rtci_hdr, mlv_start_timestamp);
  189.          mlv_fill_expo(&expo_hdr, mlv_start_timestamp);
  190.          mlv_fill_lens(&lens_hdr, mlv_start_timestamp);
  191. +        mlv_fill_elns(&elns_hdr, mlv_start_timestamp);
  192.          mlv_fill_idnt(&idnt_hdr, mlv_start_timestamp);
  193.          mlv_fill_wbal(&wbal_hdr, mlv_start_timestamp);
  194.          mlv_fill_styl(&styl_hdr, mlv_start_timestamp);
  195. @@ -2580,10 +2586,12 @@
  196.          idnt_hdr.timestamp = 4;
  197.          wbal_hdr.timestamp = 5;
  198.          styl_hdr.timestamp = 6;
  199. +        elns_hdr.timestamp = 7;
  200.  
  201.          mlv_write_hdr(f, (mlv_hdr_t *)&rtci_hdr);
  202.          mlv_write_hdr(f, (mlv_hdr_t *)&expo_hdr);
  203.          mlv_write_hdr(f, (mlv_hdr_t *)&lens_hdr);
  204. +        mlv_write_hdr(f, (mlv_hdr_t *)&elns_hdr);
  205.          mlv_write_hdr(f, (mlv_hdr_t *)&idnt_hdr);
  206.          mlv_write_hdr(f, (mlv_hdr_t *)&wbal_hdr);
  207.          mlv_write_hdr(f, (mlv_hdr_t *)&styl_hdr);
  208. @@ -3092,13 +3100,16 @@
  209.  
  210.          mlv_expo_hdr_t old_expo = last_expo_hdr;
  211.          mlv_lens_hdr_t old_lens = last_lens_hdr;
  212. +        mlv_elns_hdr_t old_elns = last_elns_hdr;
  213.  
  214.          mlv_fill_expo(&last_expo_hdr, mlv_start_timestamp);
  215.          mlv_fill_lens(&last_lens_hdr, mlv_start_timestamp);
  216. +        mlv_fill_elns(&last_elns_hdr, mlv_start_timestamp);
  217.  
  218.          /* update timestamp for comparing content changes */
  219.          old_expo.timestamp = last_expo_hdr.timestamp;
  220.          old_lens.timestamp = last_lens_hdr.timestamp;
  221. +        old_elns.timestamp = last_elns_hdr.timestamp;
  222.  
  223.          /* write new state if something changed */
  224.          if(memcmp(&last_expo_hdr, &old_expo, sizeof(mlv_expo_hdr_t)))
  225. @@ -3115,6 +3126,13 @@
  226.              memcpy(hdr, &last_lens_hdr, sizeof(mlv_lens_hdr_t));
  227.              msg_queue_post(mlv_block_queue, (uint32_t) hdr);
  228.          }
  229. +        /* write new state if something changed */
  230. +        if(memcmp(&last_elns_hdr, &old_elns, sizeof(mlv_elns_hdr_t)))
  231. +        {
  232. +            mlv_hdr_t *hdr = malloc(sizeof(mlv_elns_hdr_t));
  233. +            memcpy(hdr, &last_elns_hdr, sizeof(mlv_elns_hdr_t));
  234. +            msg_queue_post(mlv_block_queue, (uint32_t) hdr);
  235. +        }
  236.      }
  237.  
  238.      if(mlv_update_styl && (mlv_metadata & MLV_METADATA_SPORADIC))
  239. diff --git a/modules/silent/silent.c b/modules/silent/silent.c
  240. --- a/modules/silent/silent.c
  241. +++ b/modules/silent/silent.c
  242. @@ -25,6 +25,7 @@
  243.  extern WEAK_FUNC(ret_0) void mlv_fill_rtci(mlv_rtci_hdr_t *hdr, uint64_t start_timestamp);
  244.  extern WEAK_FUNC(ret_0) void mlv_fill_expo(mlv_expo_hdr_t *hdr, uint64_t start_timestamp);
  245.  extern WEAK_FUNC(ret_0) void mlv_fill_lens(mlv_lens_hdr_t *hdr, uint64_t start_timestamp);
  246. +extern WEAK_FUNC(ret_0) void mlv_fill_elns(mlv_elns_hdr_t *hdr, uint64_t start_timestamp);
  247.  extern WEAK_FUNC(ret_0) void mlv_fill_idnt(mlv_idnt_hdr_t *hdr, uint64_t start_timestamp);
  248.  extern WEAK_FUNC(ret_0) void mlv_fill_wbal(mlv_wbal_hdr_t *hdr, uint64_t start_timestamp);
  249.  extern WEAK_FUNC(ret_0) void mlv_fill_styl(mlv_styl_hdr_t *hdr, uint64_t start_timestamp);
  250. @@ -294,6 +295,7 @@
  251.      mlv_rtci_hdr_t rtci_hdr;
  252.      mlv_expo_hdr_t expo_hdr;
  253.      mlv_lens_hdr_t lens_hdr;
  254. +    mlv_elns_hdr_t elns_hdr;
  255.      mlv_idnt_hdr_t idnt_hdr;
  256.      mlv_wbal_hdr_t wbal_hdr;
  257.      mlv_styl_hdr_t styl_hdr;
  258. @@ -407,7 +409,8 @@
  259.      mlv_fill_rtci(&rtci_hdr, mlv_start_timestamp);
  260.      mlv_fill_expo(&expo_hdr, mlv_start_timestamp);
  261.      mlv_fill_lens(&lens_hdr, mlv_start_timestamp);
  262. -    
  263. +    mlv_fill_elns(&elns_hdr, mlv_start_timestamp);
  264. +
  265.      if(capture_time_ms > 0)
  266.      {
  267.          expo_hdr.shutterValue = 1000 * capture_time_ms;
  268. @@ -416,7 +419,8 @@
  269.      if (FIO_WriteFile(save_file, &rtci_hdr, rtci_hdr.blockSize) != (int)rtci_hdr.blockSize) goto write_error;
  270.      if (FIO_WriteFile(save_file, &expo_hdr, expo_hdr.blockSize) != (int)expo_hdr.blockSize) goto write_error;
  271.      if (FIO_WriteFile(save_file, &lens_hdr, lens_hdr.blockSize) != (int)lens_hdr.blockSize) goto write_error;
  272. -    
  273. +    if (FIO_WriteFile(save_file, &elns_hdr, elns_hdr.blockSize) != (int)elns_hdr.blockSize) goto write_error;
  274. +
  275.      memset(&vidf_hdr, 0, sizeof(mlv_vidf_hdr_t));
  276.      mlv_set_type((mlv_hdr_t *)&vidf_hdr, "VIDF");
  277.      mlv_set_timestamp((mlv_hdr_t *)&vidf_hdr, mlv_start_timestamp);
  278. diff --git a/scripts/lens.lua b/scripts/lens.lua
  279. --- a/scripts/lens.lua
  280. +++ b/scripts/lens.lua
  281. @@ -19,9 +19,19 @@
  282.  --  serial          -> Lens Serial Number (optional)
  283.  --  f_values        -> Available f-stop for selected lens (optional)
  284.  
  285. -    { name = "My Lens", focal_length = 50 },
  286. -    { name = "My Other Lens", focal_length = 25, manual_aperture = 2.8, f_values = {"2.8","4","5.6","8"} },
  287. -    { name = "My Zoom Lens", focal_length = 105, manual_aperture = 4, focal_min = 70, focal_max = 200, serial = 123456789 },
  288. +{ name = "My Lens", focal_length = 50, serial = 123456789 },
  289. +{ name = "My Other Lens", focal_length = 25, manual_aperture = 2.8, f_values = {"2.8","4","5.6","8"} },
  290. +{ name = "My Zoom Lens", focal_length = 25, manual_aperture = 4, focal_length = 105, focal_min = 70, focal_max = 200 },
  291. +{ name = "Yashica ML 50mm f1.9", focal_length = 50, serial = 123, manual_aperture = 5 },
  292. +{ name = "Portrait 85mm", focal_length = 85, manual_aperture = 2 },
  293. +{ name = "Portrait 105mm", focal_length = 105, focal_min = 105, focal_max = 105, manual_aperture = 8 },
  294. +{ name = "Pentax SMC 80-200mm f4,5", focal_length = 200, manual_aperture = 4.5, serial = 123456789 },
  295. +{ name = "Pentax SMC 80-200mm f4,5 with focal length min-max", focal_length = 200, focal_min = 80, focal_max = 200, manual_aperture = 4.5, serial = 123456789 },
  296. +{ name = "Portrait 125mm 2.8", focal_length = 125, manual_aperture = 2.8 },
  297. +{ name = "Portrait 200mm 5.6", focal_length = 200, focal_min = 200, focal_max = 200, manual_aperture = 5.6 },
  298. +{ name = "Portrait 125mm 1.4", focal_length = 125, manual_aperture = 1.4 },
  299. +{ name = "Carl Zeiss Vario-Sonnar T* 100-300 mm f/ 4.5-5.6 C/Y", focal_length = 150, focal_min = 100, focal_max = 300, manual_aperture = 4.5, f_values = {"4.5","8","11","16","22","32"}, serial = 123456789 },
  300. +{ name = "Carl Zeiss Jena 28-70mm f/3.5-4.5 MC Macro Jenazoom Super", focal_length = 35, focal_min = 24, focal_max = 70, manual_aperture = 3.5, f_values = {"3.5","4.5","8","11","16","22","32"}, serial = 123456789 },
  301.  
  302.  --  Zeiss ZF.2 manual lenses Nikon mount - these work with the lens profiles that ship with Adobe Camera Raw
  303.  
  304. diff --git a/src/focus.c b/src/focus.c
  305. --- a/src/focus.c
  306. +++ b/src/focus.c
  307. @@ -265,14 +265,31 @@
  308.          return;
  309.      }
  310.  
  311. -    bmp_printf( font, x, y,
  312. -        "Lens: %s, %dmm f/%d.%d",
  313. -        lens_info.name,
  314. -        lens_info.focal_len,
  315. -        lens_info.aperture / 10,
  316. -        lens_info.aperture % 10
  317. -    );
  318. -    
  319. +    // TODO:
  320. +    if(strlen(lens_info.name) > 42)
  321. +    {
  322. +      char lensName[42];
  323. +      snprintf(lensName, 42, "%s", lens_info.name);
  324. +
  325. +      bmp_printf( font, x, y,
  326. +          "Lens: %s..., %dmm f/%d.%d",
  327. +          lensName,
  328. +          lens_info.focal_len,
  329. +          lens_info.aperture / 10,
  330. +          lens_info.aperture % 10
  331. +      );
  332. +    }
  333. +    else
  334. +    {
  335. +      bmp_printf( font, x, y,
  336. +          "Lens: %s, %dmm f/%d.%d",
  337. +          lens_info.name,
  338. +          lens_info.focal_len,
  339. +          lens_info.aperture / 10,
  340. +          lens_info.aperture % 10
  341. +      );
  342. +    }
  343. +
  344.      if (!lv)
  345.      {
  346.          y += height;
  347. diff --git a/src/lens.h b/src/lens.h
  348. --- a/src/lens.h
  349. +++ b/src/lens.h
  350. @@ -37,7 +37,7 @@
  351.  struct lens_info
  352.  {
  353.          void *                  token;
  354. -        char                    name[ 32 ];
  355. +        char                    name[ 64 ];
  356.          unsigned                focal_len; // in mm
  357.          unsigned                focus_dist; // in cm
  358.          unsigned                IS; // PROP_LV_LENS_STABILIZE
RAW Paste Data