home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / d / desklib / !DeskSrc / FN / Libraries / Clear / c0 / Create next >
Encoding:
Text File  |  1996-05-10  |  1.8 KB  |  70 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Clear.c.Create
  12.     Author:  Copyright © 1993, 1994 Jason Howat
  13.     Version: 1.01 (13 May 1994)
  14.     Purpose: Allocate memory for a Clear file.
  15.     History: 1.00 (16 Dec 1993)   initial version
  16.              1.01 (13 May 1994)   updated to use Desk_Mem_ library
  17. */
  18.  
  19.  
  20. #include <stdlib.h>
  21. #include "Desk.Clear.h"
  22. #include "Desk.Mem.h"
  23. #include "Desk.DeskMem.h"
  24.  
  25. #include "Desk.Clear.h"
  26. #include "ClearDefs.h"
  27.  
  28.  
  29.  
  30.  
  31. Desk_clear_picture *Desk_Clear_Create(unsigned width, unsigned height, unsigned bpp)
  32. {
  33.   Desk_clear_picture *temp;
  34.   unsigned      Desk_bitmap_size;
  35.   
  36.  
  37.   if((temp = Desk_DeskMem_XMalloc(sizeof(Desk_clear_picture))) == NULL)
  38.     return NULL;
  39.  
  40.   temp->creator = Desk_clear__creator;
  41.   temp->creatorversion = Desk_clear__creatorversion;
  42.   temp->width = width;
  43.   temp->height = height;
  44.   temp->bpp = bpp;
  45.   if(bpp > 8)
  46.   {
  47.     temp->palette = NULL;
  48.     Desk_bitmap_size = 3 * width * height;
  49.   }
  50.   else
  51.   {
  52.     if(!Desk_Mem_Alloc((void **)&temp->palette, sizeof(Desk_palette_entry) * (1 << bpp)))
  53.     {
  54.       Desk_DeskMem_Free(temp);
  55.       return NULL;
  56.     }
  57.  
  58.     Desk_bitmap_size = width * height;
  59.   }
  60.  
  61.   if(!Desk_Mem_Alloc((void **)&temp->bitmap, Desk_bitmap_size))
  62.   {
  63.     if(temp->palette)
  64.       Desk_Mem_Free((void **)temp->palette);
  65.     Desk_DeskMem_Free(temp);
  66.   }
  67.  
  68.   return temp;
  69. }
  70.