Click here to Skip to main content
13,198,563 members (22,206 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.1K views
5 bookmarked
Posted 29 Nov 2009

Pixel Count

, 30 Nov 2009
Rate this:
Please Sign up or sign in to vote.
/*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)

Share

About the Author

BUR456
United States United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 30 Nov 2009
Article Copyright 2009 by BUR456
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid