# image

Overview

This example demonstrates how to load an image with PTC. It loads an image file to a surface, converts the surface to ARGB8888 pixel format and updates the surface to the display.

Description

Initialization
The program starts by initializing PTC. Firstly it tries a command line initialize so that the user can pass mode parameters on the command line like this: "image format". For example "image RGB565" would run the image program in a 320x200xRGB565 display mode. Note that the programmer only allows the pixel format to be set by the user, and has fixed the resolution at 320x200. If the command line initialize fails, then the program falls back onto a 320x200 virtual 32 bit display mode.

Loading the image
A surface is created that loads the targa image file "image.tga". Note that you can also load an image to a surface any time you wish like this: "surface.Load("image.tga")". After the image is loaded it isn't quite ready to be used however, first it is converted to ARGB8888 pixel format. This is done because PTC only supports fast conversions from INDEX8, RGB565 and ARGB8888, and the image being loaded is a 24 bit targa file, so naturally after it is loaded it the surface has a 24 bit pixel format.

Source code

`///////////////////////////`
`// image loading example //`
`///////////////////////////`
`#include "ptc.h"`

`int main(int argc,char *argv[])`
`{`
`// initialize from command line (ie. "image RGB565")`
`PTC ptc(320,200,argc,argv);`
`if (!ptc.ok())`
`{`
`// fallback to virtual 32bit`
`if (!ptc.Init(320,200))`
`{`
`// failure`
`ptc.Error("could not initialize ptc");`
`return 1;`
`}`
`}`
``
`// load image`
`Surface surface(ptc,"image.tga");`
`if (!surface.ok())`
`{
// failure`
`ptc.Error("could not load image");`
`return 1;`
`}`

`// convert image`
`if (!surface.Convert(ARGB8888))`
`{`
`// failure`
`ptc.Error("could not convert image");`
`return 1;`
`}`

`// display image`
`surface.Update();`
`ptc.getch();`
`return 0;`
`}`