Attachment 'stest1.c'

Download

   1 // stest1.c  - test slides for screen size and aspect ratio
   2 // 
   3 // gcc -o stest1 stest1.c -lm -lgd ; ./stest1
   4 
   5 #define NAME     "stest"
   6 #define NFRAMES  9
   7 #define FNT      "DejaVuMonoSans"
   8 #define FRWIDE   15
   9 #define F90      1.570796327
  10 
  11 #include <gd.h>
  12 #include <math.h>
  13 #include <string.h>
  14 #include <stdlib.h>
  15 
  16 
  17 //-----------------------------------
  18 int main() {
  19     
  20    char       txt[80]              ;
  21    FILE       *pngout;             ; // output file
  22    gdImagePtr im                   ; // working image
  23    gdPoint    pt                   ;
  24    gdPoint    poly[10]             ;
  25    int        white, black, gray   ;
  26    int        i                    ;
  27    int        frame                ;
  28    int        nest                 ;
  29    int        xsize, ysize         ;
  30    int        xcent, ycent         ;
  31    int        xcenm, ycenm         ;
  32    int        xnest, ynest         ;
  33    int        x ,  y               ;
  34    int        x0,  y0              ;
  35    int        x1,  y1              ;
  36    int        xf,  yf              ;
  37    int        brect[8]             ;
  38 
  39    // sizes -----------------------
  40    int   axsize[NFRAMES], aysize[NFRAMES];
  41 
  42          axsize[0]=  512; aysize[0]=  384;
  43          axsize[1]=  800; aysize[1]=  600;
  44          axsize[2]=  880; aysize[2]=  660;
  45          axsize[3]= 1024; aysize[3]=  768;
  46          axsize[4]= 1280; aysize[4]=  960;
  47          axsize[5]= 1400; aysize[5]= 1050;
  48          axsize[6]= 1600; aysize[6]= 1200;
  49          axsize[7]= 1920; aysize[7]= 1440;
  50          axsize[8]= 2048; aysize[8]= 1536;
  51    
  52    for( frame=0 ; frame < NFRAMES ; frame++ ) {
  53       xsize = axsize[frame];
  54       ysize = aysize[frame];
  55       xcent = xsize/2 ;
  56       ycent = ysize/2 ;
  57       xcenm = xcent-1 ;
  58       ycenm = ycent-1 ;
  59 
  60       im     = gdImageCreateTrueColor(xsize, ysize);
  61 
  62       white   = gdImageColorAllocate (im, 255, 255, 255);
  63       black   = gdImageColorAllocate (im,   0,   0,   0);
  64    
  65       // moire grid ---------------------------------------------
  66       for( y=0 ; y < ysize ; y +=2 ) {
  67          for( x = 0 ; x < xsize ; x +=2 ) {
  68             gdImageSetPixel( im, x  , y  , white ) ;
  69             gdImageSetPixel( im, x+1, y  , black ) ;
  70             gdImageSetPixel( im, x  , y+1, black ) ;
  71             gdImageSetPixel( im, x+1, y+1, white ) ;
  72       }  }
  73       // gray scale ----------------------------------------------
  74       for( i=0 ; i<256 ; i++ ) {
  75          gray = gdImageColorAllocate (im, i, i, i);
  76          x = xcent+i-128;
  77          gdImageLine( im, x, ycent+20, x, ycent+140, gray );
  78       }
  79       // label ---------------------------------------------------
  80       sprintf( txt, "%4dx%4d", xsize, ysize );
  81 
  82       // scale it
  83       gdImageStringFT(NULL, &brect[0],     0, FNT, 40, 0.0, 0, 0, txt );
  84 
  85       x = xcent-(brect[0]+brect[2])/2 ;
  86       y = ycent-(brect[1]+brect[3])/2 ;
  87       
  88       // print it above centerline 
  89       gdImageStringFT( im,  &brect[0], black, FNT, 40, 0.0, x, y, txt );
  90 
  91       // nested boxes with sizes and arrows ----------------------
  92 
  93       for( nest = frame ; nest >=0 ; nest-- ) {
  94          xnest = axsize[nest]/2;
  95          ynest = aysize[nest]/2;
  96 
  97          // label ---------------------------------------------------
  98          sprintf( txt, " %4dx%4d  ", xnest*2, ynest*2 );
  99 
 100          // left border  UL LR
 101          gdImageFilledRectangle( im, xcent-xnest,        ycent-ynest,
 102                                      xcent+FRWIDE-xnest, ycenm+ynest, white );
 103          
 104          // left arrow
 105          poly[0].x=xcent-xnest        ; poly[0].y=ycent        ;
 106          poly[1].x=xcent+FRWIDE-xnest ; poly[1].y=ycent+FRWIDE ;
 107 	 poly[2].x=xcent+FRWIDE-xnest ; poly[2].y=ycent-FRWIDE ;
 108 	 gdImageFilledPolygon ( im, poly, 3, black );
 109 
 110          // right
 111          gdImageFilledRectangle( im, xcenm+xnest-FRWIDE, ycent-ynest,
 112                                      xcenm+xnest       , ycenm+ynest, white );
 113          // right arrow
 114          poly[0].x=xcenm+xnest        ; poly[0].y=ycent        ;
 115          poly[1].x=xcenm+xnest-FRWIDE ; poly[1].y=ycent+FRWIDE ;
 116          poly[2].x=xcenm+xnest-FRWIDE ; poly[2].y=ycent-FRWIDE ;
 117          gdImageFilledPolygon ( im, poly, 3, black );
 118 
 119          // top
 120          gdImageFilledRectangle( im, xcent-xnest, ycent-ynest,
 121                                      xcenm+xnest, ycent+FRWIDE-ynest, white );
 122          // top arrow
 123          poly[0].x=xcent        ; poly[0].y=ycent-ynest  ;
 124          poly[1].x=xcent+FRWIDE ; poly[1].y=ycent+FRWIDE-ynest ;
 125          poly[2].x=xcent-FRWIDE ; poly[2].y=ycent+FRWIDE-ynest ;
 126          gdImageFilledPolygon ( im, poly, 3, black );
 127 
 128          // top labels
 129          gdImageStringFT(NULL, &brect[0], 0, FNT, 14, 0.0, 0, 0, txt );
 130          gdImageStringFT( im,  &brect[0], black, FNT, 14, 0.0,
 131              xcent-xnest-brect[6], ycent-ynest-brect[7], txt );
 132          gdImageStringFT(NULL, &brect[0], 0, FNT, 14, 0.0, 0, 0, txt );
 133          gdImageStringFT( im,  &brect[0], black, FNT, 14, 0.0,
 134              xcenm+xnest-brect[4], ycent-ynest-brect[7], txt );
 135 
 136          // bottom
 137          gdImageFilledRectangle( im, xcent-xnest, ycenm+ynest-FRWIDE,
 138                                      xcenm+xnest, ycenm+ynest, white );
 139          // bottom arrow
 140          poly[0].x=xcent        ; poly[0].y=ycenm+ynest  ;
 141          poly[1].x=xcent+FRWIDE ; poly[1].y=ycenm+ynest-FRWIDE ;
 142          poly[2].x=xcent-FRWIDE ; poly[2].y=ycenm+ynest-FRWIDE ;
 143          gdImageFilledPolygon ( im, poly, 3, black );
 144 
 145          // bottom labels
 146          gdImageStringFT(NULL, &brect[0], 0, FNT, 14, 0.0, 0, 0, txt );
 147          gdImageStringFT( im,  &brect[0], black, FNT, 14, 0.0,
 148              xcent-xnest-brect[6], ycenm+ynest-brect[1], txt );
 149          gdImageStringFT(NULL, &brect[0], 0, FNT, 14, 0.0, 0, 0, txt );
 150          gdImageStringFT( im,  &brect[0], black, FNT, 14, 0.0,
 151              xcenm+xnest-brect[4], ycenm+ynest-brect[1], txt );
 152 
 153       }
 154 
 155       sprintf( txt, "%s%04d.png", NAME, xsize );
 156       pngout = fopen( txt, "wb");
 157       gdImagePngEx( im, pngout, 1 );
 158       gdImageDestroy(im);
 159       fclose(pngout);
 160    }
 161    return 0 ;
 162 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-08-08 00:43:59, 0.9 KB) [[attachment:design]]
  • [get | view] (2009-08-02 01:53:08, 5.9 KB) [[attachment:stest1.c]]
  • [get | view] (2009-07-17 17:03:08, 0.2 KB) [[attachment:style.css]]
  • [get | view] (2009-08-08 00:44:25, 1.4 KB) [[attachment:template.html]]
  • [get | view] (2009-07-17 17:02:06, 37.8 KB) [[attachment:wydiwys]]
  • [get | view] (2009-08-08 00:44:41, 2.5 KB) [[attachment:wydiwys.js]]
  • [get | view] (2009-08-08 00:46:42, 4053.8 KB) [[attachment:wydiwys_demo.tar.gz]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.