home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name wnmkimg -- Allocate data buffer for IMAGE structure.
- *
- * Synopsis presult = wngetimg(pimage);
- *
- * IMAGE *presult Pointer to modified IMAGE structure,
- * or NIL if failure.
- * IMAGE *pimage Pointer to IMAGE structure for which
- * to allocate data buffer.
- *
- * Description This function allocates a buffer for an IMAGE structure
- * based on dimensions stored in the structure.
- *
- * An error occurs if the dimensions are invalid or if the
- * memory allocation fails. Do not use the data buffer
- * (pimage->pdata) if an error is reported.
- *
- * Returns presult Pointer to modified IMAGE structure,
- * or NIL if failure.
- * pimage->pdata Pointer to new data buffer,
- * or NIL if failure.
- * b_wnerr Possible values:
- * (No change) Success.
- * WN_ILL_DIM Invalid pimage->dim.
- * WN_NO_MEMORY Out of dynamic memory.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <bwindow.h>
-
- #if MSC300
- #include <malloc.h>
- #else
- #include <stdlib.h>
- #endif
-
- IMAGE *wnmkimg(pimage)
- IMAGE *pimage;
- {
- pimage->pdata = NIL; /* In case of error. */
-
- if (pimage->dim.h <= 0 || pimage->dim.w <= 0)
- {
- wnerror(WN_ILL_DIM); /* Invalide dimension(s). */
- return NIL;
- }
- /* Allocate the memory space. */
- if ((pimage->pdata =
- (CELL *) calloc((unsigned int) pimage->dim.h * pimage->dim.w,
- sizeof(CELL)))
- == NIL)
- {
- wnerror(WN_NO_MEMORY);
- return NIL;
- }
-
- return pimage; /* Success. */
- }