-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdithering.cpp
More file actions
39 lines (36 loc) · 787 Bytes
/
dithering.cpp
File metadata and controls
39 lines (36 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdlib.h>
#define n 300
#define max_itensity 256
int real[n][n];
int dither[3][3];
int output[n][n];
int main()
{
printf("Generating random 300x300 image\n");
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
real[i][j]=rand() % max_itensity;
}
printf("Done\n");
printf("Generating random 3x3 dither matrix\n");
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
dither[i][j]=rand()%9;
}
printf("Done\n");
printf("Dithering\n");
for(int y=0; y<n; y++)
{
for(int x=0; x<n; x++)
{
int i = x % n;
int j = y % n;
output[x][y] = (real[x][y] > dither[i][j])? 255 : 0;
}
}
printf("Done\n");
return 0;
}