本文整理汇总了C++中FTOCHAR函数的典型用法代码示例。如果您正苦于以下问题:C++ FTOCHAR函数的具体用法?C++ FTOCHAR怎么用?C++ FTOCHAR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FTOCHAR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: draw_zebra_float
static void draw_zebra_float(ImBuf *src, ImBuf *ibuf, float perc)
{
float limit = perc / 100.0f;
const float *p = src->rect_float;
unsigned char *o = (unsigned char *) ibuf->rect;
int x;
int y;
for (y = 0; y < ibuf->y; y++) {
for (x = 0; x < ibuf->x; x++) {
float r = *p++;
float g = *p++;
float b = *p++;
float a = *p++;
if (r >= limit || g >= limit || b >= limit) {
if (((x + y) & 0x08) != 0) {
r = -r;
g = -g;
b = -b;
}
}
*o++ = FTOCHAR(r);
*o++ = FTOCHAR(g);
*o++ = FTOCHAR(b);
*o++ = FTOCHAR(a);
}
}
}
开发者ID:Andrewson3D,项目名称:blender-for-vray,代码行数:30,代码来源:sequencer_scopes.c
示例2: norm
/* MultiresBake callback for normals' baking
general idea:
- find coord and normal of point with specified UV in hi-res mesh
- multiply it by tangmat
- vector in color space would be norm(vec) /2 + (0.5, 0.5, 0.5) */
static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, const void *UNUSED(bake_data),
const int face_index, const int lvl, const float st[2],
float tangmat[3][3], const int x, const int y)
{
MTFace *mtface= CustomData_get_layer(&lores_dm->faceData, CD_MTFACE);
MFace mface;
Image *ima= mtface[face_index].tpage;
ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL);
float uv[2], *st0, *st1, *st2, *st3;
int pixel= ibuf->x*y + x;
float n[3], vec[3], tmp[3]= {0.5, 0.5, 0.5};
lores_dm->getFace(lores_dm, face_index, &mface);
st0= mtface[face_index].uv[0];
st1= mtface[face_index].uv[1];
st2= mtface[face_index].uv[2];
if(mface.v4) {
st3= mtface[face_index].uv[3];
resolve_quad_uv(uv, st, st0, st1, st2, st3);
} else
resolve_tri_uv(uv, st, st0, st1, st2);
CLAMP(uv[0], 0.0f, 1.0f);
CLAMP(uv[1], 0.0f, 1.0f);
get_ccgdm_data(lores_dm, hires_dm, lvl, face_index, uv[0], uv[1], NULL, n);
mul_v3_m3v3(vec, tangmat, n);
normalize_v3(vec);
mul_v3_fl(vec, 0.5);
add_v3_v3(vec, tmp);
if(ibuf->rect_float) {
float *rrgbf= ibuf->rect_float + pixel*4;
rrgbf[0]= vec[0];
rrgbf[1]= vec[1];
rrgbf[2]= vec[2];
rrgbf[3]= 1.0f;
ibuf->userflags= IB_RECT_INVALID;
} else {
char *rrgb= (char*)ibuf->rect + pixel*4;
rrgb[0]= FTOCHAR(vec[0]);
rrgb[1]= FTOCHAR(vec[1]);
rrgb[2]= FTOCHAR(vec[2]);
rrgb[3]= 255;
}
}
开发者ID:BHCLL,项目名称:blendocv,代码行数:55,代码来源:object_bake.c
示例3: curvemapping_evaluate_premulRGB
/* same as above, byte version */
void curvemapping_evaluate_premulRGB(const CurveMapping *cumap, unsigned char vecout_byte[3], const unsigned char vecin_byte[3])
{
float vecin[3], vecout[3];
vecin[0] = (float) vecin_byte[0] / 255.0f;
vecin[1] = (float) vecin_byte[1] / 255.0f;
vecin[2] = (float) vecin_byte[2] / 255.0f;
curvemapping_evaluate_premulRGBF(cumap, vecout, vecin);
vecout_byte[0] = FTOCHAR(vecout[0]);
vecout_byte[1] = FTOCHAR(vecout[1]);
vecout_byte[2] = FTOCHAR(vecout[2]);
}
开发者ID:scorpion81,项目名称:blender-voro,代码行数:15,代码来源:colortools.c
示例4: apply_heights_data
static void apply_heights_data(void *bake_data)
{
MHeightBakeData *height_data= (MHeightBakeData*)bake_data;
ImBuf *ibuf= BKE_image_get_ibuf(height_data->ima, NULL);
int x, y, i;
float height, *heights= height_data->heights;
float min= height_data->height_min, max= height_data->height_max;
for(x= 0; x<ibuf->x; x++) {
for(y =0; y<ibuf->y; y++) {
i= ibuf->x*y + x;
if(((char*)ibuf->userdata)[i] != FILTER_MASK_USED)
continue;
if(ibuf->rect_float) {
float *rrgbf= ibuf->rect_float + i*4;
if(max-min > 1e-5f) height= (heights[i]-min)/(max-min);
else height= 0;
rrgbf[0]=rrgbf[1]=rrgbf[2]= height;
} else {
char *rrgb= (char*)ibuf->rect + i*4;
if(max-min > 1e-5f) height= (heights[i]-min)/(max-min);
else height= 0;
rrgb[0]=rrgb[1]=rrgb[2]= FTOCHAR(height);
}
}
}
ibuf->userflags= IB_RECT_INVALID;
}
开发者ID:ryden,项目名称:blender-mirror,代码行数:35,代码来源:object_bake.c
示例5: rna_Image_pixels_set
static void rna_Image_pixels_set(PointerRNA *ptr, const float *values)
{
Image *ima = ptr->id.data;
ImBuf *ibuf;
void *lock;
int i, size;
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
if (ibuf) {
size = ibuf->x * ibuf->y * ibuf->channels;
if (ibuf->rect_float) {
memcpy(ibuf->rect_float, values, sizeof(float) * size);
}
else {
for (i = 0; i < size; i++)
((unsigned char *)ibuf->rect)[i] = FTOCHAR(values[i]);
}
ibuf->userflags |= IB_BITMAPDIRTY | IB_DISPLAY_BUFFER_INVALID;
}
BKE_image_release_ibuf(ima, ibuf, lock);
}
开发者ID:silkentrance,项目名称:blender,代码行数:25,代码来源:rna_image.c
示例6: float_to_byte_dither_v4
MINLINE void float_to_byte_dither_v4(uchar b[4], const float f[4], DitherContext *di, float s, float t)
{
float dither_value = dither_random_value(s, t) * 0.005f * di->dither;
b[0] = ftochar(dither_value + f[0]);
b[1] = ftochar(dither_value + f[1]);
b[2] = ftochar(dither_value + f[2]);
b[3] = FTOCHAR(f[3]);
}
开发者ID:linkedinyou,项目名称:blender-git,代码行数:9,代码来源:divers.c
示例7: IMB_colormanagement_get_luminance_byte
/* Byte equivalent of IMB_colormanagement_get_luminance(). */
unsigned char IMB_colormanagement_get_luminance_byte(const unsigned char rgb[3])
{
float rgbf[3];
float val;
rgb_uchar_to_float(rgbf, rgb);
val = dot_v3v3(imbuf_luma_coefficients, rgbf);
return FTOCHAR(val);
}
开发者ID:DarkDefender,项目名称:blender-npr-tess2,代码行数:11,代码来源:colormanagement_inline.c
示例8: switch
void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol)
{
int stride = mVData->getStride(0);
if (stride == 0) stride = 3;
switch (mVData->getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
{
COLLADAFW::ArrayPrimitiveType<float> *values = mVData->getFloatValues();
if (values->empty() || values->getCount() <= (v_index * stride + 2)) return; // xxx need to create an eror instead
mloopcol->r = FTOCHAR((*values)[v_index * stride]);
mloopcol->g = FTOCHAR((*values)[v_index * stride + 1]);
mloopcol->b = FTOCHAR((*values)[v_index * stride + 2]);
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE:
{
COLLADAFW::ArrayPrimitiveType<double> *values = mVData->getDoubleValues();
if (values->empty() || values->getCount() <= (v_index * stride + 2)) return; // xxx need to create an eror instead
mloopcol->r = FTOCHAR((*values)[v_index * stride]);
mloopcol->g = FTOCHAR((*values)[v_index * stride + 1]);
mloopcol->b = FTOCHAR((*values)[v_index * stride + 2]);
}
break;
default:
fprintf(stderr, "VCOLDataWrapper.getvcol(): unknown data type\n");
}
}
开发者ID:Andrewson3D,项目名称:blender-for-vray,代码行数:32,代码来源:MeshImporter.cpp
示例9: MEM_callocN
static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixels)
{
unsigned char *pixels, *p;
const float *fp = fpixels;
const int len = 4 * length;
p = pixels = MEM_callocN(sizeof(unsigned char) * len, "GPUTexturePixels");
for (int a = 0; a < len; a++, p++, fp++)
*p = FTOCHAR((*fp));
return pixels;
}
开发者ID:GameLemur,项目名称:blender,代码行数:13,代码来源:gpu_texture.c
示例10: lockMutex
void *AntiAliasOperation::initializeTileData(rcti *rect)
{
if (this->m_buffer) { return this->m_buffer; }
lockMutex();
if (this->m_buffer == NULL) {
MemoryBuffer *tile = (MemoryBuffer *)this->m_valueReader->initializeTileData(rect);
int size = tile->getHeight() * tile->getWidth();
float *input = tile->getBuffer();
char *valuebuffer = (char *)MEM_mallocN(sizeof(char) * size, __func__);
for (int i = 0; i < size; i++) {
float in = input[i * COM_NUMBER_OF_CHANNELS];
valuebuffer[i] = FTOCHAR(in);
}
antialias_tagbuf(tile->getWidth(), tile->getHeight(), valuebuffer);
this->m_buffer = valuebuffer;
}
unlockMutex();
return this->m_buffer;
}
开发者ID:BlueLabelStudio,项目名称:blender,代码行数:19,代码来源:COM_AntiAliasOperation.cpp
示例11: rna_ImagePreview_pixels_float_set
static void rna_ImagePreview_pixels_float_set(PointerRNA *ptr, const float *values, enum eIconSizes size)
{
ID *id = ptr->id.data;
PreviewImage *prv_img = (PreviewImage *)ptr->data;
unsigned char *data = (unsigned char *)prv_img->rect[size];
const size_t len = prv_img->w[size] * prv_img->h[size] * 4;
size_t i;
BLI_assert(sizeof(unsigned int) == 4);
if (id != NULL) {
BLI_assert(prv_img == BKE_previewimg_id_ensure(id));
}
for (i = 0; i < len; i++) {
data[i] = FTOCHAR(values[i]);
}
prv_img->flag[size] |= PRV_USER_EDITED;
}
开发者ID:pawkoz,项目名称:dyplom,代码行数:20,代码来源:rna_ID.c
示例12: IMB_colormanagement_display_get_named
/* create imbuf with brush color */
static ImBuf *brush_painter_imbuf_new(BrushPainter *painter, int size, float pressure, float distance)
{
Scene *scene = painter->scene;
Brush *brush = painter->brush;
const char *display_device = scene->display_settings.display_device;
struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
rctf tex_mapping = painter->tex_mapping;
struct ImagePool *pool = painter->pool;
bool use_color_correction = painter->cache.use_color_correction;
bool use_float = painter->cache.use_float;
bool is_texbrush = painter->cache.is_texbrush;
int x, y, thread = 0;
float brush_rgb[3];
/* allocate image buffer */
ImBuf *ibuf = IMB_allocImBuf(size, size, 32, (use_float) ? IB_rectfloat : IB_rect);
/* get brush color */
if (brush->imagepaint_tool == PAINT_TOOL_DRAW) {
paint_brush_color_get(scene, brush, use_color_correction, painter->cache.invert, distance, pressure, brush_rgb, display);
}
else {
brush_rgb[0] = 1.0f;
brush_rgb[1] = 1.0f;
brush_rgb[2] = 1.0f;
}
/* fill image buffer */
for (y = 0; y < size; y++) {
for (x = 0; x < size; x++) {
/* sample texture and multiply with brush color */
float texco[3], rgba[4];
if (is_texbrush) {
brush_imbuf_tex_co(&tex_mapping, x, y, texco);
BKE_brush_sample_tex_3D(scene, brush, texco, rgba, thread, pool);
/* TODO(sergey): Support texture paint color space. */
if (!use_float) {
IMB_colormanagement_scene_linear_to_display_v3(rgba, display);
}
mul_v3_v3(rgba, brush_rgb);
}
else {
copy_v3_v3(rgba, brush_rgb);
rgba[3] = 1.0f;
}
if (use_float) {
/* write to float pixel */
float *dstf = ibuf->rect_float + (y * size + x) * 4;
mul_v3_v3fl(dstf, rgba, rgba[3]); /* premultiply */
dstf[3] = rgba[3];
}
else {
/* write to byte pixel */
unsigned char *dst = (unsigned char *)ibuf->rect + (y * size + x) * 4;
rgb_float_to_uchar(dst, rgba);
dst[3] = FTOCHAR(rgba[3]);
}
}
}
return ibuf;
}
开发者ID:DrangPo,项目名称:blender,代码行数:70,代码来源:paint_image_2d.c
示例13: IMB_buffer_byte_from_float
/* float to byte pixels, output 4-channel RGBA */
void IMB_buffer_byte_from_float(uchar *rect_to, const float *rect_from,
int channels_from, float dither, int profile_to, int profile_from, bool predivide,
int width, int height, int stride_to, int stride_from)
{
float tmp[4];
int x, y;
DitherContext *di = NULL;
float inv_width = 1.0f / width,
inv_height = 1.0f / height;
/* we need valid profiles */
BLI_assert(profile_to != IB_PROFILE_NONE);
BLI_assert(profile_from != IB_PROFILE_NONE);
if (dither)
di = create_dither_context(dither);
for (y = 0; y < height; y++) {
float t = y * inv_height;
if (channels_from == 1) {
/* single channel input */
const float *from = rect_from + stride_from * y;
uchar *to = rect_to + stride_to * y * 4;
for (x = 0; x < width; x++, from++, to += 4)
to[0] = to[1] = to[2] = to[3] = FTOCHAR(from[0]);
}
else if (channels_from == 3) {
/* RGB input */
const float *from = rect_from + stride_from * y * 3;
uchar *to = rect_to + stride_to * y * 4;
if (profile_to == profile_from) {
/* no color space conversion */
for (x = 0; x < width; x++, from += 3, to += 4) {
rgb_float_to_uchar(to, from);
to[3] = 255;
}
}
else if (profile_to == IB_PROFILE_SRGB) {
/* convert from linear to sRGB */
for (x = 0; x < width; x++, from += 3, to += 4) {
linearrgb_to_srgb_v3_v3(tmp, from);
rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
else if (profile_to == IB_PROFILE_LINEAR_RGB) {
/* convert from sRGB to linear */
for (x = 0; x < width; x++, from += 3, to += 4) {
srgb_to_linearrgb_v3_v3(tmp, from);
rgb_float_to_uchar(to, tmp);
to[3] = 255;
}
}
}
else if (channels_from == 4) {
/* RGBA input */
const float *from = rect_from + stride_from * y * 4;
uchar *to = rect_to + stride_to * y * 4;
if (profile_to == profile_from) {
float straight[4];
/* no color space conversion */
if (dither && predivide) {
for (x = 0; x < width; x++, from += 4, to += 4) {
premul_to_straight_v4_v4(straight, from);
float_to_byte_dither_v4(to, straight, di, (float) x * inv_width, t);
}
}
else if (dither) {
for (x = 0; x < width; x++, from += 4, to += 4)
float_to_byte_dither_v4(to, from, di, (float) x * inv_width, t);
}
else if (predivide) {
for (x = 0; x < width; x++, from += 4, to += 4) {
premul_to_straight_v4_v4(straight, from);
rgba_float_to_uchar(to, straight);
}
}
else {
for (x = 0; x < width; x++, from += 4, to += 4)
rgba_float_to_uchar(to, from);
}
}
else if (profile_to == IB_PROFILE_SRGB) {
/* convert from linear to sRGB */
unsigned short us[4];
float straight[4];
if (dither && predivide) {
for (x = 0; x < width; x++, from += 4, to += 4) {
premul_to_straight_v4_v4(straight, from);
linearrgb_to_srgb_ushort4(us, from);
ushort_to_byte_dither_v4(to, us, di, (float) x * inv_width, t);
}
}
//.........这里部分代码省略.........
开发者ID:linkedinyou,项目名称:blender-git,代码行数:101,代码来源:divers.c
示例14: image_buffer_rect_update
/* called inside thread! */
void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volatile rcti *renrect)
{
float x1, y1, *rectf= NULL;
int ymin, ymax, xmin, xmax;
int rymin, rxmin, do_color_management;
char *rectc;
/* if renrect argument, we only refresh scanlines */
if(renrect) {
/* if ymax==recty, rendering of layer is ready, we should not draw, other things happen... */
if(rr->renlay==NULL || renrect->ymax>=rr->recty)
return;
/* xmin here is first subrect x coord, xmax defines subrect width */
xmin = renrect->xmin + rr->crop;
xmax = renrect->xmax - xmin + rr->crop;
if(xmax<2)
return;
ymin= renrect->ymin + rr->crop;
ymax= renrect->ymax - ymin + rr->crop;
if(ymax<2)
return;
renrect->ymin= renrect->ymax;
}
else {
xmin = ymin = rr->crop;
xmax = rr->rectx - 2*rr->crop;
ymax = rr->recty - 2*rr->crop;
}
/* xmin ymin is in tile coords. transform to ibuf */
rxmin= rr->tilerect.xmin + xmin;
if(rxmin >= ibuf->x) return;
rymin= rr->tilerect.ymin + ymin;
if(rymin >= ibuf->y) return;
if(rxmin + xmax > ibuf->x)
xmax= ibuf->x - rxmin;
if(rymin + ymax > ibuf->y)
ymax= ibuf->y - rymin;
if(xmax < 1 || ymax < 1) return;
/* find current float rect for display, first case is after composit... still weak */
if(rr->rectf)
rectf= rr->rectf;
else {
if(rr->rect32)
return;
else {
if(rr->renlay==NULL || rr->renlay->rectf==NULL) return;
rectf= rr->renlay->rectf;
}
}
if(rectf==NULL) return;
if(ibuf->rect==NULL)
imb_addrectImBuf(ibuf);
rectf+= 4*(rr->rectx*ymin + xmin);
rectc= (char *)(ibuf->rect + ibuf->x*rymin + rxmin);
do_color_management = (scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT));
/* XXX make nice consistent functions for this */
for(y1= 0; y1<ymax; y1++) {
float *rf= rectf;
float srgb[3];
char *rc= rectc;
const float dither = ibuf->dither / 255.0f;
/* XXX temp. because crop offset */
if(rectc >= (char *)(ibuf->rect)) {
for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) {
/* color management */
if(do_color_management) {
srgb[0]= linearrgb_to_srgb(rf[0]);
srgb[1]= linearrgb_to_srgb(rf[1]);
srgb[2]= linearrgb_to_srgb(rf[2]);
}
else {
copy_v3_v3(srgb, rf);
}
/* dither */
if(dither != 0.0f) {
const float d = (BLI_frand()-0.5f)*dither;
srgb[0] += d;
srgb[1] += d;
srgb[2] += d;
}
/* write */
rc[0]= FTOCHAR(srgb[0]);
rc[1]= FTOCHAR(srgb[1]);
rc[2]= FTOCHAR(srgb[2]);
//.........这里部分代码省略.........
开发者ID:OldBrunet,项目名称:BGERTPS,代码行数:101,代码来源:render_internal.c
示例15: IMB_buffer_byte_from_float_mask
/* float to byte pixels, output 4-channel RGBA */
void IMB_buffer_byte_from_float_mask(uchar *rect_to, const float *rect_from,
int channels_from, float dither, bool predivide,
int width, int height, int stride_to, int stride_from, char *mask)
{
int x, y;
DitherContext *di = NULL;
float inv_width = 1.0f / width,
inv_height = 1.0f / height;
if (dither)
di = create_dither_context(dither);
for (y = 0; y < height; y++) {
float t = y * inv_height;
if (channels_from == 1) {
/* single channel input */
const float *from = rect_from + stride_from * y;
uchar *to = rect_to + stride_to * y * 4;
for (x = 0; x < width; x++, from++, to += 4)
if (*mask++ == FILTER_MASK_USED)
to[0] = to[1] = to[2] = to[3] = FTOCHAR(from[0]);
}
else if (channels_from == 3) {
/* RGB input */
const float *from = rect_from + stride_from * y * 3;
uchar *to = rect_to + stride_to * y * 4;
for (x = 0; x < width; x++, from += 3, to += 4) {
if (*mask++ == FILTER_MASK_USED) {
rgb_float_to_uchar(to, from);
to[3] = 255;
}
}
}
else if (channels_from == 4) {
/* RGBA input */
const float *from = rect_from + stride_from * y * 4;
uchar *to = rect_to + stride_to * y * 4;
float straight[4];
if (dither && predivide) {
for (x = 0; x < width; x++, from += 4, to += 4) {
if (*mask++ == FILTER_MASK_USED) {
premul_to_straight_v4_v4(straight, from);
float_to_byte_dither_v4(to, straight, di, (float) x * inv_width, t);
}
}
}
else if (dither) {
for (x = 0; x < width; x++, from += 4, to += 4)
if (*mask++ == FILTER_MASK_USED)
float_to_byte_dither_v4(to, from, di, (float) x * inv_width, t);
}
else if (predivide) {
for (x = 0; x < width; x++, from += 4, to += 4) {
if (*mask++ == FILTER_MASK_USED) {
premul_to_straight_v4_v4(straight, from);
rgba_float_to_uchar(to, straight);
}
}
}
else {
for (x = 0; x < width; x++, from += 4, to += 4)
if (*mask++ == FILTER_MASK_USED)
rgba_float_to_uchar(to, from);
}
}
}
if (dither)
clear_dither_context(di);
}
开发者ID:linkedinyou,项目名称:blender-git,代码行数:76,代码来源:divers.c
示例16: brush_imbuf_new
void brush_imbuf_new(Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
{
ImBuf *ibuf;
float xy[2], dist, rgba[4], *dstf;
int x, y, rowbytes, xoff, yoff, imbflag;
const int radius= brush_size(brush);
char *dst, crgb[3];
const float alpha= brush_alpha(brush);
float brush_rgb[3];
imbflag= (flt)? IB_rectfloat: IB_rect;
xoff = -bufsize/2.0f + 0.5f;
yoff = -bufsize/2.0f + 0.5f;
rowbytes= bufsize*4;
if (*outbuf)
ibuf= *outbuf;
else
ibuf= IMB_allocImBuf(bufsize, bufsize, 32, imbflag);
if (flt) {
copy_v3_v3(brush_rgb, brush->rgb);
if(use_color_correction){
srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
}
for (y=0; y < ibuf->y; y++) {
dstf = ibuf->rect_float + y*rowbytes;
for (x=0; x < ibuf->x; x++, dstf+=4) {
xy[0] = x + xoff;
xy[1] = y + yoff;
if (texfall == 0) {
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
copy_v3_v3(dstf, brush_rgb);
dstf[3]= alpha*brush_curve_strength_clamp(brush, dist, radius);
}
else if (texfall == 1) {
brush_sample_tex(brush, xy, dstf, 0);
}
else {
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
brush_sample_tex(brush, xy, rgba, 0);
mul_v3_v3v3(dstf, rgba, brush_rgb);
dstf[3] = rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius);
}
}
}
}
else {
crgb[0]= FTOCHAR(brush->rgb[0]);
crgb[1]= FTOCHAR(brush->rgb[1]);
crgb[2]= FTOCHAR(brush->rgb[2]);
for (y=0; y < ibuf->y; y++) {
dst = (char*)ibuf->rect + y*rowbytes;
for (x=0; x < ibuf->x; x++, dst+=4) {
xy[0] = x + xoff;
xy[1] = y + yoff;
if (texfall == 0) {
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
dst[0]= crgb[0];
dst[1]= crgb[1];
dst[2]= crgb[2];
dst[3]= FTOCHAR(alpha*brush_curve_strength(brush, dist, radius));
}
else if (texfall == 1) {
brush_sample_tex(brush, xy, rgba, 0);
dst[0]= FTOCHAR(rgba[0]);
dst[1]= FTOCHAR(rgba[1]);
dst[2]= FTOCHAR(rgba[2]);
dst[3]= FTOCHAR(rgba[3]);
}
else if (texfall == 2) {
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
brush_sample_tex(brush, xy, rgba, 0);
dst[0] = FTOCHAR(rgba[0]*brush->rgb[0]);
dst[1] = FTOCHAR(rgba[1]*brush->rgb[1]);
dst[2] = FTOCHAR(rgba[2]*brush->rgb[2]);
dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
} else {
dist = sqrt(xy[0]*xy[0] + xy[1]*xy[1]);
brush_sample_tex(brush, xy, rgba, 0);
dst[0]= crgb[0];
dst[1]= crgb[1];
dst[2]= crgb[2];
dst[3] = FTOCHAR(rgba[3]*alpha*brush_curve_strength_clamp(brush, dist, radius));
}
}
}
}
//.........这里部分代码省略.........
开发者ID:mik0001,项目名称:Blender,代码行数:101,代码来源:brush.c
示例17: BKE_brush_imbuf_new
/* TODO, use define for 'texfall' arg */
void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
{
ImBuf *ibuf;
float xy[2], rgba[4], *dstf;
int x, y, rowbytes, xoff, yoff, imbflag;
const int radius = BKE_brush_size_get(scene, brush);
unsigned char *dst, crgb[3];
const float alpha = BKE_brush_alpha_get(scene, brush);
float brush_rgb[3];
imbflag = (flt) ? IB_rectfloat : IB_rect;
xoff = -bufsize / 2.0f + 0.5f;
yoff = -bufsize / 2.0f + 0.5f;
rowbytes = bufsize * 4;
if (*outbuf)
ibuf = *outbuf;
else
ibuf = IMB_allocImBuf(bufsize, bufsize, 32, imbflag);
if (flt) {
copy_v3_v3(brush_rgb, brush->rgb);
if (use_color_correction) {
srgb_to_linearrgb_v3_v3(brush_rgb, brush_rgb);
}
for (y = 0; y < ibuf->y; y++) {
dstf = ibuf->rect_float + y * rowbytes;
for (x = 0; x < ibuf->x; x++, dstf += 4) {
xy[0] = x + xoff;
xy[1] = y + yoff;
if (texfall == 0) {
copy_v3_v3(dstf, brush_rgb);
dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
}
else if (texfall == 1) {
BKE_brush_sample_tex(scene, brush, xy, dstf, 0);
}
else {
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
mul_v3_v3v3(dstf, rgba, brush_rgb);
dstf[3] = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
}
}
}
}
else {
float alpha_f; /* final float alpha to convert to char */
rgb_float_to_uchar(crgb, brush->rgb);
for (y = 0; y < ibuf->y; y++) {
dst = (unsigned char *)ibuf->rect + y * rowbytes;
for (x = 0; x < ibuf->x; x++, dst += 4) {
xy[0] = x + xoff;
xy[1] = y + yoff;
if (texfall == 0) {
alpha_f = alpha * BKE_brush_curve_strength(brush, len_v2(xy), radius);
dst[0] = crgb[0];
dst[1] = crgb[1];
dst[2] = crgb[2];
dst[3] = FTOCHAR(alpha_f);
}
else if (texfall == 1) {
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
rgba_float_to_uchar(dst, rgba);
}
else if (texfall == 2) {
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
mul_v3_v3(rgba, brush->rgb);
alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
rgb_float_to_uchar(dst, rgba);
dst[3] = FTOCHAR(alpha_f);
}
else {
BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
dst[0] = crgb[0];
dst[1] = crgb[1];
dst[2] = crgb[2];
dst[3] = FTOCHAR(alpha_f);
}
}
}
}
*outbuf = ibuf;
}
开发者ID:danielmarg,项目名称:blender-main,代码行数:96,代码来源:brush.c
示例18: brush_painter_do_partial
static void brush_painter_do_partial(BrushPainter *painter, ImBuf *oldtexibuf, int x, int y, int w, int h, int xt, int yt, float *pos)
{
Brush *brush= painter->brush;
ImBuf *ibuf, *maskibuf, *texibuf;
float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4];
char *b, *m, *t, *ot= NULL;
int dotexold, origx= x, origy= y;
const int radius= brush_size(brush);
xoff = -radius + 0.5f;
yoff = -radius + 0.5f;
xoff += (int)pos[0] - (int)painter->startpaintpos[0];
yoff += (int)pos[1] - (int)painter->startpaintpos[1];
ibuf = painter->cache.ibuf;
texibuf = painter->cache.texibuf;
maskibuf = painter->cache.maskibuf;
dotexold = (oldtexibuf != NULL);
/* not sure if it's actually needed or it's a mistake in coords/sizes
calculation in brush_painter_fixed_tex_partial_update(), but without this
limitation memory gets corrupted at fast strokes with quite big spacing (sergey) */
w = MIN2(w, ibuf->x);
h = MIN2(h, ibuf->y);
if (painter->cache.flt) {
for (; y < h; y++) {
bf = ibuf->rect_float + (y*ibuf->x + origx)*4;
tf = texibuf->rect_float + (y*texibuf->x + origx)*4;
mf = maskibuf->rect_float + (y*maskibuf->x + origx)*4;
if (dotexold)
otf = oldtexibuf->rect_float + ((y - origy + yt)*oldtexibuf->x + xt)*4;
for (x=origx; x < w; x++, bf+=4, mf+=4, tf+=4) {
if (dotexold) {
copy_v3_v3(tf, otf);
tf[3] = otf[3];
otf += 4;
}
else {
xy[0] = x + xoff;
xy[1] = y + yoff;
brush_sample_tex(brush, xy, tf, 0);
}
bf[0] = tf[0]*mf[0];
bf[1] = tf[1]*mf[1];
bf[2] = tf[2]*mf[2];
bf[3] = tf[3]*mf[3];
}
}
}
else {
for (; y < h; y++) {
b = (char*)ibuf->rect + (y*ibuf->x + origx)*4;
t = (char*)texibuf->rect + (y*texibuf->x + origx)*4;
m = (char*)maskibuf->rect + (y*maskibuf->x + origx)*4;
if (dotexold)
ot = (char*)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
for (x=origx; x < w; x++, b+=4, m+=4, t+=4) {
if (dotexold) {
t[0] = ot[0];
t[1] = ot[1];
t[2] = ot[2];
t[3] = ot[3];
ot += 4;
}
else {
xy[0] = x + xoff;
xy[1] = y + yoff;
brush_sample_tex(brush, xy, rgba, 0);
t[0]= FTOCHAR(rgba[0]);
t[1]= FTOCHAR(rgba[1]);
t[2]= FTOCHAR(rgba[2]);
t[3]= FTOCHAR(rgba[3]);
}
b[0] = t[0]*m[0]/255;
b[1] = t[1]*m[1]/255;
b[2] = t[2]*m[2]/255;
b[3] = t[3]*m[3]/255;
}
}
}
}
开发者ID:mik0001,项目名称:Blender,代码行数:91,代码来源:brush.c
示例19: brightcontrast_apply_threaded
static void brightcontrast_apply_threaded(int width, int height, unsigned char *rect, float *rect_float,
unsigned char *mask_rect, float *mask_rect_float, void *data_v)
{
BrightContrastThreadData *data = (BrightContrastThreadData *) data_v;
int x, y;
float i;
int c;
float a, b, v;
float brightness = data->bright / 100.0f;
float contrast = data->contrast;
float delta = contrast / 200.0f;
a = 1.0f - delta * 2.0f;
/*
* The algorithm is by Werner D. Streidt
* (http://visca.com/ffactory/archives/5-99/msg00021.html)
* Extracted of OpenCV demhist.c
*/
if (contrast > 0) {
a = 1.0f / a;
b = a * (brightness - delta);
}
else {
delta *= -1;
b = a * (brightness + delta);
}
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
int pixel_index = (y * width + x) * 4;
if (rect) {
unsigned char *pixel = rect + pixel_index;
for (c = 0; c < 3; c++) {
i = (float) pixel[c] / 255.0f;
v = a * i + b;
if (mask_rect) {
unsigned char *m = mask_rect + pixel_index;
float t = (float) m[c] / 255.0f;
v = (float) pixel[c] / 255.0f * (1.0f - t) + v * t;
}
pixel[c] = FTOCHAR(v);
}
}
else if (rect_float) {
float *pixel = rect_float + pixel_index;
for (c = 0; c < 3; c++) {
i = pixel[c];
v = a * i + b;
if (mask_rect_float) {
const float *m = mask_rect_float + pixel_index;
pixel[c] = pixel[c] * (1.0f - m[c]) + v * m[c];
}
else
pixel[c] = v;
}
}
}
}
}
开发者ID:mgschwan,项目名称:blensor,代码行数:68,代码来源:seqmodifier.c
示例20: apply_ao_callback
static void apply_ao_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, const void *bake_data,
ImBuf *ibuf, const int face_index, const int lvl, const float st[2],
float UNUSED(tangmat[3][3]), const int x, const int y)
{
MAOBakeData *ao_data = (MAOBakeData *) bake_data;
MTFace *mtface = CustomData_get_layer(&lores_dm->faceData, CD_MTFACE);
MFace mface;
int i, k, perm_offs;
float pos[3], nrm[3];
float cen[3];
float axisX[3], axisY[3], axisZ[3];
float shadow = 0;
float value;
int pixel = ibuf->x * y + x;
float uv[2], *st0, *st1, *st2, *st3;
lores_dm->getTessFace(lores_dm, face_index, &mface);
st0 = mtface[face_index].uv[0];
st1 = mtface[face_index].uv[1];
st2 = mtface[face_index].uv[2];
if (mface.v4) {
st3 = mtface[face_index].uv[3];
resolve_quad_uv(uv, st, st0, st1, st2, st3);
}
else
resolve_tri_uv(uv, st, st0, st1, st2);
CLAMP(uv[0], 0.0f, 1.0f);
CLAMP(uv[1], 0.0f, 1.0f);
get_ccgdm_data(lores_dm, hires_dm,
ao_data->orig_index_mf_to_mpoly, ao_data->orig_index_mp_to_orig,
lvl, face_index, uv[0], uv[1], pos, nrm);
/* offset ray origin by user bias along normal */
for (i = 0; i < 3; i++)
cen[i] = pos[i] + ao_data->bias * nrm[i];
/* build tangent frame */
for (i = 0; i < 3; i++)
axisZ[i] = nrm[i];
build_coordinate_frame(axisX, axisY, axisZ);
/* static noise */
perm_offs = (get_ao_random2(get_ao_random1(x) + y)) & (MAX_NUMBER_OF_AO_RAYS - 1);
/* importance sample shadow rays (cosine weighted) */
for (i = 0; i < ao_data->number_of_rays; i++) {
int hit_something;
/* use N-Rooks to distribute our N ray samples across
* a multi-dimensional domain (2D)
*/
const unsigned short I = ao_data->permutation_table_1[(i + perm_offs) % ao_data->number_of_rays];
const unsigned short J = ao_data->permutation_table_2[i];
const float JitPh = (get_ao_random2(I + perm_offs) & (MAX_NUMBER_OF_AO_RAYS-1))/((float) MAX_NUMBER_OF_AO_RAYS);
const float JitTh = (get_ao_random1(J + perm_offs) & (MAX_NUMBER_OF_AO_RAYS-1))/((float) MAX_NUMBER_OF_AO_RAYS);
const float SiSqPhi = (I + JitPh) / ao_data->number_of_rays;
const float Theta = (float)(2 * M_PI) * ((J + JitTh) / ao_data->number_of_rays);
/* this gives results identical to the so-called cosine
* weighted distribution relative to the north pole.
*/
float SiPhi = sqrt(SiSqPhi);
float CoPhi = SiSqPhi < 1.0f ? sqrtf(1.0f - SiSqPhi) : 0;
float CoThe = cos(Theta);
float SiThe = sin(Theta);
const float dx = CoThe * CoPhi;
const float dy = SiThe * CoPhi;
const float dz = SiPhi;
/* transform ray direction out of tangent frame */
float dv[3];
for (k = 0; k < 3; k++)
dv[k] = axisX[k] * dx + axisY[k] * dy + axisZ[k] * dz;
hit_something = trace_ao_ray(ao_data, cen, dv);
if (hit_something != 0)
shadow += 1;
}
value = 1.0f - (shadow / ao_data->number_of_rays);
if (ibuf->rect_float) {
float *rrgbf = ibuf->rect_float + pixel * 4;
rrgbf[0] = rrgbf[1] = rrgbf[2] = value;
rrgbf[3] = 1.0f;
}
else {
unsigned char *rrgb = (unsigned char *) ibuf->rect + pixel * 4;
rrgb[0] = rrgb[1] = rrgb[2] = FTOCHAR(value);
rrgb[3] = 255;
}
//.........这里部分代码省略.........
开发者ID:danielmarg,项目名称:blender-main,代码行数:101,代码来源:multires_bake.c
注:本文中的FTOCHAR函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论