summaryrefslogtreecommitdiff
path: root/gtk/plugins/crazychat/camdata.c
blob: 93934006c181ca0414ff590ebb53e6f9f01d8594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 *  camdata.c
 *  basecame
 *
 *  Created by CS194 on Mon Apr 26 2004.
 *  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
 *
 */

#include "camdata.h"
//#include "AppBlit_Component.h"
#include "QTUtilities.h"
#include "Utilities.h"


#define	BailNULL(n)  if (!n) goto bail;
#define	BailError(n) if (n) goto bail;
#define	BailNil(n) if (!n) goto bail;
#define BailErr(x) {if (x != noErr) goto bail;}
#define bitdepth 32

mungDataPtr myMungData = NULL;
long		mWorlds[20];
UInt32		mRedCount[256], mGreenCound[256], mBlueCount[256];

static void DecompressSequencePreflight(GWorldPtr srcGWorld, 
                                        ImageSequence *imageSeq,
                                        GWorldPtr destGWorld,
                                        Rect *srcRect);
//static void DrawRGBHistogram(mungDataRecord *theMungData);
//static void CreateEffectDescription(mungDataRecord *theMungData);
//static void CreateEffectDecompSequence(mungDataRecord *theMungData);
//static void AddGWorldDataSourceToEffectDecompSeq(mungDataRecord *theMungData);
//static void MakeEffectTimeBaseForEffect(mungDataRecord *theMungData);
//static void DrawUsingEffect(mungDataRecord *theMungData);


OSErr InitializeMungData(Rect bounds)
{
	OSErr err = noErr;
    
	if(myMungData) 
    {
        DisposeMungData();
	}
    
	myMungData = (mungDataPtr)NewPtrClear(sizeof(mungDataRecord));
	if (myMungData == nil) 
    {
        err = MemError();
        goto bail;
    }

	myMungData->effect = 0; // always
    

	BailErr(QTNewGWorld(&(myMungData->gw),bitdepth,&bounds,0,0,0));
	LockPixels(GetGWorldPixMap(myMungData->gw));
    
    SetMungDataColorDefaults();



	myMungData->selectedIndex = 0;
	myMungData->overlay = NULL;

	SetCurrentClamp(-1);

            
	
	myMungData->bounds = bounds;

	SetRect(&bounds, 0, 0, 256*2+4, 128*3 + 20);
	BailErr(QTNewGWorld(&(myMungData->histoWorld),bitdepth,&bounds,0,0,0));
	LockPixels(GetGWorldPixMap(myMungData->histoWorld));

bail:
	return err;
}

OSErr DisposeMungData(void)
{  // check this out
    OSErr err = noErr;
    
    if(myMungData) 
    {
        //if(myMungData->drawSeq) 
        //{
        //    CDSequenceEnd(myMungData->drawSeq);
        //}
        
        if(myMungData->gw) 
        {
            DisposeGWorld(myMungData->gw); 
            myMungData->gw = nil;
        }
        
        if(myMungData->overlay) 
        {
            DisposeGWorld(myMungData->overlay); 
            myMungData->overlay = nil;
        }
        
        if(myMungData->histoWorld) 
        {
            DisposeGWorld(myMungData->histoWorld); 
            myMungData->histoWorld = nil;
        }
    
        if (myMungData->effectTimeBase)
        {
            DisposeTimeBase(myMungData->effectTimeBase);
        }
        if (myMungData->effectParams)
        {
            QTDisposeAtomContainer(myMungData->effectParams);
        }
        if (myMungData->effectDesc)
        {
            DisposeHandle((Handle)myMungData->effectDesc);
        }

        DisposePtr((Ptr)myMungData);
        myMungData = nil;
    }
    return err;
}

static void DecompressSequencePreflight(GWorldPtr srcGWorld, 
                                        ImageSequence *imageSeq,
                                        GWorldPtr destGWorld,
                                        Rect *srcRect)
// might not need this one
										
{
    ImageDescriptionHandle imageDesc = nil;
    
    BailErr(MakeImageDescriptionForPixMap (GetGWorldPixMap(srcGWorld), &imageDesc));
    
    // use our built-in decompressor to draw
   // (**imageDesc).cType = kCustomDecompressorType;
	
// *********** MIGHT BE MAKING A BIG MISTAKE ******************
    // pass a compressed sample so a codec can perform preflighting before the first DecompressSequenceFrameWhen call

    BailErr(DecompressSequenceBegin(imageSeq, 
                                    imageDesc, 
                                    destGWorld,
                                    0,
                                    srcRect, 
                                    nil,
                                    srcCopy,
                                    nil,
                                    0,
                                    codecNormalQuality,
                                    bestSpeedCodec));

bail:
    if (imageDesc)
    {
        DisposeHandle((Handle)imageDesc);
    }
}

ImageSequence GetMungDataDrawSeq()
{
	return myMungData->drawSeq;
}

void SetMungDataColorDefaults()
{
	if(myMungData) 
    {
        myMungData->redMin = 2;
        myMungData->redMax = 254;
        myMungData->greenMin = 2;
        myMungData->greenMax = 254;
        myMungData->blueMin = 2;
        myMungData->blueMax = 254;
    }
}

void GetMungDataBoundsRect(Rect *boundsRect)
// might not need this one
{
	MacSetRect (boundsRect, 
			myMungData->bounds.left, 
			myMungData->bounds.top, 
			myMungData->bounds.right, 
			myMungData->bounds.bottom
	);
}

void SetCurrentClamp(short index)     // :crazy:20040426 
{
    myMungData->selectedIndex = index;
}

GWorldPtr GetMungDataOffscreen()
{
    return (myMungData->gw);
}

void SetMungDataDrawSeq(ImageSequence theDrawSeq)
{
	myMungData->drawSeq = theDrawSeq;
}


CGrafPtr GetMungDataWindowPort()
{
	return GetWindowPort(myMungData->window);
}