home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / Freeware / ttengine-5.0 / Examples / Postprocess / postprocess.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-03  |  5.9 KB  |  151 lines

  1. /* test ttrender */
  2.  
  3. #define __NOLIBBASE__
  4.  
  5. #include <proto/dos.h>
  6. #include <proto/exec.h>
  7. #include <proto/intuition.h>
  8. #include <proto/graphics.h>
  9. #include <proto/ttengine.h>
  10. #include <proto/asl.h>
  11. #include <proto/cybergraphics.h>
  12.  
  13. #include <libraries/ttengine.h>
  14.  
  15. extern struct Library *SysBase, *DOSBase;
  16.  
  17. struct Library *TTEngineBase, *IntuitionBase, *GfxBase, *AslBase, *CyberGfxBase;
  18.  
  19. /*----------------------------------------------------------------------------------------------------*/
  20.  
  21. static STRPTR get_font_name(struct Library *AslBase)
  22.   {
  23.     struct FileRequester *freq;
  24.     STRPTR name = NULL;
  25.  
  26.     if (freq = AllocAslRequestTags(ASL_FileRequest, TAG_END))
  27.       {
  28.         if (AslRequestTags(freq,
  29.           ASLFR_TitleText, (ULONG)"Select TrueType font",
  30.           ASLFR_InitialDrawer, (ULONG)"FONTS:",
  31.           ASLFR_DoPatterns, TRUE,
  32.           ASLFR_InitialPattern, (ULONG)"#?.ttf",
  33.           ASLFR_RejectIcons, TRUE,
  34.           TAG_END))
  35.           {
  36.             ULONG namelen = strlen(freq->fr_File) + strlen(freq->fr_Drawer) + 4;
  37.  
  38.             if (name = AllocVec(namelen + 1, MEMF_ANY | MEMF_CLEAR))
  39.               {
  40.                 strncpy(name, freq->fr_Drawer, namelen);
  41.                 AddPart(name, freq->fr_File, namelen);
  42.               }
  43.           }
  44.         FreeAslRequest(freq);
  45.       }
  46.     return name;
  47.   }
  48.  
  49. /*----------------------------------------------------------------------------------------------------*/
  50.  
  51. static VOID free_font_name(STRPTR name)
  52.   {
  53.     if (name) FreeVec(name);
  54.   }
  55.  
  56. /*----------------------------------------------------------------------------------------------------*/
  57.  
  58. int Main (void)
  59.   {
  60.     struct Window *win;
  61.     STRPTR fontname;
  62.     APTR font;
  63.  
  64.     if (GfxBase = OpenLibrary("graphics.library", 39))
  65.       {
  66.         if (IntuitionBase = OpenLibrary("intuition.library", 39))
  67.           {
  68.             if (AslBase = OpenLibrary("asl.library", 38))
  69.               {
  70.                 if (fontname = get_font_name(AslBase))
  71.                   {
  72.                     if (TTEngineBase = OpenLibrary("ttengine.library", 4))
  73.                       {
  74.                         if (font = TT_OpenFont(
  75.                           TT_FontFile, (ULONG)fontname,
  76.                           TT_FontSize, 20,
  77.                         TAG_END))
  78.                           {
  79.                             struct TT_Pixmap *px;
  80.  
  81.                             if (px = TT_GetPixmap(font, "Postprocessed pixmap", 20,
  82.                               TT_Antialias, TT_Antialias_On,
  83.                             TAG_END))
  84.                               {
  85.                                 Printf("Pixmap $%08lx, %ld x %ld\n", (ULONG)px, px->ttp_Width, px->ttp_Height);
  86.                                 if (win = OpenWindowTags(NULL,
  87.                                   WA_Top, 25,
  88.                                   WA_Left, 0,
  89.                                   WA_InnerWidth, px->ttp_Width * 3,
  90.                                   WA_InnerHeight, px->ttp_Height * 3,
  91.                                   WA_CloseGadget, TRUE,
  92.                                   WA_DragBar, TRUE,
  93.                                   WA_DepthGadget, TRUE,
  94.                                   WA_IDCMP, IDCMP_CLOSEWINDOW,
  95.                                   WA_Title, (ULONG)"Postprocessing demo",
  96.                                 TAG_END))
  97.                                   {
  98.                                     ULONG signals, sigmask;
  99.                                     BOOL running = TRUE;
  100.                                     WORD xi, yi;
  101.  
  102.                                     /* rendering processed pixelmap, it will be magnified */
  103.                                     /* with factor 3 */
  104.  
  105.                                     if (CyberGfxBase = OpenLibrary("cybergraphics.library", 41))
  106.                                       {
  107.                                         for (xi = 0; xi < px->ttp_Width; xi++)
  108.                                           {
  109.                                             for (yi = 0; yi < px->ttp_Height; yi++)
  110.                                               FillPixelArray(win->RPort, win->BorderLeft + xi * 3, win->BorderTop + yi * 3, 3, 3,
  111.                                                px->ttp_Data[xi + yi * px->ttp_Width] * 0x00010101);
  112.                                           }
  113.                                         CloseLibrary(CyberGfxBase);
  114.                                       }
  115.                                     else PutStr("Program requires CyberGraphX or Picasso96\n");
  116.  
  117.                                     sigmask = SIGBREAKF_CTRL_C | (1 << win->UserPort->mp_SigBit);
  118.                                     while (running)
  119.                                       {
  120.                                         signals = Wait(sigmask);
  121.                                         if (signals & SIGBREAKF_CTRL_C) running = FALSE;
  122.                                         if (signals & (1 << win->UserPort->mp_SigBit))
  123.                                           {
  124.                                             struct IntuiMessage *imsg;
  125.  
  126.                                             while (imsg = (struct IntuiMessage*)GetMsg(win->UserPort))
  127.                                               {
  128.                                                 if (imsg->Class == IDCMP_CLOSEWINDOW) running = FALSE;
  129.                                                 ReplyMsg((struct Message*)imsg);
  130.                                               }
  131.                                           }
  132.                                       }
  133.                                     CloseWindow(win);
  134.                                   }
  135.                                 TT_FreePixmap(px);
  136.                               }
  137.                           }
  138.                         else PutStr("Font open failed.\n");
  139.                         CloseLibrary(TTEngineBase);
  140.                       }
  141.                     free_font_name(fontname);
  142.                   }
  143.                 CloseLibrary(AslBase);
  144.               }
  145.             CloseLibrary(IntuitionBase);
  146.           }
  147.         CloseLibrary(GfxBase);
  148.       }
  149.     return 0;
  150.   }
  151.