-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.c
More file actions
35 lines (33 loc) · 663 Bytes
/
6.c
File metadata and controls
35 lines (33 loc) · 663 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
#include<gd.h>
#include<omp.h>
#include<stdio.h>
#include<stdlib.h>
int main(){
FILE *fo,*fc;
int h,w,i,j,c,r,g,b,k;
fo=fopen("input.png","r");
gdImagePtr img;
img=gdImageCreateFromPng(fo);
w=gdImageSY(img);
h=gdImageSX(img);
#pragma omp parallel for private(c,j,r,g,b) num_threads(8)
for(i=0;i<w;i++){
#pragma omp critical
{
for(j=0;j<h;j++){
c=gdImageGetPixel(img,i,j);
r=gdImageRed(img,c);
g=gdImageGreen(img,c);
b=gdImageBlue(img,c);
k=(r+g+b)/3;
r=k,g=k,b=k;
c=gdImageColorAllocate(img,r,g,b);
gdImageSetPixel(img,i,j,c);
}
}
}
fc=fopen("output.png","w");
gdImagePng(img,fc);
fclose(fc);
gdImageDestroy(img);
}