summaryrefslogtreecommitdiff
path: root/EDK/MiniSetup/TseAdvanced/pcxc.c
blob: 6c1f9fcb528f33fe8b2479bedf40d9563cce2f50 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2010, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pcxc.c $
//
// $Author: Arunsb $
//
// $Revision: 5 $
//
// $Date: 10/18/12 5:53a $
//
//*****************************************************************//
//*****************************************************************//
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseAdvanced/pcxc.c $
// 
// 5     10/18/12 5:53a Arunsb
// Updated for 2.16.1235 QA submission
// 
// 8     10/10/12 12:35p Arunsb
// Synched the source for v2.16.1232, backup with Aptio
// 
// 4     2/19/10 1:02p Madhans
// Updated for TSE 2.01. Refer Changelog.log for File change history.
// 
// 6     2/19/10 8:11a Mallikarjunanv
// updated year in copyright message
// 
// 5     8/13/09 12:16p Blaines
// Move Image support to binary module
// 
// 4     8/04/09 10:23a Madhans
// Fix to support big PCX images.(previously it was not supporing 800x600
// images.)
// 
// 3     6/23/09 7:09p Blaines
// Coding standard update, 
// Remove spaces from file header to allow proper chm function list
// creation.
// 
// 2     6/12/09 7:43p Presannar
// Initial implementation of coding standards for AMITSE2.0
// 
// 1     6/04/09 8:05p Madhans
// 
// 1     4/28/09 11:16p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 1     4/28/09 10:27p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 3     7/05/06 11:19a Madhans
// 
// 2     7/05/06 11:09a Madhans
// DecodePCX function optimized.
// 
// 1     6/30/06 4:22p Madhans
// PCX image support in C.
// 
// 2     6/26/06 8:41a Shirinmd
// Modifications based on design change suggested by Madhan
// 
// 1     6/16/06 8:15a Shirinmd
// Added PCX Support in C for Minisetup
//
//*****************************************************************//

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		pcx.c
//
// Description:	This file contains code for pcx image handling
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#include "pcx.h"


AMI_TRUECOLOR_PIXEL * ScreenBuffer = (AMI_TRUECOLOR_PIXEL *)NULL;

//Functions
BOOL PCX_Init(BYTE * pbyPCXImage, PCX_INFO *pPCX_INFO, DWORD dwPCXImageSize);
BOOL GetPCXDimensions( BYTE * pbyPCXImageData, UINT32 * pn32Width, UINT32 * pn32Height);
BOOL DecodePCX(BYTE * pbyPCXInputData, BYTE * pbyPCXOutputData, DWORD dwPCXImageSize);
void Decode_Line(DWORD *wCountX, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer);
void Output_Line(DWORD wTop, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer);

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PCX_Init
//
// Description:	This routine is used to fill the PCX_INFO structure.
//
// Input:	BYTE * pbyPCXImage - Pointer that gives the memory location 
//						where the PCX input data is available.
//					PCX_INFO *pPCX_INFO	- Pointer to PCX_INFO structure
//					DWORD dwPCXImageSize - Size of the PCX Image
//
// Output:	BOOL - TRUE/FALSE
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOL PCX_Init(BYTE * pbyPCXImage, PCX_INFO *pPCX_INFO, DWORD dwPCXImageSize)
{
	PCX_HEADER *pPCX_HEADER = (PCX_HEADER *)pbyPCXImage;

	if(pPCX_HEADER->bVersion != 5 || pPCX_HEADER->bBitsPerPixel == 1 || pPCX_HEADER->bBitsPerPixel == 2 || pPCX_HEADER->bColorPlanes != 1)
		return FALSE;
	
	pPCX_INFO->wImageWidth		= pPCX_HEADER->wXmax - pPCX_HEADER->wXmin + 1;
	pPCX_INFO->wImageHeight		= pPCX_HEADER->wYmax - pPCX_HEADER->wYmin + 1;
	pPCX_INFO->wBytesPerLine	= pPCX_HEADER->wBytesPerLine;
	pPCX_INFO->bBitsPerPixel	= pPCX_HEADER->bBitsPerPixel;	
	pPCX_INFO->dwPCXImageSize	= dwPCXImageSize;
	pPCX_INFO->bpPCXData		= pbyPCXImage + 128;
	if(pPCX_HEADER->bBitsPerPixel == 8)			//256 color image palette at the end
		pPCX_INFO->bpPalette	= pbyPCXImage + dwPCXImageSize - 768;
	else if(pPCX_HEADER->bBitsPerPixel == 4)	//16 color image palette in the header
		pPCX_INFO->bpPalette	= pPCX_HEADER->bPalette;
	return TRUE;

}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	GetPCXDimensions
//
// Description:	Get the dimensions (Width and Height of the PCX Image).
//
// Input:	BYTE * pbyPCXImageData - Pointer to the buffer that contains the PCX data
//					UINT32 * pun32Width - Pointer to the UINT32 variable that will 
//						receive the Width of the PCX Image
//					UINT32 * pun32Height - Pointer to the UINT32 variable that 
//						will receive the Height of the PCX Image
//
// Output:	BOOL - TRUE/FALSE
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOL GetPCXDimensions( BYTE * pbyPCXImageData, UINT32 * pun32Width, UINT32 * pun32Height){
	BOOL bReturn = FALSE;
	WORD wWidth = 0;
	WORD wHeight= 0;
	wWidth  = *((WORD*)(pbyPCXImageData+8)) - *((WORD*)(pbyPCXImageData+4)) + 1;
	wHeight = *((WORD*)(pbyPCXImageData+10)) - *((WORD*)(pbyPCXImageData+6)) + 1;
	if( (wWidth > 0) && (wHeight > 0))
	{
		*pun32Width = (UINT32)wWidth;
		*pun32Height = (UINT32)wHeight;
		bReturn = TRUE;
	}
	return bReturn;

}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	Decode_Line
//
// Description:	This routine will first check whether the PCX image is 16 
//					color or 256 color and then decode the PCX image data one 
//					line at a time and put the decoded data in a One Line Buffer.
//
// Input:	WORD *wCountX - Pointer to the index of the image data after 128 byte header
//					PCX_INFO *pPCX_INFO - Pointer to PCX_INFO structure
//					BYTE *pbOneLineBuffer - Pointer to the buffer that holds one line of decoded data.
//
// Output:	None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
void Decode_Line(DWORD *wCountX, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer)
{
	WORD wOffset_of_buffer = 0;
	int nDataCount = 0;
	WORD wLength_of_buffer = 0;
	while(wLength_of_buffer < (pPCX_INFO->wImageWidth))
	{
		if((pPCX_INFO->bpPCXData[*wCountX] & 0xC0) >= 0xC0)
			nDataCount = (pPCX_INFO->bpPCXData[(*wCountX)++] & 0x3f);
		else
			nDataCount = 1;

		while(nDataCount--)
		{
			if(pPCX_INFO->bBitsPerPixel == 8)
			{
				pbOneLineBuffer[wOffset_of_buffer++] = pPCX_INFO->bpPCXData[*wCountX];
				(wLength_of_buffer)++;
			}
			else if(pPCX_INFO->bBitsPerPixel == 4)
			{
				pbOneLineBuffer[wOffset_of_buffer++] = ((pPCX_INFO->bpPCXData[*wCountX]) >> 4);
				pbOneLineBuffer[wOffset_of_buffer++] = ((pPCX_INFO->bpPCXData[*wCountX]) & 0x0f);
				(wLength_of_buffer) = (wLength_of_buffer)+2;
			}
		}
		(*wCountX)++;
	}


	if(pPCX_INFO->bBitsPerPixel == 8)
	{
		if((pPCX_INFO->wImageWidth) != (pPCX_INFO->wBytesPerLine))
			(*wCountX)++;
	}
	else if(pPCX_INFO->bBitsPerPixel == 4)
	{
		if(wLength_of_buffer < ((pPCX_INFO->wBytesPerLine)<<1))
			(*wCountX)++;
	}
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	Output_Line
//
// Description:	This routine is used to map the decoded data to the palette 
//					and fill the global Screen Buffer. 
//
// Input:	WORD wTop - This variable gives the position from where a 
//						line should start in the Screen Buffer
//					PCX_INFO *pPCX_INFO - Pointer to PCX_INFO structure
//					BYTE *pbOneLineBuffer - Pointer to the buffer that holds one line of decoded data.
//
// Output:	None
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
void Output_Line(DWORD wTop, PCX_INFO *pPCX_INFO, BYTE *pbOneLineBuffer)
{
	WORD wCountX;
	int nIndex;
	AMI_TRUECOLOR_PIXEL * pStartofLineInScreenBuffer = (AMI_TRUECOLOR_PIXEL *)ScreenBuffer + (wTop*(pPCX_INFO->wImageWidth));

		for(wCountX = 0; wCountX< pPCX_INFO->wImageWidth; wCountX++)		
		{
			nIndex = (3 * (int)(pbOneLineBuffer[wCountX]));
			pStartofLineInScreenBuffer->Red = pPCX_INFO->bpPalette[nIndex];
			pStartofLineInScreenBuffer->Green = pPCX_INFO->bpPalette[nIndex + 1];
			pStartofLineInScreenBuffer->Blue = pPCX_INFO->bpPalette[nIndex + 2];
			pStartofLineInScreenBuffer++;
		}


}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	DecodePCX
//
// Description:	This routine will call functions to decode both 16 and 256 
//					color PCX images of version 5 (with palette information) and 
//					fill the Screen Buffer.
//
// Input:	BYTE * pbyPCXInputData - Pointer that gives the memory location 
//						where the PCX input data is available.
//					BYTE * pbyPCXOutputData - Pointer to the buffer that will 
//						receive the decoded PCX image
//					DWORD dwPCXImageSize - Size of the PCX Image
//
// Output:	BOOL - TRUE/FALSE
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOL DecodePCX(BYTE * pbyPCXInputData, BYTE * pbyPCXOutputData, DWORD dwPCXImageSize)
{
	PCX_INFO pcx_info;
	BYTE  * bOneLineBuffer = NULL;
	DWORD wCountY = 0;
	DWORD wCountX = 0;

	bOneLineBuffer = EfiLibAllocatePool(sizeof(BYTE)*1280);
	if(bOneLineBuffer == NULL)
		return FALSE;

	ScreenBuffer = (AMI_TRUECOLOR_PIXEL *)pbyPCXOutputData;
	if(PCX_Init(pbyPCXInputData, &pcx_info, dwPCXImageSize))
	{
		for(wCountY = 0; wCountY < pcx_info.wImageHeight; wCountY++)
		{
			Decode_Line(&wCountX, &pcx_info, bOneLineBuffer);
			Output_Line(wCountY, &pcx_info, bOneLineBuffer);
		}
		MemFreePointer( (VOID **)&bOneLineBuffer);
		return TRUE;
	}
	else
	{
		MemFreePointer( (VOID **)&bOneLineBuffer);
		return FALSE;
	}
}
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2010, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**     5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093     **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************