1 /**********************************************************************
3 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful but, except
10 * as otherwise stated in writing, without any warranty; without even the
11 * implied warranty of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
25 ******************************************************************************/
27 #include "bufferclass_example.h"
29 #define MIN(a,b) ((a)<(b)?(a):(b))
31 void FillYUV420Image(void *pvDest, int width, int height, int bytestride)
33 static int iPhase = 0;
35 unsigned char u, v, y;
36 unsigned char *pui8y = (unsigned char *)pvDest;
37 unsigned short *pui16uv;
38 unsigned int count = 0;
40 for (j = 0; j < height; j++) {
41 for (i = 0; i < width; i++) {
42 y = (((i + iPhase) >> 6) % (2) == 0) ? 0x7f : 0x00;
49 (unsigned short *)((unsigned char *)pvDest + (width * height));
52 for (j = 0; j < height; j += 2) {
53 for (i = 0; i < width; i += 2) {
57 2)) ? 0xFF : 0x33) : ((i <
65 2)) ? 0xAC : 0x0) : ((i <
71 pui16uv[count++] = (v << 8) | u;
79 void FillYUV422Image(void *pvDest, int width, int height, int bytestride)
81 static int iPhase = 0;
83 unsigned char u, v, y0, y1;
84 unsigned int *pui32yuv = (unsigned int *)pvDest;
85 unsigned int count = 0;
87 for (y = 0; y < height; y++) {
88 for (x = 0; x < width; x += 2) {
92 2)) ? 0xFF : 0x33) : ((x <
100 2)) ? 0xAA : 0x0) : ((x <
107 (((x + iPhase) >> 6) % (2) == 0) ? 0x7f : 0x00;
110 (y1 << 24) | (v << 16) | (y0 << 8) | u;
118 void FillRGB565Image(void *pvDest, int width, int height, int bytestride)
121 unsigned long *pui32Addr = (unsigned long *)pvDest;
122 unsigned short *pui16Addr = (unsigned short *)pvDest;
123 unsigned long Colour32;
124 unsigned short Colour16;
125 static unsigned char Colour8 = 0;
128 (Colour8 >> 3) | ((Colour8 >> 2) << 5) | ((Colour8 >> 3) << 11);
129 Colour32 = Colour16 | Colour16 << 16;
131 Count = (height * bytestride) >> 2;
133 for (i = 0; i < Count; i++) {
134 pui32Addr[i] = Colour32;
139 pui16Addr = (unsigned short *)((unsigned char *)pvDest + (2 * Colour8));
141 for (i = 0; i < Count; i++) {
145 (unsigned short *)((unsigned char *)pui16Addr + bytestride);
147 Count = bytestride >> 2;
150 (unsigned long *)((unsigned char *)pvDest +
151 (bytestride * (MIN(height - 1, 0xFF) - Colour8)));
153 for (i = 0; i < Count; i++) {
154 pui32Addr[i] = 0x001F001F;
157 Colour8 = (Colour8 + 1) % MIN(height - 1, 0xFF);
160 int FillBuffer(unsigned int ui32BufferIndex)
162 BC_EXAMPLE_DEVINFO *psDevInfo = GetAnchorPtr();
163 BC_EXAMPLE_BUFFER *psBuffer;
164 BUFFER_INFO *psBufferInfo;
165 PVRSRV_SYNC_DATA *psSyncData;
167 if (psDevInfo == IMG_NULL) {
171 psBuffer = &psDevInfo->psSystemBuffer[ui32BufferIndex];
172 psBufferInfo = &psDevInfo->sBufferInfo;
174 psSyncData = psBuffer->psSyncData;
178 if (psSyncData->ui32ReadOpsPending !=
179 psSyncData->ui32ReadOpsComplete) {
183 psSyncData->ui32WriteOpsPending++;
186 switch (psBufferInfo->pixelformat) {
187 case PVRSRV_PIXEL_FORMAT_RGB565:
190 FillRGB565Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
191 BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
194 case PVRSRV_PIXEL_FORMAT_FOURCC_ORG_UYVY:
196 FillYUV422Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
197 BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
200 case PVRSRV_PIXEL_FORMAT_NV12:
202 FillYUV420Image(psBuffer->sCPUVAddr, BC_EXAMPLE_WIDTH,
203 BC_EXAMPLE_HEIGHT, BC_EXAMPLE_STRIDE);
209 psSyncData->ui32WriteOpsComplete++;
215 int GetBufferCount(unsigned int *pui32BufferCount)
217 BC_EXAMPLE_DEVINFO *psDevInfo = GetAnchorPtr();
219 if (psDevInfo == IMG_NULL) {
223 *pui32BufferCount = psDevInfo->sBufferInfo.ui32BufferCount;