Skip to content

Commit

Permalink
[effect] Switch "Grain" to use blend.h
Browse files Browse the repository at this point in the history
  • Loading branch information
grandchild committed Oct 27, 2024
1 parent 376f876 commit 6fe8b72
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions avs/vis_avs/e_grain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "e_grain.h"

#include "r_defs.h"
#include "blend.h"

#include <stdlib.h>

Expand Down Expand Up @@ -96,8 +96,6 @@ int E_Grain::render(char[2][2][576],
}

int amount_scaled = (this->config.amount * 255) / 100;
int* p;
unsigned char* q;
int l = w * h;

if (w != this->old_x || h != this->old_y) {
Expand All @@ -110,13 +108,13 @@ int E_Grain::render(char[2][2][576],
this->randtab_pos -= 491;
}

p = framebuffer;
q = this->depth_buffer;
auto p = (uint32_t*)framebuffer;
uint8_t* q = this->depth_buffer;
if (this->config.static_) {
if (this->config.blend_mode == BLEND_SIMPLE_ADDITIVE) {
while (l--) {
if (*p) {
int c = 0;
uint32_t c = 0;
if (q[1] < amount_scaled) {
int s = q[0];
int r = (((p[0] & 0xff0000) * s) >> 8);
Expand All @@ -135,15 +133,16 @@ int E_Grain::render(char[2][2][576],
}
c |= r;
}
*p = BLEND(*p, c);
blend_add_1px(&c, p, p);
// *p = BLEND(*p, c);
}
p++;
q += 2;
}
} else if (this->config.blend_mode == BLEND_SIMPLE_5050) {
while (l--) {
if (*p) {
int c = 0;
uint32_t c = 0;
if (q[1] < amount_scaled) {
int s = q[0];
int r = (((p[0] & 0xff0000) * s) >> 8);
Expand All @@ -162,15 +161,16 @@ int E_Grain::render(char[2][2][576],
}
c |= r;
}
*p = BLEND_AVG(*p, c);
blend_5050_1px(&c, p, p);
// *p = BLEND_AVG(*p, c);
}
p++;
q += 2;
}
} else { // BLEND_SIMPLE_REPLACE
while (l--) {
if (*p) {
int c = 0;
uint32_t c = 0;
if (q[1] < amount_scaled) {
int s = q[0];
int r = (((p[0] & 0xff0000) * s) >> 8);
Expand All @@ -189,7 +189,7 @@ int E_Grain::render(char[2][2][576],
}
c |= r;
}
*p = c;
blend_replace_1px(&c, p);
}
p++;
q += 2;
Expand All @@ -199,7 +199,7 @@ int E_Grain::render(char[2][2][576],
if (this->config.blend_mode == BLEND_SIMPLE_ADDITIVE) {
while (l--) {
if (*p) {
int c = 0;
uint32_t c = 0;
if (fastrandbyte() < amount_scaled) {
int s = fastrandbyte();
int r = (((p[0] & 0xff0000) * s) >> 8);
Expand All @@ -218,15 +218,16 @@ int E_Grain::render(char[2][2][576],
}
c |= r;
}
*p = BLEND(*p, c);
blend_add_1px(&c, p, p);
// *p = BLEND(*p, c);
}
p++;
q += 2;
}
} else if (this->config.blend_mode == BLEND_SIMPLE_5050) {
while (l--) {
if (*p) {
int c = 0;
uint32_t c = 0;
if (fastrandbyte() < amount_scaled) {
int s = fastrandbyte();
int r = (((p[0] & 0xff0000) * s) >> 8);
Expand All @@ -245,15 +246,16 @@ int E_Grain::render(char[2][2][576],
}
c |= r;
}
*p = BLEND_AVG(*p, c);
blend_5050_1px(&c, p, p);
// *p = BLEND_AVG(*p, c);
}
p++;
q += 2;
}
} else { // BLEND_SIMPLE_REPLACE
while (l--) {
if (*p) {
int c = 0;
uint32_t c = 0;
if (fastrandbyte() < amount_scaled) {
int s = fastrandbyte();
int r = (((p[0] & 0xff0000) * s) >> 8);
Expand All @@ -272,7 +274,8 @@ int E_Grain::render(char[2][2][576],
}
c |= r;
}
*p = c;
blend_replace_1px(&c, p);
// *p = c;
}
p++;
q += 2;
Expand Down

0 comments on commit 6fe8b72

Please sign in to comment.