2
0

writetruecolordata.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. Program WriteTrueColorData;
  2. { ***********************************************************************
  3. * This is an example that shows how to use p96WriteTrueColorData
  4. * Program terminates when space bar or any mouse button is pressed!
  5. *
  6. * alx (Mon Dec 30 12:09:35 1996)
  7. *********************************************************************** }
  8. {
  9. Translated to fpc pascal.
  10. 14 Mars 2001.
  11. Updated for fpc 1.0.7
  12. 08 Jan 2003.
  13. [email protected]
  14. }
  15. uses exec, amigados, intuition, agraphics, picasso96api, utility,systemvartags;
  16. Const
  17. DataWidth = 160;
  18. DataHeight = 160;
  19. template : PChar = 'Width=W/N,Height=H/N,Depth=D/N';
  20. vecarray : Array[0..2] of long = (0,0,0);
  21. ltrue : longint = 1;
  22. Var
  23. rda : pRDArgs;
  24. { p96WriteTrueColorData only works on True- and HiColorModes }
  25. Const
  26. HiColorFormats = (RGBFF_R5G6B5 or RGBFF_R5G5B5 or RGBFF_R5G6B5PC or RGBFF_R5G5B5PC or RGBFF_B5G6R5PC or RGBFF_B5G5R5PC);
  27. TrueColorFormats = (RGBFF_R8G8B8 or RGBFF_B8G8R8);
  28. TrueAlphaFormats = (RGBFF_R8G8B8A8 or RGBFF_B8G8R8A8 or RGBFF_A8R8G8B8 or RGBFF_A8B8G8R8);
  29. UsefulFormats = (HiColorFormats or TrueColorFormats or TrueAlphaFormats);
  30. Pens : Array [0..0] Of integer = (NOT(0));
  31. Var
  32. sc : pScreen;
  33. win : pWindow;
  34. i,
  35. DisplayID : Longint;
  36. width,
  37. height,
  38. depth : Longint;
  39. quit : Boolean;
  40. reddata,
  41. greendata,
  42. bluedata : Pointer;
  43. tci : tTrueColorInfo;
  44. fh : FileHandle;
  45. imsg : pIntuiMessage;
  46. procedure CleanUp(why : string);
  47. begin
  48. if assigned(win) then CloseWindow(win);
  49. if assigned(sc) then p96CloseScreen(sc);
  50. if why <> '' then writeln(why);
  51. end;
  52. Begin
  53. width:=640;
  54. height:=480;
  55. depth:=24;
  56. rda:=ReadArgs (template,@vecarray,Nil);
  57. If rda<>Nil Then
  58. Begin
  59. If vecarray[0]<>0 then width := long(@vecarray[0]);
  60. If vecarray[1]<>0 then height := long(@vecarray[1]);
  61. If vecarray[2]<>0 then depth := long(@vecarray[2]);
  62. FreeArgs(rda);
  63. End;
  64. DisplayID := p96BestModeIDTags([P96BIDTAG_NominalWidth, width,
  65. P96BIDTAG_NominalHeight, height,
  66. P96BIDTAG_Depth, depth,
  67. P96BIDTAG_FormatsAllowed, UsefulFormats,
  68. TAG_DONE]);
  69. sc := p96OpenScreenTags([P96SA_DisplayID, DisplayID,
  70. P96SA_Width, width,
  71. P96SA_Height, height,
  72. P96SA_Depth, depth,
  73. P96SA_AutoScroll, lTRUE,
  74. P96SA_Pens, @Pens,
  75. P96SA_Title, 'WriteTrueColorData Test',
  76. TAG_DONE]);
  77. if sc = nil then CleanUp('Can''t open screen');
  78. win := OpenWindowTags(Nil,[WA_CustomScreen, sc,
  79. WA_Backdrop, lTRUE,
  80. WA_Borderless, lTRUE,
  81. WA_SimpleRefresh, lTRUE,
  82. WA_RMBTrap, lTRUE,
  83. WA_Activate, lTRUE,
  84. WA_IDCMP, IDCMP_RAWKEY or IDCMP_MOUSEBUTTONS,
  85. TAG_END]);
  86. if win = nil then CleanUp('Can''t open window');
  87. quit:=False;
  88. reddata:=AllocVec(DataWidth*DataHeight, MEMF_ANY);
  89. greendata:=AllocVec(DataWidth*DataHeight, MEMF_ANY);
  90. bluedata:=AllocVec(DataWidth*DataHeight, MEMF_ANY);
  91. If (reddata<>Nil) And (greendata<>Nil) And (bluedata<>Nil) Then Begin
  92. tci.PixelDistance:=1;
  93. tci.BytesPerRow:=DataWidth;
  94. tci.RedData:=reddata;
  95. tci.GreenData:=greendata;
  96. tci.BlueData:=bluedata;
  97. fh:=DOSOpen ('Symbol.red',MODE_OLDFILE);
  98. If fh = 0 Then Begin
  99. i:=DOSRead(fh, reddata, DataWidth*DataHeight);
  100. DOSClose(fh);
  101. End;
  102. fh:=DOSOpen ('Symbol.green',MODE_OLDFILE);
  103. If fh = 0 Then Begin
  104. i:=DOSRead(fh, greendata, DataWidth*DataHeight);
  105. DOSClose(fh);
  106. End;
  107. fh:=DOSOpen ('Symbol.blue',MODE_OLDFILE);
  108. If fh = 0 Then Begin
  109. i:=DOSRead(fh, bluedata, DataWidth*DataHeight);
  110. DOSClose(fh);
  111. End;
  112. { paint something on the screen }
  113. p96WriteTrueColorData(@tci,0,0,win^.RPort,50,50,DataWidth,DataHeight);
  114. End;
  115. FreeVec(reddata);
  116. FreeVec(greendata);
  117. FreeVec(bluedata);
  118. { wait for input }
  119. While Not(quit) Do Begin
  120. WaitPort(win^.UserPort);
  121. imsg:=pIntuiMessage(GetMsg (win^.UserPort));
  122. While(imsg<>Nil) Do Begin
  123. If ((imsg^.IClass=IDCMP_MOUSEBUTTONS) or ((imsg^.IClass=IDCMP_RAWKEY) And (imsg^.Code=$40))) Then Begin
  124. { press MOUSEBUTTONS or SPACE bar to end program }
  125. quit:=True;
  126. End;
  127. ReplyMsg(pMessage(imsg));
  128. imsg:=pIntuiMessage(GetMsg (win^.UserPort));
  129. End;
  130. End;
  131. CleanUp('');
  132. End.