]> Creatis software - gdcm.git/blob - src/jpeg/ljpg/mcu.c
FIX: Compilation on Mac OSX is fine now + remove tabs
[gdcm.git] / src / jpeg / ljpg / mcu.c
1 /*
2  * mcu.c --
3  *
4  * Support for MCU allocation, deallocation, and printing.
5  *
6  */
7 /*
8  * $Id: mcu.c,v 1.2 2004/08/18 02:26:08 malaterre Exp $
9  */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "jpeg.h"
14 #include "mcu.h"
15 #include "proto.h"
16
17 MCU *mcuTable=NULL;     /* the global mcu table that buffers the source image */
18
19 MCU *mcuROW1=NULL;      /* point to two rows of MCU in encoding & decoding */
20 MCU *mcuROW2=NULL;
21
22 int numMCU=0;           /* number of MCUs in mcuTable */
23
24 /*
25  *--------------------------------------------------------------
26  *
27  * MakeMCU, InitMcuTable --
28  *
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.
33  *
34  * Results:
35  *        A new MCU
36  *
37  * Side effects:
38  *        None.
39  *
40  *--------------------------------------------------------------
41  */
42 void InitMcuTable (int numMCU,int compsInScan)
43 {
44     int i, mcuSize;
45     char *buffer;
46
47     /*
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).
51      */
52     mcuSize = compsInScan * sizeof(ComponentType);
53     mcuSize = JroundUp(mcuSize,sizeof(double));
54
55     /*
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
59      * it up later.
60      */
61     mcuTable = (MCU *)malloc(numMCU * sizeof(MCU));
62     if (mcuTable==NULL)
63        fprintf(stderr,"Not enough memory for mcuTable\n");
64     buffer = (char *)malloc(numMCU * mcuSize);
65     if (buffer==NULL)
66        fprintf(stderr,"Not enough memory for buffer\n");
67     for (i=0; i<numMCU; i++) {
68         mcuTable[i] = (MCU)(buffer + i*mcuSize);
69     }
70 }
71
72 #define MakeMCU(dcPtr)                (mcuTable[numMCU++])
73
74
75 /*
76  *--------------------------------------------------------------
77  *
78  * FreeMcuTable --
79  *
80  * Frees up the allocated table
81  *
82  * Results:
83  * None.
84  *
85  * Side effects:
86  * None.
87  *
88  *--------------------------------------------------------------
89  */
90 void FreeMcuTable(void)
91 {
92          free( mcuTable );
93 }
94
95 /*
96  *--------------------------------------------------------------
97  *
98  * PrintMCU --
99  *
100  *        Send an MCU in quasi-readable form to stdout.
101  *
102  * Results:
103  *        None.
104  *
105  * Side effects:
106  *        None.
107  *
108  *--------------------------------------------------------------
109  */
110 void PrintMCU (int compsInScan, MCU mcu)
111 {
112     ComponentType r;
113     int b;
114     static int callCount;
115
116     for (b=0; b<compsInScan; b++) {
117         callCount++;
118         r = mcu[b];
119         printf ("%d: %d ", callCount, r);
120         printf ("\n");
121     }
122 }