Skip to content

Commit

Permalink
Initial work on spectrometer integration. Fixed bug causing textures …
Browse files Browse the repository at this point in the history
…to have weird color space conversions when moving from sRGB to linear. Fixes #656.
  • Loading branch information
azonenberg committed Dec 9, 2023
1 parent ee54e41 commit 9131c83
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/ngscopeclient/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ MainWindow::MainWindow(shared_ptr<QueueHandle> queue)
LoadToolbarIcons();
LoadGradients();
m_texmgr.LoadTexture("warning", FindDataFile("icons/48x48/dialog-warning-2.png"));
m_texmgr.LoadTexture("visible-spectrum-380nm-750nm",
FindDataFile("icons/gradients/visible-spectrum-380nm-750nm.png"));

//Don't move windows when dragging in the body, only the title bar
ImGui::GetIO().ConfigWindowsMoveFromTitleBarOnly = true;
Expand Down
10 changes: 6 additions & 4 deletions src/ngscopeclient/TextureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Texture::Texture(
{},
*m_image,
vk::ImageViewType::e2D,
vk::Format::eR8G8B8A8Srgb,
vk::Format::eR8G8B8A8Unorm,
{},
vk::ImageSubresourceRange(vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1)
);
Expand Down Expand Up @@ -392,8 +392,10 @@ void TextureManager::LoadTexture(
fclose(fp);
return;
}
int bytesPerComponent = 1;
int bytesPerPixel = 4*bytesPerComponent;
LogTrace("Image is %d x %d pixels, RGBA8888\n", width, height);
VkDeviceSize size = width * height * 4;
VkDeviceSize size = width * height * bytesPerPixel;

//Allocate temporary staging buffer
vk::BufferCreateInfo bufinfo({}, size, vk::BufferUsageFlagBits::eTransferSrc);
Expand Down Expand Up @@ -426,7 +428,7 @@ void TextureManager::LoadTexture(
stagingBuf.bindMemory(*physMem, 0);

//Fill the mapped buffer with image data from the PNG
size_t rowSize = width * 4;
size_t rowSize = width * bytesPerPixel;
for(int y=0; y<height; y++)
memcpy(mappedPtr + (y*rowSize), rowPtrs[y], rowSize);
physMem.unmapMemory();
Expand All @@ -435,7 +437,7 @@ void TextureManager::LoadTexture(
vk::ImageCreateInfo imageInfo(
{},
vk::ImageType::e2D,
vk::Format::eR8G8B8A8Srgb,
vk::Format::eR8G8B8A8Unorm,
vk::Extent3D(width, height, 1),
1,
1,
Expand Down
4 changes: 2 additions & 2 deletions src/ngscopeclient/TimebasePropertiesDialog.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***********************************************************************************************************************
* *
* glscopeclient *
* ngscopeclient *
* *
* Copyright (c) 2012-2022 Andrew D. Zonenberg *
* Copyright (c) 2012-2023 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
Expand Down
4 changes: 1 addition & 3 deletions src/ngscopeclient/VulkanWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ bool VulkanWindow::UpdateFramebuffer()
const VkFormat requestSurfaceImageFormat[] =
{
VK_FORMAT_B8G8R8A8_UNORM,
VK_FORMAT_R8G8B8A8_UNORM,
VK_FORMAT_B8G8R8_UNORM,
VK_FORMAT_R8G8B8_UNORM
VK_FORMAT_R8G8B8A8_UNORM
};
const VkColorSpaceKHR requestSurfaceColorSpace = VK_COLORSPACE_SRGB_NONLINEAR_KHR;
auto format = ImGui_ImplVulkanH_SelectSurfaceFormat(
Expand Down
11 changes: 11 additions & 0 deletions src/ngscopeclient/WaveformArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,17 @@ void WaveformArea::RenderBackgroundGradient(ImVec2 start, ImVec2 size)
color_top,
color_bottom,
color_bottom);

//TODO: add preference or per-area setting for this
//For now, always draw if X axis units are distance/wavelength
if(m_group->GetXAxisUnit() == Unit::UNIT_PM)
{
//Visible spectrum texture covers 380 - 750 nm
draw_list->AddImage(
m_parent->GetTextureManager()->GetTexture("visible-spectrum-380nm-750nm"),
ImVec2(m_group->XAxisUnitsToXPosition(380000), start.y),
ImVec2(m_group->XAxisUnitsToXPosition(750000), start.y + size.y));
}
}

/**
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9131c83

Please sign in to comment.