summaryrefslogtreecommitdiffstats
path: root/src/bmpjpeg.c
blob: a21bfe821beb6199020cbe757e9406442d356d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "color.h"

void BMPto8x8AndYCbCr(int Start_x, int Start_y, int ImageSize_x, int ImageSize_y, int offset, unsigned char depth ,unsigned char *Image, unsigned char *blok8x8)
{
	unsigned char i,color;
	int x,y,Start_point;
//	printf("\nBMPto8x8AndYCbCr:\n");
	depth = depth/8;
	Start_point = offset + (ImageSize_x*(ImageSize_y-1)+Start_x-(Start_y*ImageSize_x))*depth;
	for(i=0;i<(64*depth);i+=depth)
	{
//			if((i%8)==0) printf("\n");
			if((Start_y+(i/(8*depth))) < ImageSize_y)
			{
				if((Start_x+((i%(8*depth))/depth)) < ImageSize_x)
				{
					if(depth == 3)
					{
						RGB2YCbCr(Image[Start_point+(i%(8*depth))  -(i/(8*depth))*(ImageSize_x*depth)],
									Image[Start_point+(i%(8*depth))+1-(i/(8*depth))*(ImageSize_x*depth)],
										Image[Start_point+(i%(8*depth))+2-(i/(8*depth))*(ImageSize_x*depth)],
										&blok8x8[i],&blok8x8[i+1],&blok8x8[i+2]);

			//			printf("%02x%02x%02x|",blok8x8[i+0],blok8x8[i+1],blok8x8[i+2]);
					}
					if(depth == 1)
					{
						blok8x8[i] = Image[Start_point+(i%(8*depth))-(i/(8*depth))*(ImageSize_x*depth)];
//						printf("%02x ",blok8x8[i]);
					}
				}
			}
			else
				i = (64*depth);
	}
}

void YCbCrAnd8x8toBMP(int Start_x, int Start_y, int ImageSize_x, int ImageSize_y, int offset, unsigned char depth ,unsigned char *Image, unsigned char *blok8x8)
{
	unsigned char i;
	int x,y,Start_point;
//	printf("\nYCbCrAnd8x8toBMP:\n");
	depth = depth/8;
	Start_point = offset + (ImageSize_x*(ImageSize_y-1)+Start_x-(Start_y*ImageSize_x))*depth;
	for(i=0;i<(64*depth);i+=depth)
	{
//			if((i%8)==0) printf("\n");
			if((Start_y+(i/(8*depth))) < ImageSize_y)
			{
				if((Start_x+((i%(8*depth))/depth)) < ImageSize_x)
				{
					if(depth == 3)
					{
						YCbCr2RGB(blok8x8[i+0],blok8x8[i+1],blok8x8[i+2],
									&Image[Start_point+(i%(8*depth))  -(i/(8*depth))*(ImageSize_x*depth)],
										&Image[Start_point+(i%(8*depth))+1-(i/(8*depth))*(ImageSize_x*depth)],
										&Image[Start_point+(i%(8*depth))+2-(i/(8*depth))*(ImageSize_x*depth)]);

			//			printf("%02x%02x%02x|",blok8x8[i+0],blok8x8[i+1],blok8x8[i+2]);
					}
					if(depth == 1)
					{
						Image[Start_point+(i%(8*depth))-(i/(8*depth))*(ImageSize_x*depth)] = blok8x8[i];
//						printf("%02x ",blok8x8[i]);
					}
				}
			}
			else
				i = (64*depth);
	}

}

/*****************************
The code without the RGB - > YUV
******************************

void BMPto8x8(int Start_x, int Start_y, int ImageSize_x, int ImageSize_y, int offset, unsigned char depth ,unsigned char *Image, unsigned char *blok8x8)
{
	unsigned char i;
	int x,y,Start_point;
	depth = depth/8;
	Start_point = offset + (ImageSize_x*(ImageSize_y-1)+Start_x-(Start_y*ImageSize_x))*depth;
	for(i=0;i<(64*depth);i+=depth)
	{
			if((i%8)==0) printf("\n");
			if((Start_y+(i/(8*depth))) < ImageSize_y)
			{
				if((Start_x+((i%(8*depth))/depth)) < ImageSize_x)
				{
					if(depth == 3)
					{
						blok8x8[i+2] = Image[Start_point+(i%(8*depth))  -(i/(8*depth))*(ImageSize_x*depth)]; //R
						blok8x8[i+1] = Image[Start_point+(i%(8*depth))+1-(i/(8*depth))*(ImageSize_x*depth)]; //G
						blok8x8[i+0] = Image[Start_point+(i%(8*depth))+2-(i/(8*depth))*(ImageSize_x*depth)]; //B
						printf("%02x%02x%02x|",blok8x8[i+0],blok8x8[i+1],blok8x8[i+2]);
					}
					if(depth == 1)
					{
						blok8x8[i+0] = Image[Start_point+(i%(8*depth))-(i/(8*depth))*(ImageSize_x*depth)];
						printf("%02x ",blok8x8[i]);
					}
				}
			}
			else
				i = (64*depth);
	}
}

void B8x8toBMP(int Start_x, int Start_y, int ImageSize_x, int ImageSize_y, int offset, unsigned char depth ,unsigned char *Image, unsigned char *blok8x8)
{
	unsigned char i;
	int x,y,Start_point;
	depth = depth/8;
	Start_point = offset + (ImageSize_x*(ImageSize_y-1)+Start_x-(Start_y*ImageSize_x))*depth;
	for(i=0;i<(64*depth);i+=depth)
	{
			if((i%8)==0) printf("\n");
			if((Start_y+(i/(8*depth))) < ImageSize_y)
			{
				if((Start_x+((i%(8*depth))/depth)) < ImageSize_x)
				{
					if(depth == 3)
					{
						Image[Start_point+(i%(8*depth))  -(i/(8*depth))*(ImageSize_x*depth)] = blok8x8[i+2]; //R
						Image[Start_point+(i%(8*depth))+1-(i/(8*depth))*(ImageSize_x*depth)] = blok8x8[i+1]; //G
						Image[Start_point+(i%(8*depth))+2-(i/(8*depth))*(ImageSize_x*depth)] = blok8x8[i+0]; //B
						printf("%02x%02x%02x|",blok8x8[i+0],blok8x8[i+1],blok8x8[i+2]);
					}
					if(depth == 1)
					{
						Image[Start_point+(i%(8*depth))-(i/(8*depth))*(ImageSize_x*depth)] = blok8x8[i+0];
						printf("%02x ",blok8x8[i]);
					}
				}
			}
			else
				i = (64*depth);
	}

}

*/