Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
12
Task/Grayscale-image/C/grayscale-image-1.c
Normal file
12
Task/Grayscale-image/C/grayscale-image-1.c
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
typedef unsigned char luminance;
|
||||
typedef luminance pixel1[1];
|
||||
typedef struct {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
luminance *buf;
|
||||
} grayimage_t;
|
||||
typedef grayimage_t *grayimage;
|
||||
|
||||
grayimage alloc_grayimg(unsigned int, unsigned int);
|
||||
grayimage tograyscale(image);
|
||||
image tocolor(grayimage);
|
||||
9
Task/Grayscale-image/C/grayscale-image-2.c
Normal file
9
Task/Grayscale-image/C/grayscale-image-2.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
grayimage alloc_grayimg(unsigned int width, unsigned int height)
|
||||
{
|
||||
grayimage img;
|
||||
img = malloc(sizeof(grayimage_t));
|
||||
img->buf = malloc(width*height*sizeof(pixel1));
|
||||
img->width = width;
|
||||
img->height = height;
|
||||
return img;
|
||||
}
|
||||
23
Task/Grayscale-image/C/grayscale-image-3.c
Normal file
23
Task/Grayscale-image/C/grayscale-image-3.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
grayimage tograyscale(image img)
|
||||
{
|
||||
unsigned int x, y;
|
||||
grayimage timg;
|
||||
double rc, gc, bc, l;
|
||||
unsigned int ofs;
|
||||
|
||||
timg = alloc_grayimg(img->width, img->height);
|
||||
|
||||
for(x=0; x < img->width; x++)
|
||||
{
|
||||
for(y=0; y < img->height; y++)
|
||||
{
|
||||
ofs = (y * img->width) + x;
|
||||
rc = (double) img->buf[ofs][0];
|
||||
gc = (double) img->buf[ofs][1];
|
||||
bc = (double) img->buf[ofs][2];
|
||||
l = 0.2126*rc + 0.7152*gc + 0.0722*bc;
|
||||
timg->buf[ofs][0] = (luminance) (l+0.5);
|
||||
}
|
||||
}
|
||||
return timg;
|
||||
}
|
||||
22
Task/Grayscale-image/C/grayscale-image-4.c
Normal file
22
Task/Grayscale-image/C/grayscale-image-4.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
image tocolor(grayimage img)
|
||||
{
|
||||
unsigned int x, y;
|
||||
image timg;
|
||||
luminance l;
|
||||
unsigned int ofs;
|
||||
|
||||
timg = alloc_img(img->width, img->height);
|
||||
|
||||
for(x=0; x < img->width; x++)
|
||||
{
|
||||
for(y=0; y < img->height; y++)
|
||||
{
|
||||
ofs = (y * img->width) + x;
|
||||
l = img->buf[ofs][0];
|
||||
timg->buf[ofs][0] = l;
|
||||
timg->buf[ofs][1] = l;
|
||||
timg->buf[ofs][2] = l;
|
||||
}
|
||||
}
|
||||
return timg;
|
||||
}
|
||||
1
Task/Grayscale-image/C/grayscale-image-5.c
Normal file
1
Task/Grayscale-image/C/grayscale-image-5.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
#define free_grayimg(IMG) free_img((image)(IMG))
|
||||
Loading…
Add table
Add a link
Reference in a new issue