diff --git a/ImpBrush.h b/ImpBrush.h index 45d1b2e..d0a3cec 100644 --- a/ImpBrush.h +++ b/ImpBrush.h @@ -24,6 +24,7 @@ enum WARP_BRUSH, BLUR_BRUSH, SHARPEN_BRUSH, + PIXELIZE_BRUSH, NUM_BRUSH_TYPE // Make sure this stays at the end! }; diff --git a/ImpressionistDoc.cpp b/ImpressionistDoc.cpp index 0f9ad60..7b746b3 100644 --- a/ImpressionistDoc.cpp +++ b/ImpressionistDoc.cpp @@ -25,6 +25,7 @@ #include "WarpBrush.h" #include "Bayesian.h" #include "KernelBrush.h" +#include "PixelizeBrush.h" #define DESTROY(p) { if ((p)!=NULL) {delete [] p; p=NULL; } } @@ -72,6 +73,8 @@ ImpressionistDoc::ImpressionistDoc() = new KernelBrush( this, "Blur Brush" ); ImpBrush::c_pBrushes[SHARPEN_BRUSH] = new KernelBrush( this, "Sharpen Brush" ); + ImpBrush::c_pBrushes[PIXELIZE_BRUSH] + = new PixelizeBrush( this, "Pixelize Brush" ); std::vector> blurKernel = { {1,2,1}, diff --git a/ImpressionistUI.cpp b/ImpressionistUI.cpp index 6de6402..d804669 100644 --- a/ImpressionistUI.cpp +++ b/ImpressionistUI.cpp @@ -784,6 +784,7 @@ Fl_Menu_Item ImpressionistUI::brushTypeMenu[NUM_BRUSH_TYPE + 1] = { { "Warp Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)WARP_BRUSH }, { "Blur Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)BLUR_BRUSH }, { "Sharpen Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)SHARPEN_BRUSH }, + { "Pixelize Brush", FL_ALT + 'a', (Fl_Callback*)ImpressionistUI::cb_brushChoice, (void*)PIXELIZE_BRUSH }, { 0 } }; diff --git a/KernelBrush.cpp b/KernelBrush.cpp index 504ce29..79c592b 100644 --- a/KernelBrush.cpp +++ b/KernelBrush.cpp @@ -72,7 +72,7 @@ void KernelBrush::BrushEnd(const Point source, const Point target) delete[] ref; } -void KernelBrush::ApplyKernel(const Point source, const Point target, GLubyte* ref) +void KernelBrush::ApplyKernel(const Point source, const Point target, unsigned char* ref) { ImpressionistDoc* pDoc = GetDocument(); int w = pDoc->m_nPaintWidth, h = pDoc->m_nPaintHeight; diff --git a/KernelBrush.h b/KernelBrush.h index 82c8f3b..39d83c7 100644 --- a/KernelBrush.h +++ b/KernelBrush.h @@ -1,7 +1,6 @@ #pragma once #include "ImpBrush.h" #include -#include "BlurBrush.h" class KernelBrush : public ImpBrush @@ -12,7 +11,7 @@ class KernelBrush : void BrushBegin(const Point source, const Point target); void BrushMove(const Point source, const Point target); void BrushEnd(const Point source, const Point target); - void ApplyKernel(Point source, Point target, GLubyte* ref); + void ApplyKernel(Point source, Point target, unsigned char* ref); char* BrushName(void); void SetKernel(std::vector>kernel) { this->kernel = kernel; } diff --git a/PixelizeBrush.cpp b/PixelizeBrush.cpp new file mode 100644 index 0000000..d9d5073 --- /dev/null +++ b/PixelizeBrush.cpp @@ -0,0 +1,70 @@ +// +// PixelizeBrush.cpp +// +// The implementation of Point Brush. It is a kind of ImpBrush. All your brush implementations +// will look like the file with the different GL primitive calls. +// + +#include "impressionistDoc.h" +#include "impressionistUI.h" +#include "PixelizeBrush.h" + +extern float frand(); + +PixelizeBrush::PixelizeBrush(ImpressionistDoc* pDoc, char* name) : + ImpBrush(pDoc, name) +{ +} + +void PixelizeBrush::BrushBegin(const Point source, const Point target) +{ + ImpressionistDoc* pDoc = GetDocument(); + ImpressionistUI* dlg = pDoc->m_pUI; + + int size = pDoc->getSize(); + + BrushMove(source, target); +} + +void PixelizeBrush::BrushMove(const Point source, const Point target) +{ + ImpressionistDoc* pDoc = GetDocument(); + ImpressionistUI* pUI = pDoc->m_pUI; + + if (pDoc == NULL) { + printf("PixelizeBrush::BrushMove document is NULL\n"); + return; + } + + if (source.x > pDoc->m_nPaintWidth || source.y < 0) + { + return; + } + + int ksize = pUI->getSize(), csize = pUI->getLineWidth(); + int w = pDoc->m_nPaintWidth, h = pDoc->m_nPaintHeight; + + glPointSize(1.0); + glBegin(GL_POINTS); + for(int i = -ksize/2; i < ksize / 2; i++) + { + for (int j = -ksize / 2; j < ksize / 2; j++) { + + Point sample, subTarget; + sample.x = source.x+i - (source.x+i) % csize; + sample.y = source.y+j - (source.y+j) % csize; + subTarget.x = target.x + i; + subTarget.y = target.y + j; + + SetColor(sample); + glVertex2d(subTarget.x, subTarget.y); + + } + } + glEnd(); +} + +void PixelizeBrush::BrushEnd(const Point source, const Point target) +{ +} + diff --git a/PixelizeBrush.h b/PixelizeBrush.h new file mode 100644 index 0000000..793d862 --- /dev/null +++ b/PixelizeBrush.h @@ -0,0 +1,25 @@ +// +// PixelizeBrush.h +// +// The header file for Point Brush. +// + +#ifndef PixelizeBrush_H +#define PixelizeBrush_H + +#include "ImpBrush.h" + +class PixelizeBrush : public ImpBrush +{ +public: + PixelizeBrush(ImpressionistDoc* pDoc = NULL, char* name = NULL); + + void BrushBegin(const Point source, const Point target); + void BrushMove(const Point source, const Point target); + void BrushEnd(const Point source, const Point target); + char* BrushName(void); + + Point startSource, startTarget; +}; + +#endif \ No newline at end of file diff --git a/impressionist.vcxproj b/impressionist.vcxproj index 4b18ca9..751de96 100644 --- a/impressionist.vcxproj +++ b/impressionist.vcxproj @@ -144,10 +144,10 @@ - + @@ -174,10 +174,10 @@ - + diff --git a/impressionist.vcxproj.filters b/impressionist.vcxproj.filters index d2e4f50..d9859a2 100644 --- a/impressionist.vcxproj.filters +++ b/impressionist.vcxproj.filters @@ -93,10 +93,10 @@ Source Files - + Source Files - + Source Files @@ -182,10 +182,10 @@ Header Files - + Header Files - + Header Files diff --git a/readme.md b/readme.md index c2a2cc1..412e072 100644 --- a/readme.md +++ b/readme.md @@ -12,7 +12,11 @@ Programming project 1 of HKUST Computer Graphics course COMP4411 > > Underline: wanted to do -- [ ] (1W each) more brushes +- [x] (1W each) more brushes + - [ ] pattern brush + - [x] pixelize brush + - [ ] random polygon + - [ ] clone brush - [x] **(1W)** clipped bushes - [x] **(1W)** cursor on original image - [x] (1W) swap content and original