Skip to content

Commit

Permalink
Add IsUsingRgbColorOrder() / IsUsingBgrColorOrder()
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Oct 6, 2024
1 parent 5d35e1f commit 61faf20
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 35 deletions.
19 changes: 12 additions & 7 deletions src/immvision/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

namespace ImmVision
{
// Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values
enum class ColorMapStatsTypeId
{
FromFullImage,
FromVisibleROI
};

// Set the color order for displayed images.
// You **must** call once at the start of your program:
// ImmVision::UseRgbColorOrder() or ImmVision::UseBgrColorOrder() (C++)
Expand All @@ -30,6 +23,18 @@ namespace ImmVision
void UseRgbColorOrder();
void UseBgrColorOrder();

// Returns true if we are using RGB color order
bool IsUsingRgbColorOrder();
// Returns true if we are using BGR color order
bool IsUsingBgrColorOrder();

// Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values
enum class ColorMapStatsTypeId
{
FromFullImage,
FromVisibleROI
};

// Scale the Colormap according to the Image stats
struct ColormapScaleFromStatsData // IMMVISION_API_STRUCT
{
Expand Down
4 changes: 1 addition & 3 deletions src/immvision/internal/drawing/image_drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace ImmVision
{
bool Priv_IsColorOrderBgr();

namespace ImageDrawing
{
static float _ImmDrawingFontScaleRatio()
Expand Down Expand Up @@ -220,7 +218,7 @@ namespace ImmVision
{
fnSelectChannel();
fnAlphaCheckerboard();
bool is_color_order_bgr = Priv_IsColorOrderBgr();
bool is_color_order_bgr = IsUsingBgrColorOrder();
finalImage = CvDrawingUtils::converted_to_rgba_image(finalImage, is_color_order_bgr);
}
in_out_rgba_image_cache = finalImage;
Expand Down
9 changes: 9 additions & 0 deletions src/immvision/internal/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ This is a required setup step. (Breaking change - October 2024)
}
return sUseBgrOrder.value();
}
bool IsUsingRgbColorOrder()
{
return !Priv_IsColorOrderBgr();
}
bool IsUsingBgrColorOrder()
{
return Priv_IsColorOrderBgr();
}


void ClearTextureCache()
{
Expand Down
6 changes: 2 additions & 4 deletions src/immvision/internal/imgui/image_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

namespace ImmVision
{
bool Priv_IsColorOrderBgr();

namespace ImageWidgets
{
void GlTexture_Draw_DisableDragWindow(const GlTexture& texture, const ImVec2 &size, bool disableDragWindow)
Expand Down Expand Up @@ -59,13 +57,13 @@ namespace ImmVision
bool isInImage = cv::Rect(cv::Point(0, 0), image.size()).contains((pt));
auto UCharToFloat = [](int v) { return (float)((float) v / 255.f); };
auto Vec3bToImVec4 = [&UCharToFloat, &params](cv::Vec3b v) {
bool isColorOrderBgr = Priv_IsColorOrderBgr();
bool isColorOrderBgr = IsUsingBgrColorOrder();
return isColorOrderBgr ?
ImVec4(UCharToFloat(v[2]), UCharToFloat(v[1]), UCharToFloat(v[0]), UCharToFloat(255))
: ImVec4(UCharToFloat(v[0]), UCharToFloat(v[1]), UCharToFloat(v[2]), UCharToFloat(255));
};
auto Vec4bToImVec4 = [&UCharToFloat, &params](cv::Vec4b v) {
bool isColorOrderBgr = Priv_IsColorOrderBgr();
bool isColorOrderBgr = IsUsingBgrColorOrder();
return isColorOrderBgr ?
ImVec4(UCharToFloat(v[2]), UCharToFloat(v[1]), UCharToFloat(v[0]), UCharToFloat(v[3]))
: ImVec4(UCharToFloat(v[0]), UCharToFloat(v[1]), UCharToFloat(v[2]), UCharToFloat(v[3]));
Expand Down
38 changes: 24 additions & 14 deletions src_all_in_one/immvision/immvision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@

namespace ImmVision
{
// Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values
enum class ColorMapStatsTypeId
{
FromFullImage,
FromVisibleROI
};

// Set the color order for displayed images.
// You **must** call once at the start of your program:
// ImmVision::UseRgbColorOrder() or ImmVision::UseBgrColorOrder() (C++)
Expand All @@ -43,6 +36,18 @@ namespace ImmVision
void UseRgbColorOrder();
void UseBgrColorOrder();

// Returns true if we are using RGB color order
bool IsUsingRgbColorOrder();
// Returns true if we are using BGR color order
bool IsUsingBgrColorOrder();

// Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values
enum class ColorMapStatsTypeId
{
FromFullImage,
FromVisibleROI
};

// Scale the Colormap according to the Image stats
struct ColormapScaleFromStatsData // IMMVISION_API_STRUCT
{
Expand Down Expand Up @@ -6396,8 +6401,6 @@ namespace ImmVision

namespace ImmVision
{
bool Priv_IsColorOrderBgr();

namespace ImageDrawing
{
static float _ImmDrawingFontScaleRatio()
Expand Down Expand Up @@ -6605,7 +6608,7 @@ namespace ImmVision
{
fnSelectChannel();
fnAlphaCheckerboard();
bool is_color_order_bgr = Priv_IsColorOrderBgr();
bool is_color_order_bgr = IsUsingBgrColorOrder();
finalImage = CvDrawingUtils::converted_to_rgba_image(finalImage, is_color_order_bgr);
}
in_out_rgba_image_cache = finalImage;
Expand Down Expand Up @@ -9518,6 +9521,15 @@ This is a required setup step. (Breaking change - October 2024)
}
return sUseBgrOrder.value();
}
bool IsUsingRgbColorOrder()
{
return !Priv_IsColorOrderBgr();
}
bool IsUsingBgrColorOrder()
{
return Priv_IsColorOrderBgr();
}


void ClearTextureCache()
{
Expand Down Expand Up @@ -10759,8 +10771,6 @@ namespace ImmVision

namespace ImmVision
{
bool Priv_IsColorOrderBgr();

namespace ImageWidgets
{
void GlTexture_Draw_DisableDragWindow(const GlTexture& texture, const ImVec2 &size, bool disableDragWindow)
Expand Down Expand Up @@ -10813,13 +10823,13 @@ namespace ImmVision
bool isInImage = cv::Rect(cv::Point(0, 0), image.size()).contains((pt));
auto UCharToFloat = [](int v) { return (float)((float) v / 255.f); };
auto Vec3bToImVec4 = [&UCharToFloat, &params](cv::Vec3b v) {
bool isColorOrderBgr = Priv_IsColorOrderBgr();
bool isColorOrderBgr = IsUsingBgrColorOrder();
return isColorOrderBgr ?
ImVec4(UCharToFloat(v[2]), UCharToFloat(v[1]), UCharToFloat(v[0]), UCharToFloat(255))
: ImVec4(UCharToFloat(v[0]), UCharToFloat(v[1]), UCharToFloat(v[2]), UCharToFloat(255));
};
auto Vec4bToImVec4 = [&UCharToFloat, &params](cv::Vec4b v) {
bool isColorOrderBgr = Priv_IsColorOrderBgr();
bool isColorOrderBgr = IsUsingBgrColorOrder();
return isColorOrderBgr ?
ImVec4(UCharToFloat(v[2]), UCharToFloat(v[1]), UCharToFloat(v[0]), UCharToFloat(v[3]))
: ImVec4(UCharToFloat(v[0]), UCharToFloat(v[1]), UCharToFloat(v[2]), UCharToFloat(v[3]));
Expand Down
19 changes: 12 additions & 7 deletions src_all_in_one/immvision/immvision.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@

namespace ImmVision
{
// Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values
enum class ColorMapStatsTypeId
{
FromFullImage,
FromVisibleROI
};

// Set the color order for displayed images.
// You **must** call once at the start of your program:
// ImmVision::UseRgbColorOrder() or ImmVision::UseBgrColorOrder() (C++)
Expand All @@ -38,6 +31,18 @@ namespace ImmVision
void UseRgbColorOrder();
void UseBgrColorOrder();

// Returns true if we are using RGB color order
bool IsUsingRgbColorOrder();
// Returns true if we are using BGR color order
bool IsUsingBgrColorOrder();

// Are we using the stats on the full image, on the Visible ROI, or are we using Min/Max values
enum class ColorMapStatsTypeId
{
FromFullImage,
FromVisibleROI
};

// Scale the Colormap according to the Image stats
struct ColormapScaleFromStatsData // IMMVISION_API_STRUCT
{
Expand Down

0 comments on commit 61faf20

Please sign in to comment.