~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to source/blender/imbuf/intern/allocimbuf.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-04-28 12:11:12 UTC
  • mto: (14.1.6 experimental) (1.5.1)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: package-import@ubuntu.com-20120428121112-2zi0vp8b6vejda8i
Tags: upstream-2.63
ImportĀ upstreamĀ versionĀ 2.63

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
{
52
52
        int a;
53
53
        
54
 
        for(a=1; a<ibuf->miptot; a++) {
55
 
                if(ibuf->mipmap[a-1])
 
54
        for (a=1; a<ibuf->miptot; a++) {
 
55
                if (ibuf->mipmap[a-1])
56
56
                        IMB_freeImBuf(ibuf->mipmap[a-1]);
57
57
                ibuf->mipmap[a-1]= NULL;
58
58
        }
63
63
/* any free rect frees mipmaps to be sure, creation is in render on first request */
64
64
void imb_freerectfloatImBuf(ImBuf *ibuf)
65
65
{
66
 
        if(ibuf==NULL) return;
 
66
        if (ibuf==NULL) return;
67
67
        
68
 
        if(ibuf->rect_float && (ibuf->mall & IB_rectfloat)) {
 
68
        if (ibuf->rect_float && (ibuf->mall & IB_rectfloat)) {
69
69
                MEM_freeN(ibuf->rect_float);
70
70
                ibuf->rect_float=NULL;
71
71
        }
79
79
/* any free rect frees mipmaps to be sure, creation is in render on first request */
80
80
void imb_freerectImBuf(ImBuf *ibuf)
81
81
{
82
 
        if(ibuf==NULL) return;
 
82
        if (ibuf==NULL) return;
83
83
 
84
 
        if(ibuf->rect && (ibuf->mall & IB_rect))
 
84
        if (ibuf->rect && (ibuf->mall & IB_rect))
85
85
                MEM_freeN(ibuf->rect);
86
86
        ibuf->rect= NULL;
87
87
        
94
94
{
95
95
        int tx, ty;
96
96
 
97
 
        if(ibuf==NULL) return;
 
97
        if (ibuf==NULL) return;
98
98
 
99
 
        if(ibuf->tiles && (ibuf->mall & IB_tiles)) {
100
 
                for(ty=0; ty<ibuf->ytiles; ty++) {
101
 
                        for(tx=0; tx<ibuf->xtiles; tx++) {
102
 
                                if(ibuf->tiles[ibuf->xtiles*ty + tx]) {
 
99
        if (ibuf->tiles && (ibuf->mall & IB_tiles)) {
 
100
                for (ty=0; ty<ibuf->ytiles; ty++) {
 
101
                        for (tx=0; tx<ibuf->xtiles; tx++) {
 
102
                                if (ibuf->tiles[ibuf->xtiles*ty + tx]) {
103
103
                                        imb_tile_cache_tile_free(ibuf, tx, ty);
104
104
                                        MEM_freeN(ibuf->tiles[ibuf->xtiles*ty + tx]);
105
105
                                }
115
115
 
116
116
static void freeencodedbufferImBuf(ImBuf *ibuf)
117
117
{
118
 
        if(ibuf==NULL) return;
 
118
        if (ibuf==NULL) return;
119
119
 
120
 
        if(ibuf->encodedbuffer && (ibuf->mall & IB_mem))
 
120
        if (ibuf->encodedbuffer && (ibuf->mall & IB_mem))
121
121
                MEM_freeN(ibuf->encodedbuffer);
122
122
 
123
123
        ibuf->encodedbuffer = NULL;
128
128
 
129
129
void IMB_freezbufImBuf(ImBuf *ibuf)
130
130
{
131
 
        if(ibuf==NULL) return;
 
131
        if (ibuf==NULL) return;
132
132
 
133
 
        if(ibuf->zbuf && (ibuf->mall & IB_zbuf))
 
133
        if (ibuf->zbuf && (ibuf->mall & IB_zbuf))
134
134
                MEM_freeN(ibuf->zbuf);
135
135
 
136
136
        ibuf->zbuf= NULL;
139
139
 
140
140
void IMB_freezbuffloatImBuf(ImBuf *ibuf)
141
141
{
142
 
        if(ibuf==NULL) return;
 
142
        if (ibuf==NULL) return;
143
143
 
144
 
        if(ibuf->zbuf_float && (ibuf->mall & IB_zbuffloat))
 
144
        if (ibuf->zbuf_float && (ibuf->mall & IB_zbuffloat))
145
145
                MEM_freeN(ibuf->zbuf_float);
146
146
 
147
147
        ibuf->zbuf_float= NULL;
150
150
 
151
151
void IMB_freeImBuf(ImBuf *ibuf)
152
152
{
153
 
        if(ibuf) {
154
 
                if(ibuf->refcounter > 0) {
 
153
        if (ibuf) {
 
154
                if (ibuf->refcounter > 0) {
155
155
                        ibuf->refcounter--;
156
156
                }
157
157
                else {
189
189
{
190
190
        int size;
191
191
        
192
 
        if(ibuf==NULL) return FALSE;
 
192
        if (ibuf==NULL) return FALSE;
193
193
        
194
194
        IMB_freezbufImBuf(ibuf);
195
195
        
196
196
        size = ibuf->x *ibuf->y *sizeof(unsigned int);
197
 
        if((ibuf->zbuf = MEM_mapallocN(size, "addzbufImBuf"))) {
 
197
        if ((ibuf->zbuf = MEM_mapallocN(size, "addzbufImBuf"))) {
198
198
                ibuf->mall |= IB_zbuf;
199
199
                ibuf->flags |= IB_zbuf;
200
200
                return TRUE;
207
207
{
208
208
        int size;
209
209
        
210
 
        if(ibuf==NULL) return FALSE;
 
210
        if (ibuf==NULL) return FALSE;
211
211
        
212
212
        IMB_freezbuffloatImBuf(ibuf);
213
213
        
214
214
        size = ibuf->x *ibuf->y *sizeof(float);
215
 
        if((ibuf->zbuf_float = MEM_mapallocN(size, "addzbuffloatImBuf"))) {
 
215
        if ((ibuf->zbuf_float = MEM_mapallocN(size, "addzbuffloatImBuf"))) {
216
216
                ibuf->mall |= IB_zbuffloat;
217
217
                ibuf->flags |= IB_zbuffloat;
218
218
                return TRUE;
224
224
 
225
225
short imb_addencodedbufferImBuf(ImBuf *ibuf)
226
226
{
227
 
        if(ibuf==NULL) return FALSE;
 
227
        if (ibuf==NULL) return FALSE;
228
228
 
229
229
        freeencodedbufferImBuf(ibuf);
230
230
 
231
 
        if(ibuf->encodedbuffersize == 0) 
 
231
        if (ibuf->encodedbuffersize == 0)
232
232
                ibuf->encodedbuffersize = 10000;
233
233
 
234
234
        ibuf->encodedsize = 0;
235
235
 
236
 
        if((ibuf->encodedbuffer = MEM_mallocN(ibuf->encodedbuffersize, "addencodedbufferImBuf"))) {
 
236
        if ((ibuf->encodedbuffer = MEM_mallocN(ibuf->encodedbuffersize, "addencodedbufferImBuf"))) {
237
237
                ibuf->mall |= IB_mem;
238
238
                ibuf->flags |= IB_mem;
239
239
                return TRUE;
248
248
        unsigned int newsize, encodedsize;
249
249
        void *newbuffer;
250
250
 
251
 
        if(ibuf==NULL) return FALSE;
 
251
        if (ibuf==NULL) return FALSE;
252
252
 
253
 
        if(ibuf->encodedbuffersize < ibuf->encodedsize) {
 
253
        if (ibuf->encodedbuffersize < ibuf->encodedsize) {
254
254
                printf("imb_enlargeencodedbufferImBuf: error in parameters\n");
255
255
                return FALSE;
256
256
        }
257
257
 
258
258
        newsize = 2 *ibuf->encodedbuffersize;
259
 
        if(newsize < 10000) newsize = 10000;
 
259
        if (newsize < 10000) newsize = 10000;
260
260
 
261
261
        newbuffer = MEM_mallocN(newsize, "enlargeencodedbufferImBuf");
262
 
        if(newbuffer == NULL) return FALSE;
 
262
        if (newbuffer == NULL) return FALSE;
263
263
 
264
 
        if(ibuf->encodedbuffer) {
 
264
        if (ibuf->encodedbuffer) {
265
265
                memcpy(newbuffer, ibuf->encodedbuffer, ibuf->encodedsize);
266
 
        } else {
 
266
        }
 
267
        else {
267
268
                ibuf->encodedsize = 0;
268
269
        }
269
270
 
284
285
{
285
286
        int size;
286
287
        
287
 
        if(ibuf==NULL) return FALSE;
 
288
        if (ibuf==NULL) return FALSE;
288
289
        
289
 
        if(ibuf->rect_float)
 
290
        if (ibuf->rect_float)
290
291
                imb_freerectfloatImBuf(ibuf); /* frees mipmap too, hrm */
291
292
        
292
293
        size = ibuf->x *ibuf->y;
293
294
        size = size *4 *sizeof(float);
294
295
        ibuf->channels= 4;
295
296
        
296
 
        if((ibuf->rect_float = MEM_mapallocN(size, "imb_addrectfloatImBuf"))) {
 
297
        if ((ibuf->rect_float = MEM_mapallocN(size, "imb_addrectfloatImBuf"))) {
297
298
                ibuf->mall |= IB_rectfloat;
298
299
                ibuf->flags |= IB_rectfloat;
299
300
                return TRUE;
307
308
{
308
309
        int size;
309
310
 
310
 
        if(ibuf==NULL) return FALSE;
 
311
        if (ibuf==NULL) return FALSE;
311
312
        
312
313
        /* don't call imb_freerectImBuf, it frees mipmaps, this call is used only too give float buffers display */
313
 
        if(ibuf->rect && (ibuf->mall & IB_rect))
 
314
        if (ibuf->rect && (ibuf->mall & IB_rect))
314
315
                MEM_freeN(ibuf->rect);
315
316
        ibuf->rect= NULL;
316
317
        
317
318
        size = ibuf->x*ibuf->y;
318
319
        size = size*sizeof(unsigned int);
319
320
 
320
 
        if((ibuf->rect = MEM_mapallocN(size, "imb_addrectImBuf"))) {
 
321
        if ((ibuf->rect = MEM_mapallocN(size, "imb_addrectImBuf"))) {
321
322
                ibuf->mall |= IB_rect;
322
323
                ibuf->flags |= IB_rect;
323
 
                if(ibuf->planes > 32) return (addzbufImBuf(ibuf));
 
324
                if (ibuf->planes > 32) return (addzbufImBuf(ibuf));
324
325
                else return TRUE;
325
326
        }
326
327
 
329
330
 
330
331
short imb_addtilesImBuf(ImBuf *ibuf)
331
332
{
332
 
        if(ibuf==NULL) return FALSE;
 
333
        if (ibuf==NULL) return FALSE;
333
334
 
334
 
        if(!ibuf->tiles)
335
 
                if((ibuf->tiles = MEM_callocN(sizeof(unsigned int*)*ibuf->xtiles*ibuf->ytiles, "imb_tiles")))
 
335
        if (!ibuf->tiles)
 
336
                if ((ibuf->tiles = MEM_callocN(sizeof(unsigned int*)*ibuf->xtiles*ibuf->ytiles, "imb_tiles")))
336
337
                        ibuf->mall |= IB_tiles;
337
338
 
338
339
        return (ibuf->tiles != NULL);
344
345
 
345
346
        ibuf = MEM_callocN(sizeof(ImBuf), "ImBuf_struct");
346
347
 
347
 
        if(ibuf) {
 
348
        if (ibuf) {
348
349
                ibuf->x= x;
349
350
                ibuf->y= y;
350
351
                ibuf->planes= planes;
352
353
                ibuf->channels= 4;      /* float option, is set to other values when buffers get assigned */
353
354
                ibuf->ppm[0]= ibuf->ppm[1]= 150.0 / 0.0254; /* 150dpi -> pixels-per-meter */
354
355
                
355
 
                if(flags & IB_rect) {
356
 
                        if(imb_addrectImBuf(ibuf)==FALSE) {
357
 
                                IMB_freeImBuf(ibuf);
358
 
                                return NULL;
359
 
                        }
360
 
                }
361
 
                
362
 
                if(flags & IB_rectfloat) {
363
 
                        if(imb_addrectfloatImBuf(ibuf)==FALSE) {
364
 
                                IMB_freeImBuf(ibuf);
365
 
                                return NULL;
366
 
                        }
367
 
                }
368
 
                
369
 
                if(flags & IB_zbuf) {
370
 
                        if(addzbufImBuf(ibuf)==FALSE) {
371
 
                                IMB_freeImBuf(ibuf);
372
 
                                return NULL;
373
 
                        }
374
 
                }
375
 
                
376
 
                if(flags & IB_zbuffloat) {
377
 
                        if(addzbuffloatImBuf(ibuf)==FALSE) {
 
356
                if (flags & IB_rect) {
 
357
                        if (imb_addrectImBuf(ibuf)==FALSE) {
 
358
                                IMB_freeImBuf(ibuf);
 
359
                                return NULL;
 
360
                        }
 
361
                }
 
362
                
 
363
                if (flags & IB_rectfloat) {
 
364
                        if (imb_addrectfloatImBuf(ibuf)==FALSE) {
 
365
                                IMB_freeImBuf(ibuf);
 
366
                                return NULL;
 
367
                        }
 
368
                }
 
369
                
 
370
                if (flags & IB_zbuf) {
 
371
                        if (addzbufImBuf(ibuf)==FALSE) {
 
372
                                IMB_freeImBuf(ibuf);
 
373
                                return NULL;
 
374
                        }
 
375
                }
 
376
                
 
377
                if (flags & IB_zbuffloat) {
 
378
                        if (addzbuffloatImBuf(ibuf)==FALSE) {
378
379
                                IMB_freeImBuf(ibuf);
379
380
                                return NULL;
380
381
                        }
390
391
        int flags = 0;
391
392
        int a, x, y;
392
393
        
393
 
        if(ibuf1 == NULL) return NULL;
 
394
        if (ibuf1 == NULL) return NULL;
394
395
 
395
 
        if(ibuf1->rect) flags |= IB_rect;
396
 
        if(ibuf1->rect_float) flags |= IB_rectfloat;
 
396
        if (ibuf1->rect) flags |= IB_rect;
 
397
        if (ibuf1->rect_float) flags |= IB_rectfloat;
397
398
 
398
399
        x = ibuf1->x;
399
400
        y = ibuf1->y;
400
 
        if(ibuf1->flags & IB_fields) y *= 2;
 
401
        if (ibuf1->flags & IB_fields) y *= 2;
401
402
        
402
403
        ibuf2 = IMB_allocImBuf(x, y, ibuf1->planes, flags);
403
 
        if(ibuf2 == NULL) return NULL;
 
404
        if (ibuf2 == NULL) return NULL;
404
405
 
405
 
        if(flags & IB_rect)
 
406
        if (flags & IB_rect)
406
407
                memcpy(ibuf2->rect, ibuf1->rect, x *y *sizeof(int));
407
408
        
408
 
        if(flags & IB_rectfloat)
 
409
        if (flags & IB_rectfloat)
409
410
                memcpy(ibuf2->rect_float, ibuf1->rect_float, ibuf1->channels *x *y *sizeof(float));
410
411
 
411
 
        if(ibuf1->encodedbuffer) {
 
412
        if (ibuf1->encodedbuffer) {
412
413
                ibuf2->encodedbuffersize = ibuf1->encodedbuffersize;
413
 
                if(imb_addencodedbufferImBuf(ibuf2) == FALSE) {
 
414
                if (imb_addencodedbufferImBuf(ibuf2) == FALSE) {
414
415
                        IMB_freeImBuf(ibuf2);
415
416
                        return NULL;
416
417
                }
427
428
        tbuf.encodedbuffer = ibuf2->encodedbuffer;
428
429
        tbuf.zbuf= NULL;
429
430
        tbuf.zbuf_float= NULL;
430
 
        for(a=0; a<IB_MIPMAP_LEVELS; a++)
 
431
        for (a=0; a<IB_MIPMAP_LEVELS; a++)
431
432
                tbuf.mipmap[a]= NULL;
432
433
        
433
434
        // set malloc flag
464
465
{
465
466
        static MEM_CacheLimiterC *c = NULL;
466
467
 
467
 
        if(!c)
 
468
        if (!c)
468
469
                c = new_MEM_CacheLimiter(imbuf_cache_destructor, NULL);
469
470
 
470
471
        return &c;