4 * Support for MCU allocation, deallocation, and printing.
8 * $Id: mcu.c,v 1.2 2004/08/18 02:26:08 malaterre Exp $
17 MCU *mcuTable=NULL; /* the global mcu table that buffers the source image */
19 MCU *mcuROW1=NULL; /* point to two rows of MCU in encoding & decoding */
22 int numMCU=0; /* number of MCUs in mcuTable */
25 *--------------------------------------------------------------
27 * MakeMCU, InitMcuTable --
29 * InitMcuTable does a big malloc to get the amount of memory
30 * we'll need for storing MCU's, once we know the size of our
31 * input and output images.
32 * MakeMCU returns an MCU for input parsing.
40 *--------------------------------------------------------------
42 void InitMcuTable (int numMCU,int compsInScan)
48 * Compute size of on MCU (in bytes). Round up so it's on a
49 * boundary for any alignment. In this code, we assume this
50 * is a whole multiple of sizeof(double).
52 mcuSize = compsInScan * sizeof(ComponentType);
53 mcuSize = JroundUp(mcuSize,sizeof(double));
56 * Allocate the MCU table, and a buffer which will contain all
57 * the data. Then carve up the buffer by hand. Note that
58 * mcuTable[0] points to the buffer, in case we want to free
61 mcuTable = (MCU *)malloc(numMCU * sizeof(MCU));
63 fprintf(stderr,"Not enough memory for mcuTable\n");
64 buffer = (char *)malloc(numMCU * mcuSize);
66 fprintf(stderr,"Not enough memory for buffer\n");
67 for (i=0; i<numMCU; i++) {
68 mcuTable[i] = (MCU)(buffer + i*mcuSize);
72 #define MakeMCU(dcPtr) (mcuTable[numMCU++])
76 *--------------------------------------------------------------
80 * Frees up the allocated table
88 *--------------------------------------------------------------
90 void FreeMcuTable(void)
96 *--------------------------------------------------------------
100 * Send an MCU in quasi-readable form to stdout.
108 *--------------------------------------------------------------
110 void PrintMCU (int compsInScan, MCU mcu)
114 static int callCount;
116 for (b=0; b<compsInScan; b++) {
119 printf ("%d: %d ", callCount, r);