Skip to content

Commit c95b094

Browse files
committed
renaming
1 parent b757c39 commit c95b094

File tree

7 files changed

+149
-145
lines changed

7 files changed

+149
-145
lines changed

common/option-model.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "device-model.h"
1010
#include "subdevice-model.h"
1111
#include <os.h>
12-
#include <rsutils/easylogging/easyloggingpp.h>
1312

1413
namespace rs2
1514
{
@@ -133,10 +132,11 @@ bool option_model::draw( std::string & error_message,
133132
"algorithm\nClick the button, then draw a rect on the frame" );
134133
}
135134

136-
if (opt == RS2_OPTION_HDR_ENABLED)
135+
#if true
136+
if (opt == RS2_OPTION_HDR_ENABLED) // TODO: enable this when the auto-hdr feature is fully implemented, currently works via the load/save preset buttons at the top of the viewer - make sure to disable HDR before loading!
137137
{
138138
auto disable_hdr_load = value_as_float() > 0; // if HDR is enabled, we can't load a new config
139-
// draw a button to load the HDR configuration from JSON
139+
140140
ImGui::SameLine(0, 10);
141141
std::string button_label = "Load HDR";
142142
std::string caption = rsutils::string::from() << "Load HDR config from JSON##" << button_label;
@@ -145,7 +145,7 @@ bool option_model::draw( std::string & error_message,
145145
{
146146
dev->_options_invalidated = true;
147147
auto ret = file_dialog_open(open_file, "JavaScript Object Notation (JSON | PRESET)\0*.json;*.preset\0", NULL, NULL);
148-
//ret = "C:\\Users\\aviaavra\\Downloads\\SubPresetTool-master\\SubPresetTool-master\\BadJson.json";
148+
149149
if (ret)
150150
{
151151
std::ifstream file(ret);
@@ -159,13 +159,14 @@ bool option_model::draw( std::string & error_message,
159159
error_message = safe_call([&]() {
160160
dev->dev.as<serializable_device>().load_json(str);
161161

162-
LOG_INFO("HDR config loaded from JSON file: " << ret);
162+
model.add_log( rsutils::string::from() << "HDR config loaded from JSON file: " << ret, RS2_LOG_SEVERITY_INFO);
163163
dev->_options_invalidated = true;
164164
});
165165
}
166166
}
167167
}, disable_hdr_load );
168168
}
169+
#endif
169170
}
170171

171172
return res;

src/core/advanced_mode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ namespace librealsense
178178
void get_color_white_balance(white_balance_control* ptr) const;
179179
void get_color_auto_white_balance(auto_white_balance_control* ptr) const;
180180
void get_color_power_line_frequency(power_line_frequency_control* ptr) const;
181-
void get_subpreset(SubPreset* ptr) const;
181+
void get_hdr_preset(hdr_preset::hdr_preset* ptr) const;
182182

183183
void set_laser_power(const laser_power_control& val);
184184
void set_laser_state(const laser_state_control& val);
@@ -216,8 +216,8 @@ namespace librealsense
216216
void set_all_depth( const preset & p );
217217
void set_all_rgb( const preset & p );
218218
bool should_set_rgb_preset() const;
219-
bool should_set_subpreset(const preset& p);
220-
void set_subpreset(const preset& p);
219+
bool should_set_hdr_preset(const preset& p);
220+
void set_hdr_preset(const preset& p);
221221

222222
std::vector<uint8_t> send_receive(const std::vector<uint8_t>& input) const;
223223

src/ds/advanced_mode/advanced_mode.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ namespace librealsense
458458
}
459459
}
460460

461-
void ds_advanced_mode_base::get_subpreset(SubPreset* ptr) const
461+
void ds_advanced_mode_base::get_hdr_preset(hdr_preset::hdr_preset* ptr) const
462462
{
463463
auto buffer = send_receive(encode_command( ds::GETSUBPRESET ));
464-
*ptr = parseSubPreset( buffer );
464+
*ptr = parse_hdr_preset( buffer );
465465
}
466466

467467
void ds_advanced_mode_base::set_depth_control_group(const STDepthControlGroup& val)
@@ -784,7 +784,7 @@ namespace librealsense
784784
get_color_auto_white_balance(&p.color_auto_white_balance);
785785
get_color_power_line_frequency(&p.color_power_line_frequency);
786786

787-
get_subpreset(&p.sub_preset);
787+
get_hdr_preset(&p.auto_hdr);
788788

789789
return p;
790790
}
@@ -794,8 +794,8 @@ namespace librealsense
794794
set_all_depth( p );
795795
if( should_set_rgb_preset() )
796796
set_all_rgb( p );
797-
if( should_set_subpreset(p) )
798-
set_subpreset( p );
797+
if( should_set_hdr_preset(p) )
798+
set_hdr_preset( p );
799799
}
800800

801801
void ds_advanced_mode_base::set_all_depth(const preset& p)
@@ -871,16 +871,15 @@ namespace librealsense
871871
return product_line != "D500";
872872
}
873873

874-
bool ds_advanced_mode_base::should_set_subpreset(const preset& p)
874+
bool ds_advanced_mode_base::should_set_hdr_preset(const preset& p)
875875
{
876-
return p.sub_preset.header.numOfItems > 0;
876+
return p.auto_hdr.header.num_of_items > 0;
877877
}
878878

879-
void ds_advanced_mode_base::set_subpreset(const preset& p)
879+
void ds_advanced_mode_base::set_hdr_preset(const preset& p)
880880
{
881-
// serialize stuff
882-
auto buffer = serializeSubPreset(p.sub_preset.header, p.sub_preset.items);
883-
// send to camera
881+
// serialize the hdr_preset and send it
882+
auto buffer = serialize_hdr_preset(p.auto_hdr.header, p.auto_hdr.items);
884883
command cmd(ds::SETSUBPRESET, static_cast<int>(buffer.size()));
885884
cmd.data = buffer;
886885
auto res = _hw_monitor->send(cmd);

src/ds/advanced_mode/json_loader.hpp

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)