⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wexjpeg.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/* wexjpeg.c - WindML Jpeg example program */

/* Copyright 2000 Wind River Systems, Inc. All Rights Reserved */

/*
modification history
--------------------
01m,22feb02,msr  Backward compatability for input API.
01l,29jan02,rbp  Addition of support for Native Unix.
01k,05nov01,gav  Fixed misnamed devIds
01j,05nov01,gav  Change to new registry
01i,05nov01,gav  Change to new registry
01h,31oct01,rfm  Open binary files
01g,09oct01,msr  Ported to new UGL_Q_EVENT architecture.
01f,19dec00,gav  Entry point identical to filename w/o extension.
01e,22nov00,gav  Added command line file path argument.
01d,16nov00,msr  Fixed SPR #62051
01c,27oct00,rfm  Added stdio usage
01b,26oct00,rfm  Modified entry point
01a,25oct00,rfm  Added modification history
*/

/**************************************************************
*  WindML Example - Jpeg display and creation
*
* This example program demonstrates how a Jpeg can be displayed
* to the screen and how a jpeg can be created from a bitmap such
* as the screen.
*
* To start the example:
*
* -> ld < wexjpeg_ugl.o
* -> wexjpeg <mode>
*
* This example will display 3 different Jpeg images. After the
* 3rd jpeg has been displayed, a jpeg will be created from the
* 3rd image on the screen.
*
* If the <mode> parameter is positive, no input devices are 
* assumed to be present and the demo will wait <mode> number
* of seconds before proceeding to the next image. A value of
* zero or a negative value assumes that a mouse or keyboard is 
* present.
*
**************************************************************/

#if !defined(WINDML_NATIVE)
#include <vxWorks.h>
#include <sysLib.h>
#endif

/* This is included for a printf prototype. */

#include <stdio.h>

/* Include the UGL header file to use UGL functions, etc.  */
/* The DIB header has defines specific to the use of DIBs. */

#include <ugl/ugl.h>
#include <ugl/uglos.h>
#include <ugl/uglMsg.h>
#include <ugl/uglfont.h>
#include <ugl/uglinput.h>
#include <ugl/ext/jpeg/ugljpeg.h>

/* Copy these files to the ftp home directory for the target and
change the path below. */

#define JPEG_IMG_FILE1 "testimg1.jpg"
#define JPEG_IMG_FILE2 "testimg2.jpg"
#define JPEG_IMG_FILE3 "testimg3.jpg"

/* This file will be created on the host. */

#define JPEG_IMG_FILE4 "testimg4.jpg"

/* A forward declaration for this program. */

UGL_LOCAL void windMLExampleJpeg (int mode, char *path);

/* Global variables */

/* Control variable to signal when to stop program */

volatile UGL_BOOL stopWex = 0;

/* Some graphics environment information */

UGL_LOCAL int displayHeight, displayWidth;
UGL_LOCAL UGL_GC_ID gc;

/* Some input related varibles for the pause routine */

UGL_LOCAL UGL_INPUT_SERVICE_ID inputServiceId;
UGL_FONT_ID font;

/*
* The color table is where we define the colors we want
* to have available.  The format is an array of
* ARGB values paired with their allocated uglColor.  As
* of this writing, we don't need to worry about Alpha
* ("A") values unless we are using video.
*/

UGL_LOCAL struct _colorStruct
    {
    UGL_ARGB rgbColor;
    UGL_COLOR uglColor;
    }
colorTable[] =
    {
    { UGL_MAKE_ARGB(0xff, 0, 0, 0), 0},    /* The color table uses ARGB's */
    { UGL_MAKE_ARGB(0xff, 0, 0, 168), 0},  /* (see uglColorAlloc).        */
    { UGL_MAKE_ARGB(0xff, 0, 168, 0), 0},  /* Initialize alpha to 255 for */
    { UGL_MAKE_ARGB(0xff, 0, 168, 168), 0},/* now (opaque).               */

    { UGL_MAKE_RGB(168, 0, 0), 0},         /* UGL_MAKE_RGB takes care of  */
    { UGL_MAKE_RGB(168, 0, 168), 0},       /* the alpha for us.           */
    { UGL_MAKE_RGB(168, 84, 0), 0},
    { UGL_MAKE_RGB(168, 168, 168), 0},

    { UGL_MAKE_RGB(84, 84, 84), 0},
    { UGL_MAKE_RGB(84, 84, 255), 0},
    { UGL_MAKE_RGB(84, 255, 84), 0},
    { UGL_MAKE_RGB(84, 255, 255), 0},

    { UGL_MAKE_RGB(255, 84, 84), 0},
    { UGL_MAKE_RGB(255, 84, 255), 0},
    { UGL_MAKE_RGB(255, 255, 84), 0},
    { UGL_MAKE_RGB(255, 255, 255), 0}
    };

#define BLACK			(0)
#define BLUE			(1)
#define GREEN			(2)
#define CYAN			(3)
#define RED		    	(4)
#define MAGENTA			(5)
#define BROWN			(6)
#define LIGHTGRAY		(7)
#define DARKGRAY		(8)
#define LIGHTBLUE		(9)
#define LIGHTGREEN		(10)
#define LIGHTCYAN		(11)
#define LIGHTRED		(12)
#define LIGHTMAGENTA		(13)
#define YELLOW			(14)
#define WHITE			(15)

/* Use this to make sure the frame buffer is clear */

UGL_LOCAL void ClearScreen(UGL_GC_ID gc)
    {
    uglBackgroundColorSet(gc, colorTable [BLACK].uglColor);
    uglForegroundColorSet(gc, colorTable [BLACK].uglColor);
    uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID);
    uglLineWidthSet(gc, 1);
    uglRectangle(gc, 0, 0, displayWidth - 1, displayHeight - 1);
    }

void flushQ(void)
    {
    UGL_MSG msg;
    UGL_STATUS status;

    do
        {
        status = uglInputMsgGet (inputServiceId, &msg, UGL_NO_WAIT);
        } while (status != UGL_STATUS_Q_EMPTY);
    }

/* Intermediate pause function. Wait for a key press to continue */

UGL_LOCAL void pause(int mode)
    {
    static UGL_CHAR * message = "Press any key or mouse button to continue.";
    int textWidth, textHeight;
    UGL_MSG msg;
    UGL_STATUS status;

    if (mode <= 0)
	{
	uglBackgroundColorSet(gc, colorTable[BLACK].uglColor);
	uglForegroundColorSet(gc, colorTable[LIGHTGREEN].uglColor);

	uglTextSizeGet(font, &textWidth, &textHeight, 
		       -1, message);

	uglTextDraw(gc, (displayWidth - textWidth) / 2, 
			(displayHeight - textHeight) / 2, -1, message);

	flushQ();

	UGL_FOREVER
	    {
	    status = uglInputMsgGet (inputServiceId, &msg, UGL_WAIT_FOREVER);

	    if (status != UGL_STATUS_Q_EMPTY)
		{
                if ((msg.type == MSG_KEYBOARD && 
                     (msg.data.keyboard.modifiers & UGL_KBD_KEYDOWN)) ||
                    (msg.type == MSG_POINTER &&
                     (msg.data.pointer.buttonChange &
                      msg.data.pointer.buttonState)))
		    break;
		}
	    }
	}
    else
	{
#if !defined(WINDML_NATIVE)
	uglOSTaskDelay(sysClkRateGet() * mode);
#endif
	}
    }

/*
* Start the example program.  This function and the bitmapStop function
* can be invoked from the host shell in order to control the program.
*/

#if defined(WINDML_NATIVE) && defined(__unix__)
int main (int argc, char *argv [])
    {
    windMLExampleJpeg (0, ".");
    return 0;
    }
#elif defined(WINDML_NATIVE) && defined(_WIN32)
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nShowCmd)
    {
    uglWin32Parameters(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
    windMLExampleJpeg(0, ".");
    return (0);
    }
#else
void wexjpeg (int mode, char *path)
    {
    printf("See the target screen for instructions on this example.\n");
    uglOSTaskCreate("tWindMLJpeg", (UGL_FPTR)windMLExampleJpeg, 110, 
		    UGL_FP_TASK, 10240, mode,0,0,0,0);
    }
#endif

/* The main function */

UGL_LOCAL void windMLExampleJpeg (int mode, char *path)
    {
    UGL_SIZE jpegWidth, jpegHeight;
    UGL_DDB_ID jpegDdbId = UGL_NULL;
    UGL_JPEG_MODE jpegMode;
    UGL_JPEG_ID jpegId = UGL_NULL;
    UGL_FONT_DRIVER_ID fontDrvId;
    UGL_FONT_DEF fontDef;
    char errorMessage[150],filename[150];
    int textWidth, textHeight;
    FILE * fp;
    int jpegVersion;

    /* 
    * This structure is filled in with data about the frame buffer
    * by the uglInfo() function.
    */
    
    UGL_MODE_INFO modeInfo;

    /*
    * The device ID is critical to the operation of UGL.  It
    * identifies individual "devices" (display adapter, keyboard,
    * font engine, etc.) to functions that may be able to work
    * with more than one device.
    */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -