Click here to Skip to main content
11,639,861 members (65,811 online)
Click here to Skip to main content

Tagged as

Pixel Count

, 30 Nov 2009 CPOL 2.9K 5
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
No Biography provided

You may also be interested in...

Comments and Discussions

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