⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makelogo.c

📁 这个代码是实现了将给定的bmp图片转换成linux所识别的logo启动画面
💻 C
字号:
/*
* This file is just used to convert the bmp file to Linux logo data
* The Input file is the 640*480 bmp file( User must guarantee this)
* The Output file is the data file with the same name but differt ext filename file
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define OFFSET		32
//#define	WIDTH		640
//#define HEIGHT		480

typedef struct {
	char id[2];
	long filesize;
	int reserved[2];
	long headersize;
	long infoSize;
	long width;
	long height;
	int biPlanes;
	int bits;
	long biCompression;
	long biSizeImage;
	long biXPixsPerMeter;
	long biYPixsPerMeter;
	long biClrUsed;
	long biClrImportant;
	}BMPHEAD;
typedef struct{
	char blue;
	char green;
	char red;
	char filled;
	}RGBQUAD;

RGBQUAD	Pal;
BMPHEAD	bhead;

void main(int argc,char *argv[])
 {
	unsigned int i,j,k;
	FILE *fp,*fq,*fp_r,*fp_g,*fp_b;
	char filename[40];
	char *p;
	unsigned char temp,t;
	char Buf[2048];
	char palnum;

	if(argc != 2){
	   printf("\nUsage: %s filename",argv[0]);
	   exit(0);
	}

	//printf("\nEnter input filename:");
	//scanf("%s",filename);
	strcpy(filename,argv[1]);
	fp=fopen(filename,"rb");
	if(fp==NULL)
		{
		printf("Input File open error\n");
		exit(-1);
		}

	p = filename + strlen(filename) - 1;
	*(p-2) = 'r';
	*(p-1) = 'x';
	*(p) = 't';

	if((fp_r = fopen(filename,"wb")) == NULL)
	   {
		  printf("Output File open error!\n");
		  fclose(fp);
		  exit(-1);
	   }
	*(p-2) = 'g';
	if((fp_g = fopen(filename,"wb")) == NULL)
	   {
		  printf("Output File open error!\n");
		  fclose(fp);
		  fclose(fp_r);
		  exit(-1);
	   }
	*(p-2) = 'b';
	if((fp_b = fopen(filename,"wb")) == NULL)
	   {
		  printf("Output File open error!\n");
		  fclose(fp);
		  fclose(fp_r);
		  fclose(fp_g);
		  exit(-1);
	   }

	fread(&bhead,sizeof(BMPHEAD),1,fp);

	//fseek(fp,bhead.headersize,SEEK_SET);

	for(k=0; k< 256/8; k++)
	   {
		for(j=0; j<8; j++)
		   {
			fread(&temp,1,1,fp);
			Buf[0] = '0';
			Buf[1] = 'x';
			t = (temp>>4)&0x0f;
			Buf[2] = (t>9) ? (t+0x37):(t+0x30);
			t = temp&0x0f;
			Buf[3] = (t>9) ? (t+0x37):(t+0x30);
			Buf[4] = ',';
			fwrite(Buf,1,5,fp_b);

			fread(&temp,1,1,fp);
			Buf[0] = '0';
			Buf[1] = 'x';
			t = (temp>>4)&0x0f;
			Buf[2] = (t>9) ? (t+0x37):(t+0x30);
			t = temp&0x0f;
			Buf[3] = (t>9) ? (t+0x37):(t+0x30);
			Buf[4] = ',';
			fwrite(Buf,1,5,fp_g);

			fread(&temp,1,1,fp);
			Buf[0] = '0';
			Buf[1] = 'x';
			t = (temp>>4)&0x0f;
			Buf[2] = (t>9) ? (t+0x37):(t+0x30);
			t = temp&0x0f;
			Buf[3] = (t>9) ? (t+0x37):(t+0x30);
			Buf[4] = ',';
			fwrite(Buf,1,5,fp_r);

			fread(&temp,1,1,fp);
			}//j
			Buf[0] = '\n';
			fwrite(Buf,1,1,fp_r);
			fwrite(Buf,1,1,fp_g);
			fwrite(Buf,1,1,fp_b);
		}//k

	fclose(fp_r);
	fclose(fp_g);
	fclose(fp_b);

	*(p-2) = 't';
	if((fq = fopen(filename,"wb")) == NULL)
		{
		printf("Output File open error!\n");
		fclose(fp);
		fclose(fp_r);
		fclose(fp_g);
		fclose(fp_b);
		exit(-1);
		}
	//printf("width = %ld,height = %ld\n",bhead.width,bhead.height);
	//printf("filesize = %x\n",bhead.filesize);
	//printf("seek %ld\n",bhead.filesize-bhead.width);
	fseek(fp,bhead.filesize-bhead.width,SEEK_SET);

	for(i=0; i< bhead.height; i++)
	{
		for(k=0; k< bhead.width/8; k++)
		{
			for(j=0; j<8; j++)
			{
				fread(&temp,1,1,fp);
				//temp += OFFSET;
				Buf[0] = '0';
				Buf[1] = 'x';
				t = (temp>>4)&0x0f;
				Buf[2] = (t>9) ? (t+0x37):(t+0x30);
				t = temp&0x0f;
				Buf[3] = (t>9) ? (t+0x37):(t+0x30);
				Buf[4] = ',';
				fwrite(Buf,1,5,fq);
			}//j
			Buf[0] = '\n';
			fwrite(Buf,1,1,fq);
		}//k
		fseek(fp,-(bhead.width*2),SEEK_CUR);
	}
	fclose(fq);

	fclose(fp);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -