home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / datatypes / qrtv43datatype / source / qrtcheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-03  |  2.0 KB  |  69 lines

  1. /*
  2. *  The format is as follows:
  3. *
  4. *  (header:)
  5. *    wwww hhhh       - Width, Height (16 bits, LSB first)
  6. *
  7. *  (each scanline:)
  8. *    llll            - Line number (16 bits, LSB first)
  9. *    rr rr rr ...    - Red data for line (8 bits per pixel,
  10. *                       left to right, 0-255 (255=bright, 0=dark))
  11. *    gg gg gg ...    - Green data for line (8 bits per pixel,
  12. *                       left to right, 0-255 (255=bright, 0=dark))
  13. *    bb bb bb ...    - Blue data for line (8 bits per pixel,
  14. *                       left to right, 0-255 (255=bright, 0=dark))
  15. */
  16.  
  17. #include <datatypes/datatypes.h>
  18. #include <exec/memory.h>
  19.  
  20. #include <clib/dos_protos.h>
  21. #include <clib/exec_protos.h>
  22.  
  23. #include <pragmas/dos_pragmas.h>
  24. #include <pragmas/exec_sysbase_pragmas.h>
  25.  
  26. #define DOSBase          dthc->dthc_DOSBase
  27. #define SysBase          dthc->dthc_SysBase
  28.  
  29. BOOL __interrupt __asm DTHook (register __a0 struct DTHookContext * dthc)
  30. {
  31.     BOOL retval = FALSE;
  32.     UBYTE *buffer;
  33.     BPTR fh;
  34.     UWORD width,height;
  35.     ULONG filesize;
  36.  
  37.     if (                            /* Make sure we have: */
  38.         (fh = dthc->dthc_FileHandle) &&            /* a FileHandle */
  39.         dthc->dthc_FIB &&                /* a FileInfoBlock */
  40.         (buffer = dthc->dthc_Buffer) &&            /* a Buffer */
  41.         (dthc->dthc_BufferLength >= 4) &&        /* width and height in buffer */
  42.         (width = (buffer[1] << 8) + buffer[0]) &&    /* width != 0 */
  43.         (height = (buffer[3] << 8) + buffer[2]) &&    /* height != 0 */
  44.         (filesize = 4            /* width + height */
  45.             + (height << 1)        /* linenumbers */
  46.             + (width * height * 3) /* 24 Bits per pixel */
  47.         ) == dthc->dthc_FIB->fib_Size            /* and the correct length of the file */
  48.        )
  49.     {
  50.         ULONG linesize = width * 3 + 2;
  51.         UWORD i;
  52.  
  53.         /* Allocate a buffer and skip width and height */
  54.         if((buffer = AllocVec(linesize, MEMF_PUBLIC)) && (Read(fh, buffer, 4) == 4))
  55.         {
  56.             for (i = 0, retval = TRUE; (i < height) && (retval == TRUE); i++)
  57.             {
  58.                 if (
  59.                     (Read(fh, buffer, linesize) != linesize) ||    /* file can be read */
  60.                     (i != ((buffer[1] << 8) + buffer[0]))        /* linenumber check */
  61.                    )
  62.                     retval = FALSE;
  63.             }
  64.             FreeVec(buffer);
  65.         }
  66.     }
  67.     return retval;
  68. }
  69.