Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-06-09 00:08:19 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-06-09 00:08:19 +0400
commitc8b4cf92067ffeb625aa39003baf5d8f7c3f0025 (patch)
treec6c50dbc3d90a65fca6c1ca56a93e4a57cf7e154 /source/blender/imbuf
parente93db433a086a3e739c0f4026cd500f0b595b0f1 (diff)
parentd76a6f5231c015c35123d22e1f5c3ffcdfbf9bbd (diff)
2.50:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19820:HEAD Notes: * Game and sequencer RNA, and sequencer header are now out of date a bit after changes in trunk. * I didn't know how to port these bugfixes, most likely they are not needed anymore. * Fix "duplicate strip" always increase the user count for ipo. * IPO pinning on sequencer strips was lost during Undo.
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r--source/blender/imbuf/IMB_imbuf.h1
-rw-r--r--source/blender/imbuf/intern/anim.c5
-rw-r--r--source/blender/imbuf/intern/imageprocess.c77
-rw-r--r--source/blender/imbuf/intern/openexr/openexr_api.cpp19
-rw-r--r--source/blender/imbuf/intern/rotate.c6
-rw-r--r--source/blender/imbuf/intern/scaling.c67
6 files changed, 127 insertions, 48 deletions
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index 8bc1439fd09..1d8035a2358 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -410,6 +410,7 @@ void bilinear_interpolation(struct ImBuf *in, struct ImBuf *out, float u, float
void bicubic_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void neareast_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
void bilinear_interpolation_color(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
+void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *col, float *col_float, float u, float v);
/**
* Change the ordering of the color bytes pointed to by rect from
diff --git a/source/blender/imbuf/intern/anim.c b/source/blender/imbuf/intern/anim.c
index 30f24d9bbf3..a2dbdfbe483 100644
--- a/source/blender/imbuf/intern/anim.c
+++ b/source/blender/imbuf/intern/anim.c
@@ -1046,10 +1046,11 @@ struct ImBuf * IMB_anim_absolute(struct anim * anim, int position) {
char head[256], tail[256];
unsigned short digits;
int pic;
- int filter_y = (anim->ib_flags & IB_animdeinterlace);
-
+ int filter_y;
if (anim == NULL) return(0);
+ filter_y = (anim->ib_flags & IB_animdeinterlace);
+
if (anim->curtype == 0) {
ibuf = anim_getnew(anim);
if (ibuf == NULL) {
diff --git a/source/blender/imbuf/intern/imageprocess.c b/source/blender/imbuf/intern/imageprocess.c
index fe7e26eac2b..e4977c77155 100644
--- a/source/blender/imbuf/intern/imageprocess.c
+++ b/source/blender/imbuf/intern/imageprocess.c
@@ -294,10 +294,79 @@ void bilinear_interpolation_color(struct ImBuf *in, unsigned char *outI, float *
b= v-floor(v);
a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
- outI[0]= ma_mb*row1I[0] + a_mb*row3I[0] + ma_b*row2I[0]+ a_b*row4I[0];
- outI[1]= ma_mb*row1I[1] + a_mb*row3I[1] + ma_b*row2I[1]+ a_b*row4I[1];
- outI[2]= ma_mb*row1I[2] + a_mb*row3I[2] + ma_b*row2I[2]+ a_b*row4I[2];
- outI[3]= ma_mb*row1I[3] + a_mb*row3I[3] + ma_b*row2I[3]+ a_b*row4I[3];
+ /* need to add 0.5 to avoid rounding down (causes darken with the smear brush)
+ * tested with white images and this should not wrap back to zero */
+ outI[0]= (ma_mb*row1I[0] + a_mb*row3I[0] + ma_b*row2I[0]+ a_b*row4I[0]) + 0.5f;
+ outI[1]= (ma_mb*row1I[1] + a_mb*row3I[1] + ma_b*row2I[1]+ a_b*row4I[1]) + 0.5f;
+ outI[2]= (ma_mb*row1I[2] + a_mb*row3I[2] + ma_b*row2I[2]+ a_b*row4I[2]) + 0.5f;
+ outI[3]= (ma_mb*row1I[3] + a_mb*row3I[3] + ma_b*row2I[3]+ a_b*row4I[3]) + 0.5f;
+ }
+}
+
+/* function assumes out to be zero'ed, only does RGBA */
+/* BILINEAR INTERPOLATION */
+
+/* Note about wrapping, the u/v still needs to be within the image bounds,
+ * just the interpolation is wrapped.
+ * This the same as bilinear_interpolation_color except it wraps rather then using empty and emptyI */
+void bilinear_interpolation_color_wrap(struct ImBuf *in, unsigned char *outI, float *outF, float u, float v)
+{
+ float *row1, *row2, *row3, *row4, a, b;
+ unsigned char *row1I, *row2I, *row3I, *row4I;
+ float a_b, ma_b, a_mb, ma_mb;
+ int y1, y2, x1, x2;
+
+
+ /* ImBuf in must have a valid rect or rect_float, assume this is alredy checked */
+
+ x1= (int)floor(u);
+ x2= (int)ceil(u);
+ y1= (int)floor(v);
+ y2= (int)ceil(v);
+
+ // sample area entirely outside image?
+ if (x2<0 || x1>in->x-1 || y2<0 || y1>in->y-1) return;
+
+ /* wrap interpolation pixels - main difference from bilinear_interpolation_color */
+ if(x1<0)x1= in->x+x1;
+ if(y1<0)y1= in->y+y1;
+
+ if(x2>=in->x)x2= x2-in->x;
+ if(y2>=in->y)y2= y2-in->y;
+
+ if (outF) {
+ // sample including outside of edges of image
+ row1= (float *)in->rect_float + in->x * y1 * 4 + 4*x1;
+ row2= (float *)in->rect_float + in->x * y2 * 4 + 4*x1;
+ row3= (float *)in->rect_float + in->x * y1 * 4 + 4*x2;
+ row4= (float *)in->rect_float + in->x * y2 * 4 + 4*x2;
+
+ a= u-floor(u);
+ b= v-floor(v);
+ a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
+
+ outF[0]= ma_mb*row1[0] + a_mb*row3[0] + ma_b*row2[0]+ a_b*row4[0];
+ outF[1]= ma_mb*row1[1] + a_mb*row3[1] + ma_b*row2[1]+ a_b*row4[1];
+ outF[2]= ma_mb*row1[2] + a_mb*row3[2] + ma_b*row2[2]+ a_b*row4[2];
+ outF[3]= ma_mb*row1[3] + a_mb*row3[3] + ma_b*row2[3]+ a_b*row4[3];
+ }
+ if (outI) {
+ // sample including outside of edges of image
+ row1I= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x1;
+ row2I= (unsigned char *)in->rect + in->x * y2 * 4 + 4*x1;
+ row3I= (unsigned char *)in->rect + in->x * y1 * 4 + 4*x2;
+ row4I= (unsigned char *)in->rect + in->x * y2 * 4 + 4*x2;
+
+ a= u-floor(u);
+ b= v-floor(v);
+ a_b= a*b; ma_b= (1.0f-a)*b; a_mb= a*(1.0f-b); ma_mb= (1.0f-a)*(1.0f-b);
+
+ /* need to add 0.5 to avoid rounding down (causes darken with the smear brush)
+ * tested with white images and this should not wrap back to zero */
+ outI[0]= (ma_mb*row1I[0] + a_mb*row3I[0] + ma_b*row2I[0]+ a_b*row4I[0]) + 0.5f;
+ outI[1]= (ma_mb*row1I[1] + a_mb*row3I[1] + ma_b*row2I[1]+ a_b*row4I[1]) + 0.5f;
+ outI[2]= (ma_mb*row1I[2] + a_mb*row3I[2] + ma_b*row2I[2]+ a_b*row4I[2]) + 0.5f;
+ outI[3]= (ma_mb*row1I[3] + a_mb*row3I[3] + ma_b*row2I[3]+ a_b*row4I[3]) + 0.5f;
}
}
diff --git a/source/blender/imbuf/intern/openexr/openexr_api.cpp b/source/blender/imbuf/intern/openexr/openexr_api.cpp
index e723609f3ae..32d97d79bd7 100644
--- a/source/blender/imbuf/intern/openexr/openexr_api.cpp
+++ b/source/blender/imbuf/intern/openexr/openexr_api.cpp
@@ -570,13 +570,17 @@ void IMB_exr_write_channels(void *handle)
FrameBuffer frameBuffer;
ExrChannel *echan;
- for(echan= (ExrChannel *)data->channels.first; echan; echan= echan->next)
- frameBuffer.insert (echan->name, Slice (FLOAT, (char *)echan->rect,
- echan->xstride*sizeof(float), echan->ystride*sizeof(float)));
-
- data->ofile->setFrameBuffer (frameBuffer);
- data->ofile->writePixels (data->height);
-
+ if(data->channels.first) {
+ for(echan= (ExrChannel *)data->channels.first; echan; echan= echan->next)
+ frameBuffer.insert (echan->name, Slice (FLOAT, (char *)echan->rect,
+ echan->xstride*sizeof(float), echan->ystride*sizeof(float)));
+
+ data->ofile->setFrameBuffer (frameBuffer);
+ data->ofile->writePixels (data->height);
+ }
+ else {
+ printf("Error: attempt to save MultiLayer without layers.\n");
+ }
}
void IMB_exr_read_channels(void *handle)
@@ -861,6 +865,7 @@ static const char *exr_rgba_channelname(InputFile *file, const char *chan)
for (ChannelList::ConstIterator i = channels.begin(); i != channels.end(); ++i)
{
+ /* const Channel &channel = i.channel(); */ /* Not used yet */
const char *str= i.name();
int len= strlen(str);
if(len) {
diff --git a/source/blender/imbuf/intern/rotate.c b/source/blender/imbuf/intern/rotate.c
index c04987b3e71..732c06907df 100644
--- a/source/blender/imbuf/intern/rotate.c
+++ b/source/blender/imbuf/intern/rotate.c
@@ -30,6 +30,7 @@
*/
#include "BLI_blenlib.h"
+#include "BKE_utildefines.h"
#include "imbuf.h"
#include "imbuf_patch.h"
@@ -94,7 +95,6 @@ void IMB_flipy(struct ImBuf * ibuf)
void IMB_flipx(struct ImBuf * ibuf)
{
short x, y, xr, xl, yi;
- unsigned int px;
float px_f[4];
if (ibuf == NULL) return;
@@ -105,9 +105,7 @@ void IMB_flipx(struct ImBuf * ibuf)
if (ibuf->rect) {
for(yi=y-1;yi>=0;yi--) {
for(xr=x-1, xl=0; xr>=xl; xr--, xl++) {
- px = ibuf->rect[(x*yi)+xr];
- ibuf->rect[(x*yi)+xr] = ibuf->rect[(x*yi)+xl];
- ibuf->rect[(x*yi)+xl] = px;
+ SWAP(unsigned int, ibuf->rect[(x*yi)+xr], ibuf->rect[(x*yi)+xl]);
}
}
}
diff --git a/source/blender/imbuf/intern/scaling.c b/source/blender/imbuf/intern/scaling.c
index 807b0c84e90..1ccdad05deb 100644
--- a/source/blender/imbuf/intern/scaling.c
+++ b/source/blender/imbuf/intern/scaling.c
@@ -596,12 +596,12 @@ static void shrink_picture_byte(
y_counter = 65536;
for (y_src = 0; y_src < src_height; y_src++) {
unsigned char* line = src + y_src * 4 * src_width;
- uintptr_t weight1y = 65536 - (y_dst & 0xffff);
- uintptr_t weight2y = 65536 - weight1y;
+ uintptr_t weight1y = 65535 - (y_dst & 0xffff);
+ uintptr_t weight2y = 65535 - weight1y;
x_dst = 0;
for (x_src = 0; x_src < src_width; x_src++) {
- uintptr_t weight1x = 65536 - (x_dst & 0xffff);
- uintptr_t weight2x = 65536 - weight1x;
+ uintptr_t weight1x = 65535 - (x_dst & 0xffff);
+ uintptr_t weight2x = 65535 - weight1x;
uintptr_t x = x_dst >> 16;
@@ -609,34 +609,35 @@ static void shrink_picture_byte(
w = (weight1y * weight1x) >> 16;
- dst_line1[x].r += (line[0] * w) >> 16;
- dst_line1[x].g += (line[1] * w) >> 16;
- dst_line1[x].b += (line[2] * w) >> 16;
- dst_line1[x].a += (line[3] * w) >> 16;
+ /* ensure correct rounding, without this you get ugly banding, or too low color values (ton) */
+ dst_line1[x].r += (line[0] * w + 32767) >> 16;
+ dst_line1[x].g += (line[1] * w + 32767) >> 16;
+ dst_line1[x].b += (line[2] * w + 32767) >> 16;
+ dst_line1[x].a += (line[3] * w + 32767) >> 16;
dst_line1[x].weight += w;
w = (weight2y * weight1x) >> 16;
- dst_line2[x].r += (line[0] * w) >> 16;
- dst_line2[x].g += (line[1] * w) >> 16;
- dst_line2[x].b += (line[2] * w) >> 16;
- dst_line2[x].a += (line[3] * w) >> 16;
+ dst_line2[x].r += (line[0] * w + 32767) >> 16;
+ dst_line2[x].g += (line[1] * w + 32767) >> 16;
+ dst_line2[x].b += (line[2] * w + 32767) >> 16;
+ dst_line2[x].a += (line[3] * w + 32767) >> 16;
dst_line2[x].weight += w;
w = (weight1y * weight2x) >> 16;
- dst_line1[x+1].r += (line[0] * w) >> 16;
- dst_line1[x+1].g += (line[1] * w) >> 16;
- dst_line1[x+1].b += (line[2] * w) >> 16;
- dst_line1[x+1].a += (line[3] * w) >> 16;
+ dst_line1[x+1].r += (line[0] * w + 32767) >> 16;
+ dst_line1[x+1].g += (line[1] * w + 32767) >> 16;
+ dst_line1[x+1].b += (line[2] * w + 32767) >> 16;
+ dst_line1[x+1].a += (line[3] * w + 32767) >> 16;
dst_line1[x+1].weight += w;
w = (weight2y * weight2x) >> 16;
- dst_line2[x+1].r += (line[0] * w) >> 16;
- dst_line2[x+1].g += (line[1] * w) >> 16;
- dst_line2[x+1].b += (line[2] * w) >> 16;
- dst_line2[x+1].a += (line[3] * w) >> 16;
+ dst_line2[x+1].r += (line[0] * w + 32767) >> 16;
+ dst_line2[x+1].g += (line[1] * w + 32767) >> 16;
+ dst_line2[x+1].b += (line[2] * w + 32767) >> 16;
+ dst_line2[x+1].a += (line[3] * w + 32767) >> 16;
dst_line2[x+1].weight += w;
x_dst += dx_dst;
@@ -646,18 +647,18 @@ static void shrink_picture_byte(
y_dst += dy_dst;
y_counter -= dy_dst;
if (y_counter < 0) {
+ int val;
uintptr_t x;
struct scale_outpix_byte * temp;
y_counter += 65536;
for (x=0; x < dst_width; x++) {
- uintptr_t f = 0x80000000UL
- / dst_line1[x].weight;
- *dst++ = (dst_line1[x].r * f) >> 15;
- *dst++ = (dst_line1[x].g * f) >> 15;
- *dst++ = (dst_line1[x].b * f) >> 15;
- *dst++ = (dst_line1[x].a * f) >> 15;
+ uintptr_t f = 0x80000000UL / dst_line1[x].weight;
+ *dst++ = (val= (dst_line1[x].r * f) >> 15) > 255 ? 255: val;
+ *dst++ = (val= (dst_line1[x].g * f) >> 15) > 255 ? 255: val;
+ *dst++ = (val= (dst_line1[x].b * f) >> 15) > 255 ? 255: val;
+ *dst++ = (val= (dst_line1[x].a * f) >> 15) > 255 ? 255: val;
}
memset(dst_line1, 0, dst_width *
sizeof(struct scale_outpix_byte));
@@ -667,13 +668,14 @@ static void shrink_picture_byte(
}
}
if (dst - dst_begin < dst_width * dst_height * 4) {
+ int val;
uintptr_t x;
for (x = 0; x < dst_width; x++) {
uintptr_t f = 0x80000000UL / dst_line1[x].weight;
- *dst++ = (dst_line1[x].r * f) >> 15;
- *dst++ = (dst_line1[x].g * f) >> 15;
- *dst++ = (dst_line1[x].b * f) >> 15;
- *dst++ = (dst_line1[x].a * f) >> 15;
+ *dst++ = (val= (dst_line1[x].r * f) >> 15) > 255 ? 255: val;
+ *dst++ = (val= (dst_line1[x].g * f) >> 15) > 255 ? 255: val;
+ *dst++ = (val= (dst_line1[x].b * f) >> 15) > 255 ? 255: val;
+ *dst++ = (val= (dst_line1[x].a * f) >> 15) > 255 ? 255: val;
}
}
MEM_freeN(dst_line1);
@@ -911,6 +913,8 @@ static void q_scale_float(float* in, float* out, int in_width,
Should be comparable in speed to the ImBuf ..._fast functions at least
for byte-buffers.
+ NOTE: disabled, due to inacceptable inaccuracy and quality loss, see bug #18609 (ton)
+
*/
static int q_scale_linear_interpolation(
struct ImBuf *ibuf, int newx, int newy)
@@ -1583,7 +1587,8 @@ struct ImBuf *IMB_scaleImBuf(struct ImBuf * ibuf, short newx, short newy)
scalefast_Z_ImBuf(ibuf, newx, newy);
/* try to scale common cases in a fast way */
- if (q_scale_linear_interpolation(ibuf, newx, newy)) {
+ /* disabled, quality loss is inacceptable, see report #18609 (ton) */
+ if (0 && q_scale_linear_interpolation(ibuf, newx, newy)) {
return ibuf;
}