home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / test / trig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  18.3 KB  |  704 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.2 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/test/RCS/trig.c,v 1.2 1992/10/23 19:09:28 koziol beta koziol $
  30.  
  31. $Log: trig.c,v $
  32.  * Revision 1.2  1992/10/23  19:09:28  koziol
  33.  * Updated for new Vset calls, DFvsetopen(), DFvsetclose, and changed
  34.  * VFREESPACE and VGETSPACE to HDfreespace() and HDgetspace()
  35.  *
  36.  * Revision 1.1  1992/10/12  18:48:12  koziol
  37.  * Initial revision
  38.  *
  39.  * Revision 1.2  1992/10/01  03:27:34  chouck
  40.  * Added tests in tp.c into trig.c
  41.  *
  42.  * Revision 1.1  1992/10/01  02:53:23  chouck
  43.  * Initial revision
  44.  *
  45.  * Revision 1.2  1992/09/17  19:54:14  chouck
  46.  * Made arrays smaller to keep Mac from crashing
  47.  *
  48.  * Revision 1.1  1992/02/10  21:11:56  chouck
  49.  * Initial revision
  50.  *
  51. */
  52. #include "hdf.h"
  53.  
  54. #define XSIZE 10
  55. #define YSIZE 10
  56. #define TESTFILE "tdf24.hdf"
  57.  
  58. int num_errs = 0;
  59. int Error;
  60.  
  61. #define RESULT(a) \
  62. {if(ret != 0) {printf("ret from %s is %d\n", a, ret); num_errs++;}}
  63.  
  64.  
  65. /* ------------------------------- test_r24 ------------------------------- */
  66.  
  67. test_r24()
  68. {
  69.     int32 xd, yd;
  70.     int il;
  71.     char buf[XSIZE][YSIZE][3];
  72.     char buf1[XSIZE][3][YSIZE];
  73.     char buf2[3][XSIZE][YSIZE];
  74.     char in[XSIZE][YSIZE][3];
  75.     char in1[XSIZE][3][YSIZE];
  76.     char in2[3][XSIZE][YSIZE];
  77.     int i,j,ret;
  78.     int ref0, ref1, ref2;
  79.  
  80.     for (i=0; i < XSIZE; i++)
  81.        for (j=0; j < YSIZE; j++) {
  82.            buf[i][j][0] = buf[i][j][1] = buf[i][j][2] = i + j;
  83.            buf1[i][0][j] = buf1[i][1][j] = buf1[i][2][j] = i | j;
  84.            buf2[0][i][j] = buf2[1][i][j] = buf2[2][i][j] = i ^ j;
  85.        }
  86.  
  87.     printf("\nStoring 24bit images with differing interlacing\n");
  88.  
  89.     ret = DF24setil(0);
  90.     RESULT("DF24setil");
  91.     ret = DF24putimage(TESTFILE, &(buf[0][0][0]), XSIZE, YSIZE);
  92.     RESULT("DF24putimage");
  93.     ref0 = DF24lastref();
  94.  
  95.     ret = DF24setil(1);
  96.     RESULT("DF24setil");
  97.     ret = DF24addimage(TESTFILE, &(buf1[0][0][0]), XSIZE, YSIZE);
  98.     RESULT("DF24addimage");
  99.     ref1 = DF24lastref();
  100.  
  101.     ret = DF24setil(2);
  102.     RESULT("DF24setil");
  103.     ret = DF24addimage(TESTFILE, &(buf2[0][0][0]), XSIZE, YSIZE);
  104.     RESULT("DF24addimage");
  105.     ref2 = DF24lastref();
  106.  
  107.     /* read image 0 */
  108.  
  109.     printf("\nReading and verifying 24bit images\n\n");
  110.   
  111.     ret = DF24restart();
  112.     RESULT("DF24restart");
  113.     ret = DF24reqil(0);
  114.     RESULT("DF24reqil");
  115.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  116.     RESULT("DF24getdims");
  117.  
  118.     if((xd != XSIZE) || (yd != YSIZE) || il != 0) {
  119.         fprintf(stderr, "Returned meta-data is wrong for image 0\n");
  120.         num_errs++;
  121.     }
  122.  
  123.     ret = DF24getimage(TESTFILE,(VOIDP)in, XSIZE, YSIZE);
  124.     RESULT("DF24getimage");
  125.     Error = FALSE;
  126.      for (i=0; i< XSIZE; i++)
  127.        for (j=0; j< YSIZE; j++)
  128.            if (in[i][j][0] != buf[i][j][0]
  129.                || in[i][j][1] != buf[i][j][1]
  130.                || in[i][j][2] != buf[i][j][2]) {
  131.                Error = TRUE;
  132.        }
  133.  
  134.     if(Error) {
  135.         fprintf(stderr, "Image 0 was incorrect\n");
  136.         num_errs++;
  137.     }
  138.  
  139.     if(ref0 != DF24lastref()) {
  140.         fprintf(stderr, "Bogus lastref for image 0\n");
  141.         num_errs++;
  142.     }
  143.  
  144.     /* read image 1 */
  145.  
  146.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  147.     RESULT("DF24getdims");
  148.  
  149.     if((xd != XSIZE) || (yd != YSIZE) || il != 1) {
  150.         fprintf(stderr, "Returned meta-data is wrong for image 1\n");
  151.         num_errs++;
  152.     }
  153.  
  154.     ret = DF24getimage(TESTFILE,(VOIDP)in, XSIZE, YSIZE);
  155.     RESULT("DF24getimage");
  156.     Error = FALSE;
  157.      for (i=0; i< XSIZE; i++)
  158.        for (j=0; j< YSIZE; j++)
  159.            if (in[i][j][0] != buf1[i][0][j]
  160.                || in[i][j][1] != buf1[i][1][j]
  161.                || in[i][j][2] != buf1[i][2][j]) {
  162.                Error = TRUE;
  163.        }
  164.     
  165.     if(Error) {
  166.         fprintf(stderr, "Image 1 was incorrect\n");
  167.         num_errs++;
  168.     }
  169.     
  170.     if(ref1 != DF24lastref()) {
  171.         fprintf(stderr, "Bogus lastref for image 1\n");
  172.         num_errs++;
  173.     }
  174.  
  175.  
  176.     /* read image 2 */
  177.       
  178.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  179.     RESULT("DF24getdims");
  180.  
  181.     if((xd != XSIZE) || (yd != YSIZE) || il != 2) {
  182.         fprintf(stderr, "Returned meta-data is wrong for image 2\n");
  183.         num_errs++;
  184.     }
  185.  
  186.     ret = DF24getimage(TESTFILE,(VOIDP)in, XSIZE, YSIZE);
  187.     RESULT("DF24getimage");
  188.     Error = FALSE;
  189.      for (i=0; i< XSIZE; i++)
  190.        for (j=0; j< YSIZE; j++)
  191.            if (in[i][j][0] != buf2[0][i][j]
  192.                || in[i][j][1] != buf2[1][i][j]
  193.                || in[i][j][2] != buf2[2][i][j]) {
  194.                Error = TRUE;
  195.        }
  196.  
  197.  
  198.     if(Error) {
  199.         fprintf(stderr, "Image 2 was incorrect\n");
  200.         num_errs++;
  201.     }
  202.     
  203.     if(ref2 != DF24lastref()) {
  204.         fprintf(stderr, "Bogus lastref for image 2\n");
  205.         num_errs++;
  206.     }
  207.  
  208.     ret = DF24restart();
  209.     RESULT("DF24restart");
  210.   
  211.  
  212.     /* read image 3 */
  213.  
  214.     ret = DF24reqil(1);
  215.     RESULT("DF24reqil");
  216.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);    
  217.     RESULT("DF24getdims");
  218.     
  219.     if((xd != XSIZE) || (yd != YSIZE) || il != 0) {
  220.         fprintf(stderr, "Returned meta-data is wrong for image 3\n");
  221.         num_errs++;
  222.     }
  223.  
  224.     ret = DF24getimage(TESTFILE,(VOIDP)in1, XSIZE, YSIZE);
  225.     RESULT("DF24getimage");
  226.     Error = FALSE;
  227.      for (i=0; i< XSIZE; i++)
  228.        for (j=0; j< YSIZE; j++)
  229.            if (in1[i][0][j] != buf[i][j][0]
  230.                || in1[i][1][j] != buf[i][j][1]
  231.                || in1[i][2][j] != buf[i][j][2]) {
  232.                Error = TRUE;
  233.        }
  234.  
  235.     if(Error) {
  236.         fprintf(stderr, "Image 3 was incorrect\n");
  237.         num_errs++;
  238.     }
  239.   
  240.     /* read image 4 */
  241.  
  242.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  243.     RESULT("DF24getdims");
  244.  
  245.     if((xd != XSIZE) || (yd != YSIZE) || il != 1) {
  246.         fprintf(stderr, "Returned meta-data is wrong for image 4\n");
  247.         num_errs++;
  248.     }
  249.  
  250.     ret = DF24getimage(TESTFILE,(VOIDP)in1, XSIZE, YSIZE);
  251.     RESULT("DF24getimage");
  252.     Error = FALSE;
  253.      for (i=0; i< XSIZE; i++)
  254.        for (j=0; j< YSIZE; j++)
  255.            if (in1[i][0][j] != buf1[i][0][j]
  256.                || in1[i][1][j] != buf1[i][1][j]
  257.                || in1[i][2][j] != buf1[i][2][j]) {
  258.                Error = TRUE;
  259.        }  
  260.  
  261.     if(Error) {
  262.         fprintf(stderr, "Image 4 was incorrect\n");
  263.         num_errs++;
  264.     }
  265.  
  266.     /* read image 5 */
  267.   
  268.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  269.     RESULT("DF24getdims");
  270.  
  271.     if((xd != XSIZE) || (yd != YSIZE) || il != 2) {
  272.         fprintf(stderr, "Returned meta-data is wrong for image 5\n");
  273.         num_errs++;
  274.     }
  275.  
  276.     ret = DF24getimage(TESTFILE,(VOIDP)in1, XSIZE, YSIZE);
  277.     RESULT("DF24getimage");
  278.     Error = FALSE;
  279.      for (i=0; i< XSIZE; i++)
  280.        for (j=0; j< YSIZE; j++)
  281.            if (in1[i][0][j] != buf2[0][i][j]
  282.                || in1[i][1][j] != buf2[1][i][j]
  283.                || in1[i][2][j] != buf2[2][i][j]) {
  284.                Error = TRUE;
  285.        }
  286.  
  287.     if(Error) {
  288.         fprintf(stderr, "Image 5 was incorrect\n");
  289.         num_errs++;
  290.     }
  291.   
  292.  
  293.     /* read image 6 */
  294.  
  295.     ret = DF24restart();
  296.     RESULT("DF24restart");
  297.  
  298.     ret = DF24reqil(2);
  299.     RESULT("DF24reqil");
  300.  
  301.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  302.     RESULT("DF24getdims");
  303.  
  304.     if((xd != XSIZE) || (yd != YSIZE) || il != 0) {
  305.         fprintf(stderr, "Returned meta-data is wrong for image 6\n");
  306.         num_errs++;
  307.     }
  308.  
  309.     ret = DF24getimage(TESTFILE,(VOIDP)in2, XSIZE, YSIZE);
  310.     RESULT("DF24getimage");
  311.     Error = FALSE;
  312.      for (i=0; i< XSIZE; i++)
  313.        for (j=0; j< YSIZE; j++)
  314.            if (in2[0][i][j] != buf[i][j][0]
  315.                || in2[1][i][j] != buf[i][j][1]
  316.                || in2[2][i][j] != buf[i][j][2]) {
  317.                Error = TRUE;
  318.        }
  319.  
  320.     if(Error) {
  321.         fprintf(stderr, "Image 6 was incorrect\n");
  322.         num_errs++;
  323.     }
  324.     
  325.     /* read image 7 */
  326.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  327.     RESULT("DF24getdims");
  328.  
  329.     if((xd != XSIZE) || (yd != YSIZE) || il != 1) {
  330.         fprintf(stderr, "Returned meta-data is wrong for image 7\n");
  331.         num_errs++;
  332.     }
  333.  
  334.     ret = DF24getimage(TESTFILE,(VOIDP)in2, XSIZE, YSIZE);
  335.     RESULT("DF24getimage");
  336.      for (i=0; i< XSIZE; i++)
  337.        for (j=0; j< YSIZE; j++)
  338.            if (in2[0][i][j] != buf1[i][0][j]
  339.                || in2[1][i][j] != buf1[i][1][j]
  340.                || in2[2][i][j] != buf1[i][2][j]) {
  341.                Error = TRUE;
  342.        }
  343.  
  344.     if(Error) {
  345.         fprintf(stderr, "Image 7 was incorrect\n");
  346.         num_errs++;
  347.     }
  348.  
  349.     /* read image 8 */
  350.  
  351.     ret = DF24getdims(TESTFILE, &xd, &yd, &il);
  352.     RESULT("DF24getdims");
  353.  
  354.     if((xd != XSIZE) || (yd != YSIZE) || il != 2) {
  355.         fprintf(stderr, "Returned meta-data is wrong for image 8\n");
  356.         num_errs++;
  357.     }
  358.  
  359.     ret = DF24getimage(TESTFILE,(VOIDP)in2, XSIZE, YSIZE);
  360.     RESULT("DF24getimage");
  361.     Error = FALSE;
  362.      for (i=0; i< XSIZE; i++)
  363.        for (j=0; j< YSIZE; j++)
  364.            if (in2[0][i][j] != buf2[0][i][j]
  365.                || in2[1][i][j] != buf2[1][i][j]
  366.                || in2[2][i][j] != buf2[2][i][j]) {
  367.                Error = TRUE;
  368.        }
  369.  
  370.     if(Error) {
  371.         fprintf(stderr, "Image 8 was incorrect\n");
  372.         num_errs++;
  373.     }
  374.   
  375. }
  376.  
  377.  
  378.  
  379. /* ------------------------------- test_r8 -------------------------------- */
  380.  
  381. #define XD1 10
  382. #define YD1 10
  383. #define XD2 7
  384. #define YD2 11
  385.  
  386. test_r8()
  387. {
  388.     uint8 *im2, *ii2;
  389.     uint8 *im1, *ii1;
  390.     uint8 *pal1, *pal2, *ipal;
  391.  
  392.     int x,y;
  393.     int ret, num_images=0;
  394.     uint16 ref1, ref2, ref3;
  395.     int32 xd, yd;
  396.     int ispal;
  397.     int error;
  398.  
  399.     im1 = (uint8 *) malloc(XD1 * YD1 * sizeof(uint8));
  400.     ii1 = (uint8 *) malloc(XD1 * YD1 * sizeof(uint8));
  401.     if(!im1 || !ii1) {
  402.         fprintf(stderr, "Out of memory!\n");
  403.         exit(1);
  404.     }
  405.     
  406.     im2 = (uint8 *) HDgetspace(XD2 * YD2 * sizeof(uint8));
  407.     ii2 = (uint8 *) HDgetspace(XD2 * YD2 * sizeof(uint8));
  408.     if(!im2 || !ii2) {
  409.         fprintf(stderr, "Out of memory!\n");
  410.         exit(1);
  411.     }
  412.     
  413.     pal1 = (uint8 *) malloc(768 * sizeof(char));
  414.     pal2 = (uint8 *) malloc(768 * sizeof(char));
  415.     ipal = (uint8 *) malloc(768 * sizeof(char));
  416.     if(!ipal || !pal1 || !pal2) {
  417.         fprintf(stderr, "Out of memory!\n");
  418.         exit(1);    
  419.     }
  420.  
  421.     for(x=0;x<XD1;x++)
  422.        for (y=0;y<YD1;y++)
  423.            im1[x * XD1 + y] = x+y;
  424.     for(x=0;x<XD2;x++)
  425.        for(y=0;y<YD2;y++)
  426.            im2[x * XD2 + y] = (2*x+y)-256*((2*x+y)/256);
  427.     for (x=0;x<256;x++) {
  428.        pal1[3*x] = x;
  429.        pal1[3*x + 1] = x;
  430.        pal1[3*x + 2] = x;
  431.        pal2[x] = x;
  432.        pal2[x+256] = x;
  433.        pal2[x+512] = x;
  434.     }
  435.  
  436.     /* start here */
  437.  
  438.     printf("\nStoring 8bit raster images\n");
  439.     ret = DFR8setpalette(pal1);
  440.     RESULT("DFR8setpalette");
  441.  
  442.     printf("\nPutting image with no compression\n");
  443.     ret = DFR8putimage(TESTFILE, (VOIDP)im1, XD1, YD1, 0);
  444.     RESULT("DFR8putimage");
  445.     num_images++;
  446.     ref1 = DFR8lastref();
  447.  
  448.     printf("\nPutting image RLE compression\n");
  449.     ret = DFR8addimage(TESTFILE, (VOIDP)im2, XD2, YD2, DFTAG_RLE);
  450.     RESULT("DFR8addimage");
  451.     num_images++;
  452.     ref2 = DFR8lastref();
  453.  
  454.     ret = DFR8setpalette(pal2);
  455.     RESULT("DFR8setpalette");
  456.     printf("\nPutting image IMCOMP compression\n");
  457.     ret = DFR8addimage(TESTFILE, (VOIDP)im2, XD2, YD2, DFTAG_IMCOMP);
  458.     RESULT("DFR8addimage");
  459.     num_images++;
  460.     ref3 = DFR8lastref();
  461.  
  462.     ret = DFR8nimages(TESTFILE);
  463.     if (ret != num_images) {
  464.         fprintf(stderr, "        >>> WRONG NUMBER OF IMAGES <<<\n");
  465.         num_errs++;
  466.     }
  467.  
  468.     printf("\nReading and verifying 8bit raster images\n");
  469.  
  470.     ret = DFR8restart();
  471.     RESULT("DFR8restart");
  472.  
  473.     printf("\nVerifying uncompressed image\n");
  474.  
  475.     ret = DFR8getdims(TESTFILE, &xd, &yd, &ispal);
  476.     RESULT("DFR8getdims");
  477.     ret = DFR8getimage(TESTFILE, (uint8 *) ii1, (int32) XD1, (int32) YD1, ipal);
  478.     RESULT("DFR8getimage");
  479.     error = FALSE;
  480.     check_im_pal(XD1, YD1, xd, yd, (uint8 **)im1, (uint8 **)ii1, pal1, ipal);
  481.  
  482.     printf("\nVerifying RLE compressed image\n");
  483.  
  484.     ret = DFR8getdims(TESTFILE, &xd, &yd, &ispal);
  485.     RESULT("DFR8getdims");
  486.  
  487.     printf("\nVerifying IMCOMP compressed image\n");
  488.  
  489.     ret = DFR8getdims(TESTFILE, &xd, &yd, &ispal);
  490.     RESULT("DFR8getdims");
  491.     ret = DFR8getimage(TESTFILE, (uint8 *) ii2, (int32) XD2, (int32) YD2, ipal);
  492.     RESULT("DFR8getimage");
  493.  
  494.     printf("\nRechecking RLE image\n");
  495.  
  496.     ret = DFR8readref(TESTFILE, ref2);
  497.     RESULT("DFR8readref");
  498.     ret = DFR8getimage(TESTFILE, (uint8 *) ii2, (int32) XD2, (int32) YD2, ipal);
  499.     RESULT("DFR8getimage");
  500.     check_im_pal(XD2, YD2, XD2, YD2, (uint8 **)im2, (uint8 **)ii2, pal1, ipal);
  501.  
  502.     printf("\nChanging palette of first image\n");
  503.  
  504.     ret = DFR8writeref(TESTFILE, ref1);
  505.     RESULT("DFR8writeref");
  506.     ret = DFR8setpalette(pal2);
  507.     RESULT("DFR8setpalette");
  508.     ret = DFR8addimage(TESTFILE, (VOIDP)im1, XD1, YD1, DFTAG_RLE);
  509.     RESULT("DFR8addimage");
  510.  
  511.  
  512.     printf("\nVerifying palette change\n");
  513.  
  514.     ret = DFR8readref(TESTFILE, ref1);
  515.     RESULT("DFR8readref");
  516.     ret = DFR8getdims(TESTFILE, &xd, &yd, &ispal);
  517.     RESULT("DFR8getdims");
  518.     ret = DFR8getimage(TESTFILE, (uint8 *) ii1, (int32) XD1, (int32) YD1, ipal);
  519.     RESULT("DFR8getimage");
  520.     check_im_pal(XD1, YD1, xd, yd, (uint8 **)im1, (uint8 **)ii1, pal2, ipal);
  521.  
  522. }
  523.  
  524. check_im_pal(oldx, oldy, newx, newy, oldim, newim, oldpal, newpal)
  525.     int oldx, oldy, newx, newy;
  526.     uint8 **oldim, **newim, *oldpal, *newpal;    
  527. {
  528.     int error;
  529.     int x, y;
  530.     uint8 *op, *np;
  531.  
  532.     printf("\nChecking image and palette.\n");
  533.  
  534.     op = (uint8 *)oldim;
  535.     np = (uint8 *)newim;
  536.     if ( newx!=oldx || newy != oldy)
  537.         printf("        >>> DIMENSIONS WRONG <<<\n\n");
  538.     error = FALSE;
  539.     for (x=0;x<oldx;x++)
  540.        for (y=0;y<oldy;y++) {
  541.            if ( *op != *np) { 
  542.                printf("\t>>>Error at %d %d, orig image=%d; new image=%d<<<\n",
  543.                                                                x, y, *op, *np);
  544.                error = TRUE;
  545.            }
  546.            op++;
  547.            np++;
  548.     }
  549.     if (error) {
  550.         printf("    >>> Image is wrong. <<<\n");
  551.         num_errs++;
  552.     }
  553.  
  554.     error = FALSE;
  555.     for (x=0;x<768;x++)
  556.        if (oldpal[x] != newpal[x]) {
  557.            printf("\t>>>Pal error at %d, orig pal %u new pal %u<<<\n",
  558.                                                  x, oldpal[x], newpal[x]);
  559.                error = TRUE;
  560.        }
  561.     if (error) {
  562.         printf("    >>> Palette is wrong. <<<\n");
  563.         num_errs++;
  564.     }
  565. }
  566.  
  567. test_pal()
  568. {
  569.     int i;
  570.     int ret;
  571.     uint16 ref1, ref2;
  572.  
  573.     char *pal1, *pal2, *ipal;
  574.    
  575.     pal1 = (char *) malloc(768 * sizeof(char));
  576.     pal2 = (char *) malloc(768 * sizeof(char));
  577.     ipal = (char *) malloc(768 * sizeof(char));
  578.     if(!ipal || !pal1 || !pal2) {
  579.         fprintf(stderr, "Out of memory!\n");
  580.         exit(1);    
  581.     }
  582.  
  583.     for (i=0;i<256;i++) {
  584.        pal1[3*i] = i;
  585.        pal1[3*i + 1] = i;
  586.        pal1[3*i + 2] = i;
  587.        pal2[i] = i;
  588.        pal2[i + 256] = i;
  589.        pal2[i + 512] = i;
  590.     }
  591.     
  592.     printf("\nAdding palettes to a file\n");
  593.  
  594.     ret = DFPputpal(TESTFILE, pal1, 0, "w");
  595.     RESULT("DFPputpal");
  596.     ref1 = DFPlastref();
  597.  
  598.  
  599.     ret = DFPaddpal(TESTFILE, pal2);
  600.     RESULT("DFPaddpal");
  601.     ref2 = DFPlastref();
  602.  
  603.     printf("\nReading and verifying palettes\n");
  604.  
  605.     ret = DFPrestart();
  606.     RESULT("DFPrestart");
  607.  
  608.  
  609.     /* read and check palette 1 */
  610.     ret = DFPgetpal(TESTFILE, ipal);
  611.     RESULT("DFPgetpal");
  612.     for (i=0;i<768;i++)
  613.        if (ipal[i] != pal1[i])
  614.            printf("Error at %d, ipal %d pal1 %d\n", i, ipal[i], pal1[i]);
  615.  
  616.     if(ref1 != DFPlastref()) {
  617.         fprintf(stderr,"  >>> DFPlastref() bad for palette 1 <<<\n");
  618.         num_errs++;
  619.     }
  620.  
  621.  
  622.     /* read and check palette 2 */
  623.     ret = DFPgetpal(TESTFILE, ipal);
  624.     RESULT("DFPgetpal");
  625.     for (i=0;i<768;i++)
  626.        if (ipal[i] != pal2[i])
  627.            printf("Error at %d, ipal %d pal2 %d\n", i, ipal[i], pal2[i]);
  628.  
  629.     if(ref2 != DFPlastref()) {
  630.         fprintf(stderr,"  >>> DFPlastref() bad for palette 2 <<<\n");
  631.         num_errs++;
  632.     }
  633.  
  634.     /*
  635.      * this is 4 instead of 2 since they are 8-bit pals and thus
  636.      * list twice and generic pals 
  637.      */
  638.  
  639.     if(DFPnpals(TESTFILE) != 4) {
  640.         fprintf(stderr,"  >>> DFPnpals() gives wrong number <<<\n");
  641.         num_errs++;
  642.     }
  643.  
  644.     /* recheck palette number 2 */
  645.     ret = DFPreadref(TESTFILE, ref2);
  646.     RESULT("DFPreadref");
  647.     ret = DFPgetpal(TESTFILE, ipal);
  648.     RESULT("DFPgetpal");
  649.     for (i=0;i<768;i++)
  650.        if (ipal[i] != pal2[i])
  651.            printf("Error at %d, ipal %d pal2 %d\n", i, ipal[i], pal2[i]);
  652.  
  653.  
  654.     /* recheck palette number 1 */
  655.     ret = DFPreadref(TESTFILE, ref1);
  656.     RESULT("DFPreadref");
  657.     ret = DFPgetpal(TESTFILE, ipal);
  658.     RESULT("DFPgetpal");
  659.     for (i=0;i<768;i++)
  660.        if (ipal[i] != pal1[i])
  661.            printf("Error at %d, ipal %d pal1 %d\n", i, ipal[i], pal1[i]);
  662.  
  663.     printf("\nModifying first palette\n");
  664.     for (i=0;i<256;i++)
  665.        pal1[i+256] = 255 - i;
  666.     ret = DFPwriteref(TESTFILE, ref1);
  667.     RESULT("DFPwriteref");
  668.  
  669.     ret = DFPputpal(TESTFILE, pal1, 1, "a");
  670.     RESULT("DFPputpal");
  671.  
  672.     ret = DFPreadref(TESTFILE, ref1);
  673.     RESULT("DFPreafref");
  674.  
  675.     ret = DFPgetpal(TESTFILE, ipal);
  676.     RESULT("DFPgetpal");
  677.     for (i=0;i<768;i++)
  678.        if (ipal[i] != pal1[i])
  679.            printf("Error at %d, ipal %d pal1 %d\n", i, ipal[i], pal1[i]);
  680. }
  681.  
  682.  
  683.  
  684.  
  685. main() {
  686.  
  687.  
  688.     printf("\n************ TESTING 24BIT RASTER IMAGE INTERFACE *************\n");
  689.     test_r24();
  690.  
  691.     printf("\n************ TESTING  8BIT RASTER IMAGE INTERFACE *************\n");
  692.     test_r8(); 
  693.  
  694.     printf("\n************ TESTING  PALETTE INTERFACE *************\n");
  695.     test_pal();
  696.  
  697.     if(num_errs) {
  698.         fprintf(stderr, "\n!!! %d Error(s) were detected !!!\n\n", num_errs);
  699.     } else {
  700.         fprintf(stderr, "\n<<< All tests successful >>>\n\n");
  701.     }
  702.  
  703. }
  704.