MCPcopy Create free account
hub / github.com/bluescan/tacentview / DoQuantizeModal

Method DoQuantizeModal

Src/Quantize.cpp:122–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120
121
122void Viewer::DoQuantizeModal(bool quantizeImagePressed)
123{
124 if (quantizeImagePressed)
125 ImGui::OpenPopup("Quantize");
126
127 float modalWidth = Gutil::GetUIParamScaled(308.0f, 2.5f);
128 bool isOpenQuantizeImage = true;
129 ImGui::SetNextWindowSize(tVector2(modalWidth, 0.0f));
130 if (!ImGui::BeginPopupModal("Quantize", &isOpenQuantizeImage, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar))
131 return;
132
133 float buttonWidth = Gutil::GetUIParamScaled(76.0f, 2.5f);
134 float itemWidth = Gutil::GetUIParamScaled(160.0f, 2.5f);
135
136 tAssert(CurrImage);
137 static int method = int(tImage::tQuantize::Method::Wu);
138 static int spatialFilterSize = 1;
139 static float spatialDitherLevel = 0.0f;
140 static int neuSampleFactor = 1;
141 static int numColours = 256;
142
143 DoQuantizeInterface(method, spatialFilterSize, spatialDitherLevel, neuSampleFactor, itemWidth);
144
145 ImGui::SetNextItemWidth(itemWidth);
146 ImGui::InputInt("Num Colours", &numColours);
147 ImGui::SameLine();
148 Gutil::HelpMark
149 (
150 "The number of colours you are quantizing to. Must be between 2 and 256."
151 );
152 tMath::tiClamp(numColours, 2, 256);
153
154 static bool checkExact = true;
155 ImGui::Checkbox("Check Exact", &checkExact);
156 ImGui::SameLine();
157 Gutil::HelpMark
158 (
159 "If Check-Exact is true pressing Quantize will inspect all image pixels in case there are\n"
160 "fewer (or equal) colours than the number of colours requested. If this is true then the\n"
161 "image is exactly representable already and the quantize is not needed. If false the\n"
162 "quantize will proceed either way, and the chosen quantize method may adjust the colours."
163 );
164
165 // This is so we can print a warning if it's going to take a really long time.
166 float quantizeDurationApprox = ComputeApproxQuantizeDuration(CurrImage, tImage::tQuantize::Method(method), numColours);
167 float maxDurationBeforeWarning = 10.0f;
168 if (quantizeDurationApprox > maxDurationBeforeWarning)
169 {
170 ImGui::Text
171 (
172 "\n"
173 "Based on the image resolution, quantization\n"
174 "method, and number of colours, this operation\n"
175 "will take more than %d seconds.\n\n"
176 "Consider a different method or reduce the\n"
177 "number of colours.",
178 int(quantizeDurationApprox)
179 );

Callers

nothing calls this directly

Calls 6

UnbindMethod · 0.80
QuantizeFixedMethod · 0.80
QuantizeSpatialMethod · 0.80
QuantizeNeuMethod · 0.80
QuantizeWuMethod · 0.80
BindMethod · 0.80

Tested by

no test coverage detected