home *** CD-ROM | disk | FTP | other *** search
/ Computer Panoráma / computer_panorama_1997-12-hibas.iso / SHARE / GRAPH / PTC051.ZIP / EXAMPLES / IMAGE.TXT < prev    next >
Text File  |  1997-09-23  |  2KB  |  68 lines

  1.                           ========================
  2.                           = image loader example =
  3.                           ========================
  4.  
  5.  
  6. Overview
  7. --------
  8.  
  9. This example program demonstrates how to load image files to surfaces for use
  10. in PTC and how to convert the loaded images to the pixel format required.
  11.  
  12.  
  13.  
  14.  
  15. Loading the image
  16. -----------------
  17.  
  18. >    // load image
  19. >    Surface surface(ptc,"image.tga");
  20. >    if (!surface.ok())
  21. >    {
  22. >        ptc.Close();
  23. >        cout << "could not load image\n";
  24. >        return 1;
  25. >    }
  26.  
  27. This code creates a surface to load the targa image file "image.tga". Note
  28. that you can also use Surface::Load to load an image to a surface after
  29. creation like so:
  30.  
  31.     Surface surface;
  32.     .....
  33.     surface.Load(ptc,"image.tga");
  34.  
  35. Finally, note that when the PTC object is passed to the load function or load
  36. constructor, the surface will be bound to that PTC object. If you wish to load
  37. an image to an unbound surface, then do not pass the PTC object. For example:
  38.  
  39.     Surface surface;
  40.     .....
  41.     surface.Load("image.tga"); 
  42.  
  43.  
  44.  
  45.  
  46.  
  47. Converting the surface
  48. ----------------------
  49.  
  50. >    // convert image
  51. >    if (!surface.Convert(ARGB8888))
  52. >    {
  53. >        // failure
  54. >        ptc.Close();
  55. >        cout << "could not convert image\n";
  56. >        return 1;
  57. >    }
  58.  
  59. The code above converts the surface pixel format from *whatever* format it is, 
  60. to ARGB8888 format (32bits per pixel). This is done because an image is loaded
  61. in whatever format it exists on disk. If you load a 16bit targa image then
  62. after loading the surface will have that same 16bit pixel format. In this
  63. example, the file "image.tga" is a 24bit targa file. Because PTC doesnt
  64. support fast pixel format conversion from 24bit -> X (instead it uses a slower
  65. general converter routine for all "unsupported" pixel format conversions), it
  66. is best to convert the image to another better supported pixel format such as
  67. RGB565 or ARGB8888.
  68.