Click here to Skip to main content
15,891,946 members
Articles / Programming Languages / C
Tip/Trick

Pixel Count

Rate me:
Please Sign up or sign in to vote.
1.40/5 (2 votes)
30 Nov 2009CPOL 6.9K   5  
/*1st TARGET:Program that prints multiple bmp images*//*2nd TARGET:prints the pixel value of colors used in image*/#include<stdio.h>#include<conio.h>#include<graphics.h>#include<dos.h>int main(void){ clrscr(); unsigned char color; long int Doffset, w, h; int...
/*1st TARGET:Program that prints multiple bmp images*/
/*2nd TARGET:prints the pixel value of colors used in image*/



#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>


int main(void)
{
	clrscr();
	unsigned char color;
	long int Doffset, w, h;
	int i,n[256],gd=0, gm=0, y ,x;
	FILE *flag, *flag2, *flag3, *flag4;
	flag = fopen("C:\\TC\\BIN\\bmp1.bmp","r");
	flag2 = fopen("C:\\TC\\BIN\\car.bmp","r");
	flag3 = fopen("C:\\TC\\BIN\\bmp2.bmp","r");
	flag4 = fopen("C:\\TC\\BIN\\bmp3.bmp","r");
	initgraph(&gd, &gm, "c:\\tc\\bgi");
	int gr = graphresult();
	if (gr!=0)
	{
		printf ("Fail");
		getch();
		return 0;
	}
	cleardevice();

	for(z=0; z<4; z++)
        {
        fseek(flag, 18, SEEK_SET);
	fread(&w, 4, 1, flag);
	fseek(flag, 22, SEEK_SET);
	fread(&h, 4, 1, flag);
	fseek(flag, 10, SEEK_SET);
	fread(&Doffset, 4, 1, flag);
	fseek(flag, Doffset, SEEK_SET);
	for(i=0; i<256; i++)
		n[i]=0;
	for(y=h; y>0; y--)
	{
		for(x=0; x<w; x++)
		{

			fread(&color, 1, 1, flag);
			putpixel(x, y, color);
			n[color]++;
		}

	}
	for(i=0; i<256; i++)
		{
		if(n[i] >0)
		printf("pixels of color %d=%d\n", i, n[i]);
		}
	getch();
	getch();
	cleardevice();
	fseek(flag2, 18, SEEK_SET);
	fread(&w, 4, 1, flag2);
	fseek(flag2, 22, SEEK_SET);
	fread(&h, 4, 1, flag2);
	fseek(flag2, 10, SEEK_SET);
	fread(&Doffset, 4, 1, flag2);
	fseek(flag2, Doffset, SEEK_SET);
	for(i=0; i<256; i++)
		n[i]=0;
       for(y=h; y>0; y--)
		{
		for(x=0; x<w; x++)
			{
			fread(&color, 1, 1, flag2);
			putpixel(x, y, color);
			n[color]++;
			}
		 }
	for(i=0; i<256; i++)
		{
		if(n[i] >0)
		printf("pixels of color %d=%d\n", i, n[i]);
		}

	getch();
	getch();
	cleardevice();
	fseek(flag3, 18, SEEK_SET);
	fread(&w, 4, 1, flag3);
	fseek(flag3, 22, SEEK_SET);
	fread(&h, 4, 1, flag3);
	fseek(flag3, 10, SEEK_SET);
	fread(&Doffset, 4, 1, flag3);
	fseek(flag3, Doffset, SEEK_SET);
	for(i=0; i<256; i++)
		n[i]=0;
       for(y=h; y>0; y--)
		{
		for(x=0; x<w; x++)
			{
			fread(&color, 1, 1, flag3);
			putpixel(x, y, color);
			n[color]++;
			}
		 }
	for(i=0; i<256; i++)
		{
		if(n[i] >0)
		printf("pixels of color %d=%d\n", i, n[i]);
		}

	getch();
	getch();
	cleardevice;
	fseek(flag4, 18, SEEK_SET);
	fread(&w, 4, 1, flag4);
	fseek(flag4, 22, SEEK_SET);
	fread(&h, 4, 1, flag4);
	fseek(flag4, 10, SEEK_SET);
	fread(&Doffset, 4, 1, flag4);
	fseek(flag4, Doffset, SEEK_SET);
	for(i=0; i<256; i++)
		n[i]=0;
	for(y=h; y>0; y--)
		{
		for(x=0; x<w; x++)
			{
			fread(&color, 1, 1, flag4);
			putpixel(x, y, color);
			n[color]++;
			}
		 }
		 for(i=0; i<256; i++)
		{
		if(n[i] >0)
		printf("pixels of color %d=%d\n", i, n[i]);
		}
getch();
getch();
}}
//*MUHAMMAD BURHAN UDDIN*/ ;P

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --