home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / WNMKIMG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  1.6 KB  |  62 lines

  1. /**
  2. *
  3. * Name        wnmkimg -- Allocate data buffer for IMAGE structure.
  4. *
  5. * Synopsis    presult = wngetimg(pimage);
  6. *
  7. *        IMAGE *presult      Pointer to modified IMAGE structure,
  8. *                  or NIL if failure.
  9. *        IMAGE *pimage      Pointer to IMAGE structure for which
  10. *                  to allocate data buffer.
  11. *
  12. * Description    This function allocates a buffer for an IMAGE structure
  13. *        based on dimensions stored in the structure.
  14. *
  15. *        An error occurs if the dimensions are invalid or if the
  16. *        memory allocation fails.  Do not use the data buffer
  17. *        (pimage->pdata) if an error is reported.
  18. *
  19. * Returns    presult       Pointer to modified IMAGE structure,
  20. *                  or NIL if failure.
  21. *        pimage->pdata      Pointer to new data buffer,
  22. *                  or NIL if failure.
  23. *        b_wnerr       Possible values:
  24. *                  (No change)       Success.
  25. *                  WN_ILL_DIM       Invalid pimage->dim.
  26. *                  WN_NO_MEMORY       Out of dynamic memory.
  27. *
  28. * Version    3.0  (C)Copyright Blaise Computing Inc. 1986
  29. *
  30. **/
  31.  
  32. #include <bwindow.h>
  33.  
  34. #if MSC300
  35. #include <malloc.h>
  36. #else
  37. #include <stdlib.h>
  38. #endif
  39.  
  40. IMAGE *wnmkimg(pimage)
  41. IMAGE *pimage;
  42. {
  43.     pimage->pdata = NIL;          /* In case of error.          */
  44.  
  45.     if (pimage->dim.h <= 0 || pimage->dim.w <= 0)
  46.     {
  47.     wnerror(WN_ILL_DIM);          /* Invalide dimension(s).       */
  48.     return NIL;
  49.     }
  50.                       /* Allocate the memory space.   */
  51.     if ((pimage->pdata =
  52.        (CELL *) calloc((unsigned int) pimage->dim.h * pimage->dim.w,
  53.                sizeof(CELL)))
  54.                == NIL)
  55.     {
  56.     wnerror(WN_NO_MEMORY);
  57.     return NIL;
  58.     }
  59.  
  60.     return pimage;              /* Success.              */
  61. }
  62.