OpenCores
URL https://opencores.org/ocsvn/djpeg/djpeg/trunk

Subversion Repositories djpeg

[/] [djpeg/] [trunk/] [c_model/] [convsim.c] - Blame information for rev 10

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 10 hidemi
//////////////////////////////////////////////////////////////////////////////
2
#include <stdio.h>
3
#include <stdlib.h>
4
 
5
typedef unsigned short WORD;
6
typedef unsigned long DWORD;
7
typedef long LONG;
8
 
9
typedef struct tagBITMAPINFOHEADER{
10
  DWORD  biSize;
11
  LONG   biWidth;
12
  LONG   biHeight;
13
  WORD   biPlanes;
14
  WORD   biBitCount;
15
  DWORD  biCompression;
16
  DWORD  biSizeImage;
17
  LONG   biXPelsPerMeter;
18
  LONG   biYPelsPerMeter;
19
  DWORD  biClrUsed;
20
  DWORD  biClrImportant;
21
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;
22
 
23
//////////////////////////////////////////////////////////////////////////////
24
// メイン関数
25
//////////////////////////////////////////////////////////////////////////////
26
int main(int argc, char *argv[])
27
{
28
  unsigned char buff[4];
29
  char data[256];
30
  FILE *rfp,*wfp;
31
 
32
  unsigned long width;
33
  unsigned long height;
34
  unsigned long bitdata;
35
  unsigned char tbuff[4];
36
  BITMAPINFOHEADER lpBi;
37
 
38
  unsigned char *image;
39
  unsigned int i;
40
 
41
  if((rfp = fopen(argv[1],"rb")) == NULL){
42
    perror(0);
43
    exit(0);
44
  }
45
 
46
  if((wfp = fopen(argv[2],"wb")) == NULL){
47
    perror(0);
48
    exit(0);
49
  }
50
 
51
 
52
  fgets(data,256,rfp);
53
  width = (unsigned int)strtol(data,NULL,10);
54
  fgets(data,256,rfp);
55
  height = (unsigned int)strtol(data,NULL,10);
56
 
57
  image = (unsigned char *)malloc(height*width*3);
58
 
59
  // ファイルヘッダの設定
60
  tbuff[0] = 'B';
61
  tbuff[1] = 'M';
62
  fwrite(tbuff,2,1,wfp);
63
  tbuff[3] = ((14 +40 +width * height * 3) >> 24) & 0xff;
64
  tbuff[2] = ((14 +40 +width * height * 3) >> 16) & 0xff;
65
  tbuff[1] = ((14 +40 +width * height * 3) >>  8) & 0xff;
66
  tbuff[0] = ((14 +40 +width * height * 3) >>  0) & 0xff;
67
  fwrite(tbuff,4,1,wfp);
68
  tbuff[1] = 0;
69
  tbuff[0] = 0;
70
  fwrite(tbuff,2,1,wfp);
71
  fwrite(tbuff,2,1,wfp);
72
  tbuff[3] = 0;
73
  tbuff[2] = 0;
74
  tbuff[1] = 0;
75
  tbuff[0] = 54;
76
  fwrite(tbuff,4,1,wfp);
77
 
78
  // インフォメーションの設定
79
  lpBi.biSize            = 40;
80
  lpBi.biWidth           = width;
81
  lpBi.biHeight          = height;
82
  lpBi.biPlanes          = 1;
83
  lpBi.biBitCount        = 3*8;
84
  lpBi.biCompression     = 0;
85
  lpBi.biSizeImage       = width*height*3;
86
  lpBi.biXPelsPerMeter   = 300;
87
  lpBi.biYPelsPerMeter   = 300;
88
  lpBi.biClrUsed         = 0;
89
  lpBi.biClrImportant    = 0;
90
  fwrite(&lpBi,1,40,wfp);
91
 
92
  i = 0;
93
  while(!feof(rfp)){
94
    if(i>=width*height) break;
95
    fgets(data,256,rfp);
96
    bitdata=strtol(data,NULL,16);
97
    image[((height-i/width-1)*width*3)+(i%width)*3+0] = (bitdata >>  0) & 0xff;
98
    image[((height-i/width-1)*width*3)+(i%width)*3+1] = (bitdata >>  8) & 0xff;
99
    image[((height-i/width-1)*width*3)+(i%width)*3+2] = (bitdata >> 16) & 0xff;
100
    i++;
101
  }
102
  fwrite(image,1,width*height*3,wfp);
103
  fclose(rfp);
104
  fclose(wfp);
105
  free(image);
106
 
107
  return 0;
108
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.