~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/image_gen.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
 
/*  image_gen.c 
2
 
 * 
3
 
 * $Id: image_gen.c 28341 2010-04-22 10:56:45Z bdiego $
4
 
 *
 
1
/*
5
2
 * ***** BEGIN GPL LICENSE BLOCK *****
6
3
 *
7
4
 * This program is free software; you can redistribute it and/or
23
20
 * ***** END GPL LICENSE BLOCK *****
24
21
 */
25
22
 
 
23
/** \file blender/blenkernel/intern/image_gen.c
 
24
 *  \ingroup bke
 
25
 */
 
26
 
 
27
 
26
28
#include <math.h>
27
29
#include <stdlib.h>
 
30
 
 
31
#include "BKE_image.h"
28
32
#include "BLI_math_color.h"
 
33
#include "BLI_math_base.h"
29
34
#include "BLF_api.h"
30
35
 
31
 
void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4])
 
36
void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4])
32
37
{
33
38
        int x, y;
34
39
 
35
40
        /* blank image */
36
 
        if(rect_float) {
37
 
                for(y= 0; y<height; y++) {
38
 
                        for(x= 0; x<width; x++) {
39
 
                                rect_float[0]= color[0];
40
 
                                rect_float[1]= color[1];
41
 
                                rect_float[2]= color[2];
42
 
                                rect_float[3]= color[3];
 
41
        if (rect_float) {
 
42
                for (y= 0; y<height; y++) {
 
43
                        for (x= 0; x<width; x++) {
 
44
                                copy_v4_v4(rect_float, color);
43
45
                                rect_float+= 4;
44
46
                        }
45
47
                }
46
48
        }
47
49
        
48
 
        if(rect) {
49
 
                char ccol[4];
50
 
 
51
 
                ccol[0]= (char)(color[0]*255.0f);
52
 
                ccol[1]= (char)(color[1]*255.0f);
53
 
                ccol[2]= (char)(color[2]*255.0f);
54
 
                ccol[3]= (char)(color[3]*255.0f);
55
 
                for(y= 0; y<height; y++) {
56
 
                        for(x= 0; x<width; x++) {
 
50
        if (rect) {
 
51
                unsigned char ccol[4];
 
52
 
 
53
                rgba_float_to_uchar(ccol, color);
 
54
 
 
55
                for (y= 0; y<height; y++) {
 
56
                        for (x= 0; x<width; x++) {
57
57
                                
58
58
                                rect[0]= ccol[0];
59
59
                                rect[1]= ccol[1];
69
69
void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int width, int height)
70
70
{
71
71
        /* these two passes could be combined into one, but it's more readable and 
72
 
        * easy to tweak like this, speed isn't really that much of an issue in this situation... */
 
72
         * easy to tweak like this, speed isn't really that much of an issue in this situation... */
73
73
 
74
74
        int checkerwidth= 32, dark= 1;
75
75
        int x, y;
76
 
    
 
76
 
77
77
        unsigned char *rect_orig= rect;
78
78
        float *rect_float_orig= rect_float;
79
 
    
 
79
 
80
80
        
81
81
        float h=0.0, hoffs=0.0, hue=0.0, s=0.9, v=0.9, r, g, b;
82
82
 
83
83
        /* checkers */
84
 
        for(y= 0; y<height; y++) {
 
84
        for (y= 0; y<height; y++) {
85
85
                dark= powf(-1.0f, floorf(y / checkerwidth));
86
86
                
87
 
                for(x= 0; x<width; x++) {
 
87
                for (x= 0; x<width; x++) {
88
88
                        if (x % checkerwidth == 0) dark= -dark;
89
89
                        
90
90
                        if (rect_float) {
91
91
                                if (dark > 0) {
92
92
                                        rect_float[0]= rect_float[1]= rect_float[2]= 0.25f;
93
93
                                        rect_float[3]= 1.0f;
94
 
                                } else {
 
94
                                }
 
95
                                else {
95
96
                                        rect_float[0]= rect_float[1]= rect_float[2]= 0.58f;
96
97
                                        rect_float[3]= 1.0f;
97
98
                                }
101
102
                                if (dark > 0) {
102
103
                                        rect[0]= rect[1]= rect[2]= 64;
103
104
                                        rect[3]= 255;
104
 
                                } else {
 
105
                                }
 
106
                                else {
105
107
                                        rect[0]= rect[1]= rect[2]= 150;
106
108
                                        rect[3]= 255;
107
109
                                }
114
116
        rect_float= rect_float_orig;
115
117
 
116
118
        /* 2nd pass, colored + */
117
 
        for(y= 0; y<height; y++) {
 
119
        for (y= 0; y<height; y++) {
118
120
                hoffs= 0.125f * floorf(y / checkerwidth);
119
121
                
120
 
                for(x= 0; x<width; x++) {
 
122
                for (x= 0; x<width; x++) {
121
123
                        h= 0.125f * floorf(x / checkerwidth);
122
124
                        
123
125
                        if ((fabs((x % checkerwidth) - (checkerwidth / 2)) < 4) &&
154
156
 
155
157
/* Utility functions for BKE_image_buf_fill_checker_color */
156
158
 
157
 
#define BLEND_FLOAT(real, add)  (real+add <= 1.0) ? (real+add) : 1.0
158
 
#define BLEND_CHAR(real, add) ((real + (char)(add * 255.0)) <= 255) ? (real + (char)(add * 255.0)) : 255
159
 
 
160
 
static int is_pow2(int n)
161
 
{
162
 
        return ((n)&(n-1))==0;
163
 
}
164
 
static int larger_pow2(int n)
165
 
{
166
 
        if (is_pow2(n))
167
 
                return n;
168
 
 
169
 
        while(!is_pow2(n))
170
 
                n= n&(n-1);
171
 
 
172
 
        return n*2;
173
 
}
 
159
#define BLEND_FLOAT(real, add)  (real+add <= 1.0f) ? (real+add) : 1.0f
 
160
#define BLEND_CHAR(real, add) ((real + (char)(add * 255.0f)) <= 255) ? (real + (char)(add * 255.0f)) : 255
174
161
 
175
162
static void checker_board_color_fill(unsigned char *rect, float *rect_float, int width, int height)
176
163
{
179
166
 
180
167
        sat= 1.0;
181
168
 
182
 
        hue_step= larger_pow2(width / 8);
183
 
        if(hue_step < 8) hue_step= 8;
 
169
        hue_step= power_of_2_max_i(width / 8);
 
170
        if (hue_step < 8) hue_step= 8;
184
171
 
185
 
        for(y= 0; y < height; y++)
 
172
        for (y= 0; y < height; y++)
186
173
        {
187
 
        
 
174
 
188
175
                val= 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */
189
 
                for(x= 0; x < width; x++)
 
176
                for (x= 0; x < width; x++)
190
177
                {
191
178
                        hue= (float)((double)(x/hue_step) * 1.0 / width * hue_step);
192
179
                        hsv_to_rgb(hue, sat, val, &r, &g, &b);
217
204
        int x, y;
218
205
        float blend_half= blend * 0.5f;
219
206
 
220
 
        for(y= 0; y < height; y++)
221
 
        {
222
 
                for(x= 0; x < width; x++)
223
 
                {
224
 
                        if( ( (y/size)%2 == 1 && (x/size)%2 == 1 ) || ( (y/size)%2 == 0 && (x/size)%2 == 0 ) )
225
 
                        {
 
207
        for (y= 0; y < height; y++) {
 
208
                for (x= 0; x < width; x++) {
 
209
                        if (((y / size) % 2 == 1 && (x / size) % 2 == 1 ) || ( (y / size) % 2 == 0 && (x / size) % 2 == 0 )) {
226
210
                                if (rect) {
227
211
                                        rect[0]= (char)BLEND_CHAR(rect[0], blend);
228
212
                                        rect[1]= (char)BLEND_CHAR(rect[1], blend);
266
250
static void checker_board_grid_fill(unsigned char *rect, float *rect_float, int width, int height, float blend)
267
251
{
268
252
        int x, y;
269
 
        for(y= 0; y < height; y++)
270
 
        {
271
 
                for(x= 0; x < width; x++)
272
 
                {
273
 
                        if( ((y % 32) == 0) || ((x % 32) == 0)  || x == 0 )
274
 
                        {
 
253
        for (y= 0; y < height; y++) {
 
254
                for (x= 0; x < width; x++) {
 
255
                        if (((y % 32) == 0) || ((x % 32) == 0)  || x == 0) {
275
256
                                if (rect) {
276
257
                                        rect[0]= BLEND_CHAR(rect[0], blend);
277
258
                                        rect[1]= BLEND_CHAR(rect[1], blend);
290
271
                                }
291
272
                        }
292
273
                        else {
293
 
                                if(rect_float) rect_float += 4;
294
 
                                if(rect) rect += 4;
 
274
                                if (rect_float) rect_float += 4;
 
275
                                if (rect) rect += 4;
295
276
                        }
296
277
                }
297
278
        }
298
279
}
299
280
 
300
281
/* defined in image.c */
301
 
extern int stamp_font_begin(int size);
302
282
 
303
283
static void checker_board_text(unsigned char *rect, float *rect_float, int width, int height, int step, int outline)
304
284
{
305
 
        int x, y, mono;
 
285
        int x, y;
306
286
        int pen_x, pen_y;
307
287
        char text[3]= {'A', '1', '\0'};
308
 
 
309
 
        /* hard coded size! */
310
 
        mono= stamp_font_begin(54);
 
288
        const int mono= blf_mono_font;
 
289
 
 
290
        BLF_size(mono, 54, 72); /* hard coded size! */
 
291
 
311
292
        BLF_buffer(mono, rect_float, rect, width, height, 4);
312
 
    
313
 
        for(y= 0; y < height; y+=step)
 
293
 
 
294
        for (y= 0; y < height; y+=step)
314
295
        {
315
296
                text[1]= '1';
316
 
        
317
 
                for(x= 0; x < width; x+=step)
 
297
 
 
298
                for (x= 0; x < width; x+=step)
318
299
                {
319
300
                        /* hard coded offset */
320
301
                        pen_x = x + 33;
321
302
                        pen_y = y + 44;
322
 
            
 
303
 
323
304
                        /* terribly crappy outline font! */
324
305
                        BLF_buffer_col(mono, 1.0, 1.0, 1.0, 1.0);
325
306
 
331
312
                        BLF_draw_buffer(mono, text);
332
313
                        BLF_position(mono, pen_x, pen_y+outline, 0.0);
333
314
                        BLF_draw_buffer(mono, text);
334
 
            
 
315
 
335
316
                        BLF_position(mono, pen_x-outline, pen_y-outline, 0.0);
336
317
                        BLF_draw_buffer(mono, text);
337
318
                        BLF_position(mono, pen_x+outline, pen_y+outline, 0.0);
344
325
                        BLF_buffer_col(mono, 0.0, 0.0, 0.0, 1.0);
345
326
                        BLF_position(mono, pen_x, pen_y, 0.0);
346
327
                        BLF_draw_buffer(mono, text);
347
 
            
 
328
 
348
329
                        text[1]++;
349
330
                }
350
331
                text[0]++;
351
332
        }
352
 
    
 
333
 
353
334
        /* cleanup the buffer. */
354
335
        BLF_buffer(mono, NULL, NULL, 0, 0, 0);
355
336
}