未验证 提交 63fcc116 编写于 作者: J JackieWu 提交者: GitHub

去掉imread函数中多余的数据拷贝 (#392)

* remove unnecessary copy

* combine loop
上级 04f5d2a0
......@@ -634,41 +634,23 @@ void combination_image(image source, image dest, int dx, int dy)
image imread(const char* filename)
{
image im = load_image_stb(filename, 0);
for (int c = 0; c < im.c; c++)
{
for (int h = 0; h < im.h; h++)
{
for (int w = 0; w < im.w; w++)
{
int newIndex = ( c )*im.h * im.w + h * im.w + w;
im.data[newIndex] = im.data[newIndex];
}
}
}
return im;
return load_image_stb(filename, 0);
}
image imread2post(const char* filename)
{
image im = load_image_stb(filename, 0);
for (int c = 0; c < im.c; c++)
{
for (int h = 0; h < im.h; h++)
{
for (int w = 0; w < im.w; w++)
{
int newIndex = ( c )*im.h * im.w + h * im.w + w;
im.data[newIndex] = im.data[newIndex] * 255;
}
}
const int len = im.c * im.h * im.w;
for (int i = 0; i < len; ++i) {
im.data[i] *= 255;
}
return im;
}
image rgb2bgr_premute(image src)
{
float* GRB = ( float* )malloc(sizeof(float) * src.c * src.h * src.w);
const int len = src.c * src.h * src.w;
float* GRB = ( float* )malloc(sizeof(float) * len);
for (int c = 0; c < src.c; c++)
{
for (int h = 0; h < src.h; h++)
......@@ -681,16 +663,8 @@ image rgb2bgr_premute(image src)
}
}
}
for (int c = 0; c < src.c; c++)
{
for (int h = 0; h < src.h; h++)
{
for (int w = 0; w < src.w; w++)
{
int newIndex = ( c )*src.h * src.w + h * src.w + w;
src.data[newIndex] = GRB[newIndex];
}
}
for (int i = 0; i < len; ++i) {
src.data[i] = GRB[i];
}
free(GRB);
return src;
......@@ -808,7 +782,7 @@ void draw_circle(image im, int x, int y, int radius, int r, int g, int b)
void subtract(image a, image b, image c)
{
int size = a.c * a.h * a.w;
const int size = a.c * a.h * a.w;
for (int i = 0; i < size; i++)
{
c.data[i] = a.data[i] - b.data[i];
......@@ -820,7 +794,7 @@ void subtract(image a, image b, image c)
void multi(image a, float value, image b)
{
int size = a.c * a.h * a.w;
const int size = a.c * a.h * a.w;
for (int i = 0; i < size; i++)
{
b.data[i] = a.data[i] * value;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册