小编Mat*_* K.的帖子

如何将两个位图与 AVX2 混合 80-20%?

我有 2 个位图。我想以 80:20 的比例混合它们,所以我只需将像素值乘以 0,8 和 0,2。用 C 编写的代码(作为 for 循环)运行良好,但使用 AVX2 指令会导致输出图像错误。

#include <stdio.h>
#include <stdlib.h>
#include <immintrin.h>

#define ARRSIZE 5992826

void main(void){

 FILE *bmp    = fopen("filepath1", "rb"),
      *bmpp   = fopen("filepath2", "rb"),
      *write  = fopen("output", "wb");

 unsigned char *a = aligned_alloc(32, ARRSIZE),
               *b = aligned_alloc(32, ARRSIZE),
               *c = aligned_alloc(32, ARRSIZE);

 fread(c, 1, 122, bmp);
 rewind(bmp); 
 fread(a, 1, ARRSIZE, bmp);
 fread(b, 1, ARRSIZE, bmpp);

 __m256i mm_a, mm_b;
 __m256d mm_two   = _mm256_set1_pd(2),
         mm_eight = _mm256_set1_pd(8);

 __m256d mm_c, mm_d,
         mm_ten = …
Run Code Online (Sandbox Code Playgroud)

c bitmap intrinsics avx avx2

1
推荐指数
1
解决办法
270
查看次数

标签 统计

avx ×1

avx2 ×1

bitmap ×1

c ×1

intrinsics ×1