Skip to content

Commit

Permalink
Merge pull request #19 from dipsywong98/wip/pixelize
Browse files Browse the repository at this point in the history
pixelize brush
  • Loading branch information
dipsywong98 authored Feb 28, 2019
2 parents c29961d + 1d13f78 commit 1ceb5cc
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 10 deletions.
1 change: 1 addition & 0 deletions ImpBrush.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum
WARP_BRUSH,
BLUR_BRUSH,
SHARPEN_BRUSH,
PIXELIZE_BRUSH,
NUM_BRUSH_TYPE // Make sure this stays at the end!
};

Expand Down
3 changes: 3 additions & 0 deletions ImpressionistDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }

Expand Down Expand Up @@ -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<std::vector<float>> blurKernel = {
{1,2,1},
Expand Down
1 change: 1 addition & 0 deletions ImpressionistUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down
2 changes: 1 addition & 1 deletion KernelBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions KernelBrush.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include "ImpBrush.h"
#include <vector>
#include "BlurBrush.h"

class KernelBrush :
public ImpBrush
Expand All @@ -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<std::vector<float>>kernel) { this->kernel = kernel; }

Expand Down
70 changes: 70 additions & 0 deletions PixelizeBrush.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
}

25 changes: 25 additions & 0 deletions PixelizeBrush.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions impressionist.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@
<ClCompile Include="AlphaMapBrush.cpp" />
<ClCompile Include="Bayesian.cpp" />
<ClCompile Include="Bitmap.cpp" />
<ClCompile Include="BlurBrush.cpp" />
<ClCompile Include="CircleBrush.cpp" />
<ClCompile Include="Cluster.cpp" />
<ClCompile Include="CurvedBrush.cpp" />
<ClCompile Include="PixelizeBrush.cpp" />
<ClCompile Include="PowerIter.cpp" />
<ClCompile Include="ImageUtils.cpp" />
<ClCompile Include="ImpBrush.cpp" />
Expand All @@ -174,10 +174,10 @@
<ClInclude Include="AlphaMapBrush.h" />
<ClInclude Include="Bayesian.h" />
<ClInclude Include="bitmap.h" />
<ClInclude Include="BlurBrush.h" />
<ClInclude Include="CircleBrush.h" />
<ClInclude Include="Cluster.h" />
<ClInclude Include="CurvedBrush.h" />
<ClInclude Include="PixelizeBrush.h" />
<ClInclude Include="PowerIter.h" />
<ClInclude Include="ImageUtils.h" />
<ClInclude Include="ImpBrush.h" />
Expand Down
8 changes: 4 additions & 4 deletions impressionist.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@
<ClCompile Include="Tester.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BlurBrush.cpp">
<ClCompile Include="KernelBrush.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="KernelBrush.cpp">
<ClCompile Include="PixelizeBrush.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down Expand Up @@ -182,10 +182,10 @@
<ClInclude Include="Tester.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BlurBrush.h">
<ClInclude Include="KernelBrush.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="KernelBrush.h">
<ClInclude Include="PixelizeBrush.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1ceb5cc

Please sign in to comment.