@@ -450,23 +450,23 @@ namespace librealsense
450450 return map;
451451 }
452452
453- std::string controlNameFromId ( ControlId id )
453+ std::string control_name_from_id ( hdr_preset::control_id id )
454454 {
455- auto it = control_id_string_map.find ( id );
456- if ( it != control_id_string_map.end () )
455+ auto it = hdr_preset:: control_id_string_map.find ( id );
456+ if ( it != hdr_preset:: control_id_string_map.end () )
457457 {
458458 return it->second ;
459459 }
460- throw std::invalid_argument (" Error: Incorrect buffer! controlName NOT found! (" + std::to_string (id) + " )" );
460+ throw std::invalid_argument (" Error: Incorrect buffer! control ID NOT found! (" + std::to_string (id) + " )" );
461461 }
462462
463- ControlId getControlIdFromString ( const std::string & name )
463+ hdr_preset::control_id get_control_id_from_string ( const std::string & name )
464464 {
465465 // Build reverse map on first use
466- static const std::unordered_map< std::string, ControlId > string_control_id_map = []()
466+ static const std::unordered_map< std::string, hdr_preset::control_id > string_control_id_map = []()
467467 {
468- std::unordered_map< std::string, ControlId > result;
469- for ( const auto & pair : control_id_string_map)
468+ std::unordered_map< std::string, hdr_preset::control_id > result;
469+ for ( const auto & pair : hdr_preset:: control_id_string_map)
470470 {
471471 result[pair.second ] = pair.first ;
472472 }
@@ -483,30 +483,30 @@ namespace librealsense
483483
484484 // Helper function to append a struct to the buffer
485485 template <typename T>
486- void appendStruct (std::vector<uint8_t >& buffer, const T& st) {
486+ void append_struct (std::vector<uint8_t >& buffer, const T& st) {
487487 const uint8_t * ptr = reinterpret_cast <const uint8_t *>(&st);
488488 buffer.insert (buffer.end (), ptr, ptr + sizeof (T));
489489 }
490490
491- // Given populated SubPresetHeader and items, build the byte buffer
492- std::vector<uint8_t > serializeSubPreset (
493- const SubPresetHeader& sph ,
494- const std::vector<std::pair<ItemHeader , std::vector<Control >>>& items
491+ // Given header and items, build the byte buffer
492+ std::vector<uint8_t > serialize_hdr_preset (
493+ const hdr_preset::preset_header& header ,
494+ const std::vector<std::pair<hdr_preset::item_header , std::vector<hdr_preset::sub_control >>>& items
495495 ) {
496496 std::vector<uint8_t > buffer;
497- appendStruct (buffer, sph );
497+ append_struct (buffer, header );
498498 for (const auto & entry : items) {
499- appendStruct (buffer, entry.first );
499+ append_struct (buffer, entry.first );
500500 for (const auto & ctrl : entry.second ) {
501- appendStruct (buffer, ctrl);
501+ append_struct (buffer, ctrl);
502502 }
503503 }
504504 return buffer;
505505 }
506506
507507 // Helper to read a struct of type T from buffer at offset
508508 template <typename T>
509- T readStruct (const std::vector<uint8_t >& buffer, size_t & offset) {
509+ T read_struct (const std::vector<uint8_t >& buffer, size_t & offset) {
510510 if (offset + sizeof (T) > buffer.size ()) {
511511 throw std::out_of_range (" Buffer too small for struct" );
512512 }
@@ -516,45 +516,45 @@ namespace librealsense
516516 return obj;
517517 }
518518
519- // Deserialize full SubPreset from byte buffer
520- SubPreset parseSubPreset (const std::vector<uint8_t >& buffer) {
519+ // Deserialize full hdr_preset from byte buffer
520+ hdr_preset::hdr_preset parse_hdr_preset (const std::vector<uint8_t >& buffer) {
521521 size_t offset = 4 ; // The command is at the beginning of the buffer
522- SubPreset preset {};
522+ hdr_preset::hdr_preset _hdr_preset {};
523523 if (buffer.size () <= offset) {
524- return preset ;
524+ return _hdr_preset ;
525525 }
526526
527527 // Read header
528- preset .header = readStruct<SubPresetHeader >(buffer, offset);
529- if (preset .header .headerSize != SubPresetHeader ::size ()) {
530- throw std::runtime_error (" Unexpected SubPresetHeader size" );
528+ _hdr_preset .header = read_struct<hdr_preset::preset_header >(buffer, offset);
529+ if (_hdr_preset .header .header_size != hdr_preset::preset_header ::size ()) {
530+ throw std::runtime_error (" Unexpected header size" );
531531 }
532532
533533 // Read items
534- for (uint8_t i = 0 ; i < preset .header .numOfItems ; ++i) {
534+ for (uint8_t i = 0 ; i < _hdr_preset .header .num_of_items ; ++i) {
535535 // Read item header
536- ItemHeader ih = readStruct<ItemHeader >(buffer, offset);
537- if (ih.headerSize != ItemHeader ::size ()) {
538- throw std::runtime_error (" Unexpected ItemHeader size" );
536+ hdr_preset::item_header ih = read_struct<hdr_preset::item_header >(buffer, offset);
537+ if (ih.header_size != hdr_preset::item_header ::size ()) {
538+ throw std::runtime_error (" Unexpected item_header size" );
539539 }
540540
541541 // Read controls for the item
542- std::vector<Control > controls;
543- controls.reserve (ih.numOfControls );
544- for (uint8_t c = 0 ; c < ih.numOfControls ; ++c) {
545- Control ctrl = readStruct<Control >(buffer, offset);
542+ std::vector<hdr_preset::sub_control > controls;
543+ controls.reserve (ih.num_of_controls );
544+ for (uint8_t c = 0 ; c < ih.num_of_controls ; ++c) {
545+ hdr_preset::sub_control ctrl = read_struct<hdr_preset::sub_control >(buffer, offset);
546546 controls.push_back (ctrl);
547547 }
548548
549- preset .items .emplace_back (ih, std::move (controls));
549+ _hdr_preset .items .emplace_back (ih, std::move (controls));
550550 }
551551
552552 // validate that we read exactly buffer size
553553 if (offset != buffer.size ()) {
554554 throw std::runtime_error (" Buffer contains extra data" );
555555 }
556556
557- return preset ;
557+ return _hdr_preset ;
558558 }
559559
560560
@@ -576,31 +576,31 @@ namespace librealsense
576576 preset_writer.write_param (f.first .c_str (), str);
577577 }
578578
579- if (!in_preset.sub_preset .items .empty ())
579+ if (!in_preset.auto_hdr .items .empty ())
580580 {
581- json subpreset ;
582- auto & sp = in_preset.sub_preset ;
583- subpreset [" id" ] = std::to_string (sp .header .id );
584- subpreset [" iterations" ] = std::to_string (sp .header .iterations );
581+ json hdr_preset ;
582+ auto & auto_hdr = in_preset.auto_hdr ;
583+ hdr_preset [" id" ] = std::to_string (auto_hdr .header .id );
584+ hdr_preset [" iterations" ] = std::to_string (auto_hdr .header .iterations );
585585
586586 // build 'items' array of objects
587- for (size_t i = 0 ; i < sp .items .size (); ++i) {
588- const auto & ih = sp .items [i].first ;
587+ for (size_t i = 0 ; i < auto_hdr .items .size (); ++i) {
588+ const auto & ih = auto_hdr .items [i].first ;
589589 json item;
590590 item[" iterations" ] = std::to_string (ih.iterations );
591591
592592 // build 'controls' array for the item
593- for (int c = 0 ; c < ih.numOfControls ; ++c) {
594- const Control & ctrl = sp .items [i].second [c];
595- const std::string controlName = controlNameFromId ( ControlId ( ctrl.controlId ) );
596- const std::string controlValue = std::to_string ( ctrl.controlValue );
593+ for (int c = 0 ; c < ih.num_of_controls ; ++c) {
594+ const hdr_preset::sub_control & ctrl = auto_hdr .items [i].second [c];
595+ const std::string control_name = control_name_from_id ( hdr_preset::control_id ( ctrl.control_id ) );
596+ const std::string control_value = std::to_string ( ctrl.control_value );
597597
598- item[" controls" ].push_back ({ { controlName, controlValue } });
598+ item[" controls" ].push_back ({ { control_name, control_value } });
599599 }
600600
601- subpreset [" items" ].push_back (std::move (item));
601+ hdr_preset [" items" ].push_back (std::move (item));
602602 }
603- preset_writer.write_root_param (" SubPreset " , subpreset);
603+ preset_writer.write_root_param (" hdr-preset " , hdr_preset); // in the JSON, the HDR control is stored under "hdr-preset"
604604 }
605605
606606 auto str = preset_writer.to_string ();
@@ -629,7 +629,7 @@ namespace librealsense
629629 auto key = it.key ();
630630 auto value = it.value ();
631631 auto kvp = fields.find (key);
632- if (key == " SubPreset " ) // skip the SubPreset block
632+ if (key == " hdr-preset " ) // skip the hdr-preset block
633633 continue ;
634634 if (kvp != fields.end ())
635635 {
@@ -693,29 +693,29 @@ namespace librealsense
693693 update_preset_camera_control (in_preset.color_auto_white_balance , p.color_auto_white_balance );
694694 update_preset_camera_control (in_preset.color_power_line_frequency , p.color_power_line_frequency );
695695
696- auto subpreset = preset_reader.get_subpreset ();
697- if (!subpreset .is_null ())
696+ auto hdr_preset_from_json = preset_reader.get_hdr_preset (); // hdr-preset block
697+ if (!hdr_preset_from_json .is_null ())
698698 {
699- SubPreset sp ;
699+ hdr_preset::hdr_preset auto_hdr ;
700700
701- sp .header .headerSize = SubPresetHeader ::size ();
702- auto id = std::stoi (subpreset .at (" id" ).get <std::string>());
701+ auto_hdr .header .header_size = hdr_preset::preset_header ::size ();
702+ auto id = std::stoi (hdr_preset_from_json .at (" id" ).get <std::string>());
703703 if ( id < 0 || id > 0xF )
704- throw std::invalid_argument (" Error: Incorrect subpreset id: \" " + std::to_string (id) + " \" " + " , valid range <0:15>" );
705- sp .header .id = static_cast <uint8_t >(id);
704+ throw std::invalid_argument (" Error: Incorrect hdr_preset id: \" " + std::to_string (id) + " \" " + " , valid range <0:15>" );
705+ auto_hdr .header .id = static_cast <uint8_t >(id);
706706
707- auto iterations = std::stoi ( subpreset .at ( " iterations" ).get < std::string >() );
707+ auto iterations = std::stoi (hdr_preset_from_json .at ( " iterations" ).get < std::string >() );
708708 if ( iterations < 0 || iterations > 0xFFFF )
709709 throw std::invalid_argument (" Error: Incorrect number of iterations: \" " + std::to_string (iterations) + " \" " + " , valid range <1:ffff>, 0 - for infinite" );
710- sp .header .iterations = static_cast <uint16_t >(iterations);
710+ auto_hdr .header .iterations = static_cast <uint16_t >(iterations);
711711
712- const auto & items = subpreset .at (" items" );
712+ const auto & items = hdr_preset_from_json .at (" items" );
713713
714714 for (const auto & item : items) {
715- ItemHeader item_header{};
716- std::vector<Control > item_controls;
715+ hdr_preset::item_header item_header{};
716+ std::vector<hdr_preset::sub_control > item_controls;
717717
718- item_header.headerSize = ItemHeader ::size ();
718+ item_header.header_size = hdr_preset::item_header ::size ();
719719 item_header.iterations = static_cast <uint16_t >(std::stoi (item.at (" iterations" ).get <std::string>()));
720720
721721 const auto & controls = item.at (" controls" );
@@ -724,23 +724,23 @@ namespace librealsense
724724 const std::string key = control.begin ().key ();
725725 const std::string value = control.begin ().value ().get <std::string>();
726726
727- Control ctrl{};
728- ctrl.controlId = static_cast <uint8_t >(getControlIdFromString (key)); // will throw if not found
729- ctrl.controlValue = static_cast <uint32_t >(std::stoul (value));
727+ hdr_preset::sub_control ctrl{};
728+ ctrl.control_id = static_cast <uint8_t >(get_control_id_from_string (key)); // will throw if not found
729+ ctrl.control_value = static_cast <uint32_t >(std::stoul (value));
730730 item_controls.push_back (ctrl);
731731 }
732732
733- item_header.numOfControls = static_cast <uint8_t >(item_controls.size ());
733+ item_header.num_of_controls = static_cast <uint8_t >(item_controls.size ());
734734
735- sp .items .push_back ( { item_header, item_controls } );
735+ auto_hdr .items .push_back ( { item_header, item_controls } );
736736 }
737737
738- auto num_of_items = sp .items .size ();
739- if ( num_of_items == 0 || num_of_items > 0xFF ) // TODO: limit is 6 frames?
740- throw std::invalid_argument ( " Error: Incorrect number of items: \" " + std::to_string ( num_of_items ) + " \" " + " , valid range <1:255 >" );
741- sp .header .numOfItems = static_cast < uint8_t >( num_of_items );
738+ auto num_of_items = auto_hdr .items .size ();
739+ if ( num_of_items < 2 || num_of_items > 6 )
740+ throw std::invalid_argument ( " Error: Incorrect number of items: \" " + std::to_string ( num_of_items ) + " \" " + " , valid range <2:6 >" );
741+ auto_hdr .header .num_of_items = static_cast < uint8_t >( num_of_items );
742742
743- in_preset.sub_preset = sp ;
743+ in_preset.auto_hdr = auto_hdr ;
744744 }
745745
746746 }
0 commit comments