Skip to content

Commit

Permalink
Merge pull request #20 from dipsywong98/daniel
Browse files Browse the repository at this point in the history
Completed Dissolve
  • Loading branch information
danvim authored Feb 28, 2019
2 parents 1ceb5cc + f325bec commit 77ba7a7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
56 changes: 56 additions & 0 deletions ImpressionistUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,44 @@ void ImpressionistUI::cb_tracer_update(Fl_Widget* o, void* v)
uiPtr->m_paintView->redraw();
}

void ImpressionistUI::cb_open_dissolve_dialog(Fl_Widget* o, void*)
{
whoami(dynamic_cast<Fl_Menu_*>(o))->m_dissolveDialog->show();
}


void ImpressionistUI::cb_dissolve(Fl_Widget* o, void*)
{
auto* uiPtr = static_cast<ImpressionistUI*>(o->user_data());

const auto dissolveRatio = uiPtr->m_dissolveOpacitySlider->value() / 100.0;

auto* fileName = fl_file_chooser("Open File?", "*.bmp", nullptr);
if (fileName != nullptr) {
auto width = 0;
auto height = 0;
ImageWrapper imageWrapper = {
readBMP(fileName, width, height),
{ width, height }
};

ImageUtils::eachPixel<unsigned char>(uiPtr->m_pDoc->m_ucPainting, {uiPtr->m_pDoc->m_nPaintWidth, uiPtr->m_pDoc->m_nPaintHeight }, [&](unsigned char* rgbArray, const long x, const long y)
{
auto* otherPixel = imageWrapper.getPixelPtr(x, y);
rgbArray[0] = static_cast<unsigned char>(dissolveRatio * rgbArray[0] + (1 - dissolveRatio) * otherPixel[0]);
rgbArray[1] = static_cast<unsigned char>(dissolveRatio * rgbArray[1] + (1 - dissolveRatio) * otherPixel[1]);
rgbArray[2] = static_cast<unsigned char>(dissolveRatio * rgbArray[2] + (1 - dissolveRatio) * otherPixel[2]);
});

uiPtr->m_paintView->redraw();
}
else
{
fl_alert("File not selected!");
}
}




//---------------------------------- per instance functions --------------------------------------
Expand Down Expand Up @@ -753,6 +791,7 @@ Fl_Menu_Item ImpressionistUI::menuitems[] = {
{ "&Swap Content", FL_ALT + 's', (Fl_Callback*)ImpressionistUI::cb_swap_content },
{ "&Undo", FL_ALT + 'z', (Fl_Callback*)ImpressionistUI::cb_undo },
{ "Tracer...", 0, cb_open_tracer_dialog },
{ "Dissolve...", 0, cb_open_dissolve_dialog },
{ "&Auto Fill", FL_ALT + 'f', (Fl_Callback*)ImpressionistUI::cb_auto_fill_menu },
{ "&Load Another Img", FL_ALT + 'l', (Fl_Callback*)ImpressionistUI::cb_load_another_image },
{ "&Load Mural Img", FL_ALT + 'm', (Fl_Callback*)ImpressionistUI::cb_load_mural_image },
Expand Down Expand Up @@ -1124,4 +1163,21 @@ ImpressionistUI::ImpressionistUI()
m_tracerOpacitySlider->callback(cb_tracer_update);
}
m_tracerDialog->end();

m_dissolveDialog = new Fl_Window(320, 100, "Dissolve...");
{
m_dissolveOpacitySlider = new Fl_Value_Slider(10, 10, 300, 20, "Original Opacity");
m_dissolveOpacitySlider->user_data(static_cast<void*>(this));
m_dissolveOpacitySlider->type(FL_HOR_NICE_SLIDER);
m_dissolveOpacitySlider->minimum(0.0);
m_dissolveOpacitySlider->maximum(100.0);
m_dissolveOpacitySlider->step(1.0);
m_dissolveOpacitySlider->value(50.0);
m_dissolveOpacitySlider->align(FL_ALIGN_BOTTOM);

m_dissolveLoadImageBtn = new Fl_Button(110, 65, 100, 25, "Load Image");
m_dissolveLoadImageBtn->user_data(static_cast<void*>(this));
m_dissolveLoadImageBtn->callback(cb_dissolve);
}
m_dissolveDialog->end();
}
2 changes: 1 addition & 1 deletion impressionist.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<WarningLevel>Level3</WarningLevel>
<MinimalRebuild>true</MinimalRebuild>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>local\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>local\include;$(MSBuildProjectDirectory);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AssemblerListingLocation>c:\temp\</AssemblerListingLocation>
<PrecompiledHeaderOutputFile>c:\temp\impressionist.pch</PrecompiledHeaderOutputFile>
Expand Down
6 changes: 6 additions & 0 deletions impressionistUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ class ImpressionistUI {
Fl_Window* m_tracerDialog;
Fl_Value_Slider* m_tracerOpacitySlider;

Fl_Window* m_dissolveDialog;
Fl_Value_Slider* m_dissolveOpacitySlider;
Fl_Button* m_dissolveLoadImageBtn;


// Member functions
void setDocument(ImpressionistDoc* doc);
Expand Down Expand Up @@ -203,6 +207,8 @@ class ImpressionistUI {
static Fl_Callback cb_open_colors_dialog;
static Fl_Callback cb_open_tracer_dialog;
static Fl_Callback cb_tracer_update;
static Fl_Callback cb_open_dissolve_dialog;
static Fl_Callback cb_dissolve;

};

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Programming project 1 of HKUST Computer Graphics course COMP4411
- [x] (1B) change color of image (change channel)
- [x] **(1B)** blur brush and sharpen brush (wait for kernel brush)
- [x] **(1B)** undo
- [ ] (1B) Dissolve one image into another
- [x] (1B) Dissolve one image into another
- [x] (1B1W) original image overlay
- [x] _(1B1W)_ mural image (load another image without resetting)
- [x] (1B1W) alpha mapping brush
Expand Down

0 comments on commit 77ba7a7

Please sign in to comment.