📄 testpattern.c
字号:
//===========================================================================
// TestPattern.c
//---------------------------------------------------------------------------
//
// Copyright (c) 2002 Epson Research and Development, Inc.
// All Rights Reserved.
//
//===========================================================================
#include <stdio.h>
#include "halapi.h"
#include "graphics.h"
#include "graphlib.h"
//----------------------------------------------------------------------------
// Keep three digits of precision (1000)
#define PRECISION 1000L
enum
{
RED = 0,
GREEN,
BLUE,
GRAY
};
//----------------------------------------------------------------------------
static void _AdvanceRed8_RGB332( UInt8* pColor, int advance );
static void _AdvanceGreen8_RGB332( UInt8* pColor, int advance );
static void _AdvanceBlue8_RGB332( UInt8* pColor );
static void _AdvanceRed16( UInt16* pColor );
static void _AdvanceGreen16( UInt16* pColor, int advance );
static void _AdvanceBlue16( UInt16* pColor );
//----------------------------------------------------------------------------
//
// gfxDrawTestPattern - Display test pattern image in VRAM if chip is initialized.
//
//----------------------------------------------------------------------------
void gfxDrawTestPattern( UInt32 width, UInt32 height, TestPatternModeDef TestPatternMode )
{
#define WHITE8 0xff
#define WHITE16 0xffff
#define WHITE32 0x00ffffff
UInt32 colorpanel;
UInt32 xMax, yMax;
UInt32 xTickLeft, xTickRight, yTickHeight; // mark top middle with tick mark for upright position
UInt32 x, y, xStep, yStep, xStep32, xStep64, xStep256;
UInt32 xStepRed, xStepGreen, xStepBlue, xStepGray;
UInt32 LineAddr;
UInt8 color8, LastColor8;
UInt16 color16;
UInt32 color32;
UInt32 DisplayAddr;
int CurrentColor;
UInt8 red, green, blue;
UInt32 xNext, xNextInt;
UInt32 yNext, yNextInt;
colorpanel = 1;
color8 = LastColor8 = 0;
color16 = 0;
color32 = 0;
yTickHeight = 10;
// Get the starting video memory address and add in the DWORD residual offset, if required.
LineAddr = gGraphAddr;
xMax = width - 1;
yMax = height - 1;
xTickLeft = (width / 2) - 10;
xTickRight = xTickLeft + 19;
switch (gGraphBpp)
{
default:
case 1:
{
// LUT[0] - LUT[63] is red
// LUT[64] - LUT[64*2-1] is green
// LUT[64*2] - LUT[64*3-1] is blue
// LUT[64*3] - LUT[64*4-1] is gray shades
if ( width>64 )
{
xStepRed = (width*PRECISION) / 64;
xStepGreen = xStepRed;
xStepBlue = xStepRed;
xStepGray = xStepRed;
}
else
xStepRed = xStepGreen = xStepBlue = xStepGray = 1 * PRECISION;
}
yStep = (height*PRECISION) / 4;
yTickHeight = yStep / 2 / PRECISION; // Ensure tick mark doesn't go below red color bar
if ( yTickHeight < 1 )
yTickHeight = 2; // Tick mark must be at least two lines high
// Ensure that steps are not zero
if (xStepRed == 0) xStepRed = 1;
if (xStepGreen == 0) xStepGreen = 1;
if (xStepBlue == 0) xStepBlue = 1;
if (xStepGray == 0) xStepGray = 1;
if (yStep == 0) yStep = 1;
CurrentColor = RED;
xStep = xStepRed;
DisplayAddr = LineAddr;
// Draw top white border
if (gfISVRAM)
{
halWriteDisplay8(DisplayAddr, 0x8f, width/8);
}
else for ( x=0; x<=(xMax/8); x++ )
{
*(UInt8*)DisplayAddr = WHITE8;
DisplayAddr += 1;
}
// The stride may be greater than the physical width, so don't
// rely on just incrementing DisplayAddr to go to the next line.
LineAddr += gGraphStride;
DisplayAddr = LineAddr;
// This loop writes lines 1 to height - 2
yNext = yStep;
yNextInt = yNext / PRECISION;
for ( y=1; y<(yMax/8); y++ )
{
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, WHITE8, 1);
else
*(UInt8*)DisplayAddr = WHITE8; // white left border
DisplayAddr += 1;
if ( y == yNextInt )
{
yNext += yStep;
yNextInt = yNext / PRECISION;
++CurrentColor;
if (TestPatternMode != TESTPATTERN_8BPP_332)
{
if (CurrentColor == GREEN)
{
xStep = xStepGreen;
LastColor8 = 64;
}
else if (CurrentColor == BLUE)
{
xStep = xStepBlue;
LastColor8 = 64*2;
}
else
{
xStep = xStepGray;
LastColor8 = 64*3;
}
}
else
{
if (CurrentColor == GREEN)
xStep = xStepGreen;
else if (CurrentColor == BLUE)
xStep = xStepBlue;
else
xStep = xStepGray;
}
}
color8 = LastColor8;
// This loop writes columns 1 to width - 2
xNext = xStep;
xNextInt = xStep / PRECISION;
for ( x=1; x<(xMax/8); x++ )
{
if ((x >= xNextInt) || (xStep < PRECISION))
{
xNext += xStep;
xNextInt = xNext / PRECISION;
if (TestPatternMode != TESTPATTERN_8BPP_332)
++color8;
else
{
if (CurrentColor==RED)
_AdvanceRed8_RGB332( &color8, 1 );
else if (CurrentColor==BLUE)
_AdvanceBlue8_RGB332( &color8 );
else if (CurrentColor==GRAY)
{
_AdvanceRed8_RGB332( &color8, 2 );
_AdvanceGreen8_RGB332( &color8, 2 );
_AdvanceBlue8_RGB332( &color8 );
}
else
_AdvanceGreen8_RGB332( &color8, 1 );
}
}
if ( (y<yTickHeight) && (x>=xTickLeft) && (x<=xTickRight) )
{
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, (UInt8) ~color8, 1);
else
*(UInt8*)DisplayAddr = (UInt8) ~color8; // tick mark at top of display (inverted color to make mark visible)
}
else
{
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, (UInt8) 0xaa/*color8*/, 1);
else
*(UInt8*)DisplayAddr = color8;
}
DisplayAddr += 1;
}
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, WHITE8, 1);
else
*(UInt8*)DisplayAddr = WHITE8; // white right border
LineAddr += gGraphStride; // convert stride to words
DisplayAddr = LineAddr;
}
// Draw bottom white border
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, WHITE8, xMax+1);
else for ( x=0; x<=(xMax/8); x++ )
{
*(UInt8*)DisplayAddr = WHITE8; // white
DisplayAddr += 1;
}
break;
case 8:
// Draw three color bars and a gray shade bar
// Program LUT if not in bypass mode
if ( TestPatternMode == TESTPATTERN_8BPP_332 )
{
xStepRed = (width*PRECISION) / 8;
xStepGreen = (width*PRECISION) / 8;
xStepBlue = (width*PRECISION) / 4;
xStepGray = (width*PRECISION) / 4;
}
else // Assume standard 256 color LUT
{
// LUT[0] - LUT[63] is red
// LUT[64] - LUT[64*2-1] is green
// LUT[64*2] - LUT[64*3-1] is blue
// LUT[64*3] - LUT[64*4-1] is gray shades
if ( width>64 )
{
xStepRed = (width*PRECISION) / 64;
xStepGreen = xStepRed;
xStepBlue = xStepRed;
xStepGray = xStepRed;
}
else
xStepRed = xStepGreen = xStepBlue = xStepGray = 1 * PRECISION;
}
yStep = (height*PRECISION) / 4;
yTickHeight = yStep / 2 / PRECISION; // Ensure tick mark doesn't go below red color bar
if ( yTickHeight < 1 )
yTickHeight = 2; // Tick mark must be at least two lines high
// Ensure that steps are not zero
if (xStepRed == 0) xStepRed = 1;
if (xStepGreen == 0) xStepGreen = 1;
if (xStepBlue == 0) xStepBlue = 1;
if (xStepGray == 0) xStepGray = 1;
if (yStep == 0) yStep = 1;
CurrentColor = RED;
xStep = xStepRed;
DisplayAddr = LineAddr;
// Draw top white border
if (gfISVRAM)
{
halWriteDisplay8(DisplayAddr, WHITE8, xMax+1);
}
else for ( x=0; x<=xMax; x++ )
{
*(UInt8*)DisplayAddr = WHITE8;
DisplayAddr += 1;
}
// The stride may be greater than the physical width, so don't
// rely on just incrementing DisplayAddr to go to the next line.
LineAddr += gGraphStride;
DisplayAddr = LineAddr;
// This loop writes lines 1 to height - 2
yNext = yStep;
yNextInt = yNext / PRECISION;
for ( y=1; y<yMax; y++ )
{
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, WHITE8, 1);
else
*(UInt8*)DisplayAddr = WHITE8; // white left border
DisplayAddr += 1;
if ( y == yNextInt )
{
yNext += yStep;
yNextInt = yNext / PRECISION;
++CurrentColor;
if (TestPatternMode != TESTPATTERN_8BPP_332)
{
if (CurrentColor == GREEN)
{
xStep = xStepGreen;
LastColor8 = 64;
}
else if (CurrentColor == BLUE)
{
xStep = xStepBlue;
LastColor8 = 64*2;
}
else
{
xStep = xStepGray;
LastColor8 = 64*3;
}
}
else
{
if (CurrentColor == GREEN)
xStep = xStepGreen;
else if (CurrentColor == BLUE)
xStep = xStepBlue;
else
xStep = xStepGray;
}
}
color8 = LastColor8;
// This loop writes columns 1 to width - 2
xNext = xStep;
xNextInt = xStep / PRECISION;
for ( x=1; x<xMax; x++ )
{
if ((x >= xNextInt) || (xStep < PRECISION))
{
xNext += xStep;
xNextInt = xNext / PRECISION;
if (TestPatternMode != TESTPATTERN_8BPP_332)
++color8;
else
{
if (CurrentColor==RED)
_AdvanceRed8_RGB332( &color8, 1 );
else if (CurrentColor==BLUE)
_AdvanceBlue8_RGB332( &color8 );
else if (CurrentColor==GRAY)
{
_AdvanceRed8_RGB332( &color8, 2 );
_AdvanceGreen8_RGB332( &color8, 2 );
_AdvanceBlue8_RGB332( &color8 );
}
else
_AdvanceGreen8_RGB332( &color8, 1 );
}
}
if ( (y<yTickHeight) && (x>=xTickLeft) && (x<=xTickRight) )
{
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, (UInt8) ~color8, 1);
else
*(UInt8*)DisplayAddr = (UInt8) ~color8; // tick mark at top of display (inverted color to make mark visible)
}
else
{
if (gfISVRAM)
halWriteDisplay8(DisplayAddr, (UInt8) color8, 1);
else
*(UInt8*)DisplayAddr = color8;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -