~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * $Id: thumbs_blend.c 30425 2010-07-17 00:38:34Z campbellbarton $
3
 
 *
 
1
/*
4
2
 * ***** BEGIN GPL LICENSE BLOCK *****
5
3
 *
6
4
 * This program is free software; you can redistribute it and/or
22
20
 * ***** END GPL LICENSE BLOCK *****
23
21
 */
24
22
 
 
23
/** \file blender/imbuf/intern/thumbs_blend.c
 
24
 *  \ingroup imbuf
 
25
 */
 
26
 
 
27
 
25
28
#include <string.h>
26
29
 
27
30
#include "zlib.h"
28
31
 
 
32
#include "BLI_utildefines.h"
 
33
#include "BLI_fileops.h"
 
34
 
29
35
#include "BKE_utildefines.h"
30
36
#include "BKE_global.h"
31
37
 
36
42
#include "MEM_guardedalloc.h"
37
43
 
38
44
/* extracts the thumbnail from between the 'REND' and the 'GLOB'
39
 
 * chunks of the header, dont use typical blend loader because its too slow */
 
45
 * chunks of the header, don't use typical blend loader because its too slow */
40
46
 
41
47
static ImBuf *loadblend_thumb(gzFile gzfile)
42
48
{
44
50
        int bhead[24/sizeof(int)]; /* max size on 64bit */
45
51
        char endian, pointer_size;
46
52
        char endian_switch;
47
 
        int sizeof_bhead ;
 
53
        int sizeof_bhead;
48
54
 
49
55
        /* read the blend file header */
50
 
        if(gzread(gzfile, buf, 12) != 12)
 
56
        if (gzread(gzfile, buf, 12) != 12)
51
57
                return NULL;
52
 
        if(strncmp(buf, "BLENDER", 7))
 
58
        if (strncmp(buf, "BLENDER", 7))
53
59
                return NULL;
54
60
 
55
 
        if(buf[7]=='-')
 
61
        if (buf[7]=='-')
56
62
                pointer_size= 8;
57
 
        else if(buf[7]=='_')
 
63
        else if (buf[7]=='_')
58
64
                pointer_size= 4;
59
65
        else
60
66
                return NULL;
61
67
 
62
 
         sizeof_bhead = 16 + pointer_size;
 
68
        sizeof_bhead = 16 + pointer_size;
63
69
 
64
 
        if(buf[8]=='V')
 
70
        if (buf[8]=='V')
65
71
                endian= B_ENDIAN; /* big: PPC */
66
 
        else if(buf[8]=='v')
 
72
        else if (buf[8]=='v')
67
73
                endian= L_ENDIAN; /* little: x86 */
68
74
        else
69
75
                return NULL;
70
76
 
71
77
        endian_switch = ((ENDIAN_ORDER != endian)) ? 1 : 0;
72
78
 
73
 
        while(gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) {
74
 
                if(endian_switch)
 
79
        while (gzread(gzfile, bhead, sizeof_bhead) == sizeof_bhead) {
 
80
                if (endian_switch)
75
81
                        SWITCH_INT(bhead[1]); /* length */
76
82
 
77
83
                if (bhead[0]==REND) {
83
89
        }
84
90
 
85
91
        /* using 'TEST' since new names segfault when loading in old blenders */
86
 
        if(bhead[0] == TEST) {
 
92
        if (bhead[0] == TEST) {
87
93
                ImBuf *img= NULL;
88
94
                int size[2];
89
95
 
90
 
                if(gzread(gzfile, size, sizeof(size)) != sizeof(size))
 
96
                if (gzread(gzfile, size, sizeof(size)) != sizeof(size))
91
97
                        return NULL;
92
98
 
93
 
                if(endian_switch) {
 
99
                if (endian_switch) {
94
100
                        SWITCH_INT(size[0]);
95
101
                        SWITCH_INT(size[1]);
96
102
                }
97
103
                /* length */
98
104
                bhead[1] -= sizeof(int) * 2;
99
105
 
100
 
                /* inconsistant image size, quit early */
101
 
                if(bhead[1] != size[0] * size[1] * sizeof(int))
 
106
                /* inconsistent image size, quit early */
 
107
                if (bhead[1] != size[0] * size[1] * sizeof(int))
102
108
                        return NULL;
103
109
        
104
110
                /* finally malloc and read the data */
105
 
                img= IMB_allocImBuf(size[0], size[1], 32, IB_rect | IB_metadata, 0);
 
111
                img= IMB_allocImBuf(size[0], size[1], 32, IB_rect | IB_metadata);
106
112
        
107
 
                if(gzread(gzfile, img->rect, bhead[1]) != bhead[1]) {
 
113
                if (gzread(gzfile, img->rect, bhead[1]) != bhead[1]) {
108
114
                        IMB_freeImBuf(img);
109
115
                        img= NULL;
110
116
                }
118
124
ImBuf *IMB_loadblend_thumb(const char *path)
119
125
{
120
126
        gzFile gzfile;
121
 
 
122
127
        /* not necessarily a gzip */
123
 
        gzfile = gzopen(path, "rb");
 
128
        gzfile = BLI_gzopen(path, "rb");
124
129
 
125
130
        if (NULL == gzfile ) {
126
131
                return NULL;
146
151
        int margin_r = width - MARGIN;
147
152
        int margin_t = height - MARGIN;
148
153
 
149
 
        if(aspect < 1.0f) {
 
154
        if (aspect < 1.0f) {
150
155
                margin_l= (int)((width - ((float)width * aspect)) / 2.0f);
151
156
                margin_l += MARGIN;
152
157
                CLAMP(margin_l, MARGIN, (width/2));
161
166
 
162
167
        {       
163
168
                int x, y;
164
 
                int hline, vline;
165
169
                int stride_x= (margin_r - margin_l) - 2;
166
170
                
167
 
                for(y=0; y < height; y++) {
168
 
                        for(x=0; x < width; x++, px+=4) {
169
 
                                if((x > margin_l && x < margin_r) && (y > margin_b && y < margin_t)) {
 
171
                for (y=0; y < height; y++) {
 
172
                        for (x=0; x < width; x++, px+=4) {
 
173
                                int hline= 0, vline= 0;
 
174
                                if ((x > margin_l && x < margin_r) && (y > margin_b && y < margin_t)) {
170
175
                                        /* interior. skip */
171
176
                                        x  += stride_x;
172
177
                                        px += stride_x * 4;
173
 
                                } else if(      (hline=(((x == margin_l || x == margin_r)) && y >= margin_b && y <= margin_t)) ||
174
 
                                                        (vline=(((y == margin_b || y == margin_t)) && x >= margin_l && x <= margin_r))
175
 
                                ) {
 
178
                                }
 
179
                                else if ((hline=(((x == margin_l || x == margin_r)) && y >= margin_b && y <= margin_t)) ||
 
180
                                        (vline=(((y == margin_b || y == margin_t)) && x >= margin_l && x <= margin_r)))
 
181
                                {
176
182
                                        /* dashed line */
177
 
                                        if((hline && y % 2) || (vline && x % 2)) {
 
183
                                        if ((hline && y % 2) || (vline && x % 2)) {
178
184
                                                px[0]= px[1]= px[2]= 0;
179
185
                                                px[3] = 255;
180
186
                                        }