mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2026-01-27 12:50:39 +03:00
test1
This commit is contained in:
@@ -11,9 +11,9 @@ CRotateImage::CRotateImage(std::string _name, CImageBasis *_org, CImageBasis *_t
|
||||
width = _org->width;
|
||||
height = _org->height;
|
||||
bpp = _org->bpp;
|
||||
externalImage = true;
|
||||
ImageTMP = _temp;
|
||||
ImageOrg = _org;
|
||||
externalImage = true;
|
||||
ImageTMP = _temp;
|
||||
ImageOrg = _org;
|
||||
islocked = false;
|
||||
doflip = _flip;
|
||||
}
|
||||
@@ -31,10 +31,13 @@ void CRotateImage::Rotate(float _angle, int _centerx, int _centery)
|
||||
{
|
||||
org_width = width;
|
||||
org_height = height;
|
||||
|
||||
height = org_width;
|
||||
width = org_height;
|
||||
x_center = x_center - (org_width/2) + (org_height/2);
|
||||
y_center = y_center + (org_width/2) - (org_height/2);
|
||||
|
||||
x_center = x_center - (org_width / 2) + (org_height / 2);
|
||||
y_center = y_center + (org_width / 2) - (org_height / 2);
|
||||
|
||||
if (ImageOrg)
|
||||
{
|
||||
ImageOrg->height = height;
|
||||
@@ -57,32 +60,32 @@ void CRotateImage::Rotate(float _angle, int _centerx, int _centery)
|
||||
|
||||
if (doflip)
|
||||
{
|
||||
m[0][2] = m[0][2] + (org_width/2) - (org_height/2);
|
||||
m[1][2] = m[1][2] - (org_width/2) + (org_height/2);
|
||||
m[0][2] = m[0][2] + (org_width / 2) - (org_height / 2);
|
||||
m[1][2] = m[1][2] - (org_width / 2) + (org_height / 2);
|
||||
}
|
||||
|
||||
int memsize = width * height * channels;
|
||||
uint8_t* odata;
|
||||
uint8_t *temp_image;
|
||||
if (ImageTMP)
|
||||
{
|
||||
odata = ImageTMP->RGBImageLock();
|
||||
temp_image = ImageTMP->RGBImageLock();
|
||||
}
|
||||
else
|
||||
{
|
||||
odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM);
|
||||
temp_image = (unsigned char *)malloc_psram_heap(std::string(TAG) + "->temp_image", memsize, MALLOC_CAP_SPIRAM);
|
||||
}
|
||||
|
||||
|
||||
int x_source, y_source;
|
||||
stbi_uc* p_target;
|
||||
stbi_uc* p_source;
|
||||
stbi_uc *p_target;
|
||||
stbi_uc *p_source;
|
||||
|
||||
RGBImageLock();
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
p_target = odata + (channels * (y * width + x));
|
||||
p_target = temp_image + (channels * (y * width + x));
|
||||
|
||||
x_source = int(m[0][0] * x + m[0][1] * y);
|
||||
y_source = int(m[1][0] * x + m[1][1] * y);
|
||||
@@ -93,30 +96,44 @@ void CRotateImage::Rotate(float _angle, int _centerx, int _centery)
|
||||
if ((x_source >= 0) && (x_source < org_width) && (y_source >= 0) && (y_source < org_height))
|
||||
{
|
||||
p_source = rgb_image + (channels * (y_source * org_width + x_source));
|
||||
|
||||
for (int _channels = 0; _channels < channels; ++_channels)
|
||||
{
|
||||
p_target[_channels] = p_source[_channels];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int _channels = 0; _channels < channels; ++_channels)
|
||||
p_target[_channels] = 255;
|
||||
{
|
||||
// p_target[_channels] = 255; // nicht vorhandene Pixel werden Weiß gemacht
|
||||
// p_target[_channels] = 0; // nicht vorhandene Pixel werden Schwarz gemacht
|
||||
// p_target[_channels] = 128; // nicht vorhandene Pixel werden Grau gemacht
|
||||
p_target[_channels] = pixel_fill_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// memcpy(rgb_image, odata, memsize);
|
||||
memCopy(odata, rgb_image, memsize);
|
||||
|
||||
if (!ImageTMP)
|
||||
{
|
||||
free_psram_heap(std::string(TAG) + "->odata", odata);
|
||||
}
|
||||
|
||||
memCopy(temp_image, rgb_image, memsize);
|
||||
|
||||
if (ImageTMP)
|
||||
{
|
||||
ImageTMP->RGBImageRelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
free_psram_heap(std::string(TAG) + "->temp_image", temp_image);
|
||||
}
|
||||
|
||||
RGBImageRelease();
|
||||
}
|
||||
|
||||
|
||||
void CRotateImage::Rotate(float _angle)
|
||||
{
|
||||
// ESP_LOGD(TAG, "width %d, height %d", width, height);
|
||||
Rotate(_angle, width / 2, height / 2);
|
||||
}
|
||||
|
||||
void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
|
||||
{
|
||||
@@ -131,10 +148,13 @@ void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
|
||||
{
|
||||
org_width = width;
|
||||
org_height = height;
|
||||
|
||||
height = org_width;
|
||||
width = org_height;
|
||||
x_center = x_center - (org_width/2) + (org_height/2);
|
||||
y_center = y_center + (org_width/2) - (org_height/2);
|
||||
|
||||
x_center = x_center - (org_width / 2) + (org_height / 2);
|
||||
y_center = y_center + (org_width / 2) - (org_height / 2);
|
||||
|
||||
if (ImageOrg)
|
||||
{
|
||||
ImageOrg->height = height;
|
||||
@@ -157,34 +177,34 @@ void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
|
||||
|
||||
if (doflip)
|
||||
{
|
||||
m[0][2] = m[0][2] + (org_width/2) - (org_height/2);
|
||||
m[1][2] = m[1][2] - (org_width/2) + (org_height/2);
|
||||
m[0][2] = m[0][2] + (org_width / 2) - (org_height / 2);
|
||||
m[1][2] = m[1][2] - (org_width / 2) + (org_height / 2);
|
||||
}
|
||||
|
||||
int memsize = width * height * channels;
|
||||
uint8_t* odata;
|
||||
uint8_t *temp_image;
|
||||
if (ImageTMP)
|
||||
{
|
||||
odata = ImageTMP->RGBImageLock();
|
||||
temp_image = ImageTMP->RGBImageLock();
|
||||
}
|
||||
else
|
||||
{
|
||||
odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM);
|
||||
temp_image = (unsigned char *)malloc_psram_heap(std::string(TAG) + "->temp_image", memsize, MALLOC_CAP_SPIRAM);
|
||||
}
|
||||
|
||||
|
||||
int x_source_1, y_source_1, x_source_2, y_source_2;
|
||||
float x_source, y_source;
|
||||
float quad_ul, quad_ur, quad_ol, quad_or;
|
||||
stbi_uc* p_target;
|
||||
stbi_uc *p_target;
|
||||
stbi_uc *p_source_ul, *p_source_ur, *p_source_ol, *p_source_or;
|
||||
|
||||
RGBImageLock();
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
p_target = odata + (channels * (y * width + x));
|
||||
p_target = temp_image + (channels * (y * width + x));
|
||||
|
||||
x_source = (m[0][0] * x + m[0][1] * y);
|
||||
y_source = (m[1][0] * x + m[1][1] * y);
|
||||
@@ -198,10 +218,9 @@ void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
|
||||
y_source_2 = y_source_1 + 1;
|
||||
|
||||
quad_ul = (x_source_2 - x_source) * (y_source_2 - y_source);
|
||||
quad_ur = (1- (x_source_2 - x_source)) * (y_source_2 - y_source);
|
||||
quad_or = (x_source_2 - x_source) * (1-(y_source_2 - y_source));
|
||||
quad_ol = (1- (x_source_2 - x_source)) * (1-(y_source_2 - y_source));
|
||||
|
||||
quad_ur = (1 - (x_source_2 - x_source)) * (y_source_2 - y_source);
|
||||
quad_or = (x_source_2 - x_source) * (1 - (y_source_2 - y_source));
|
||||
quad_ol = (1 - (x_source_2 - x_source)) * (1 - (y_source_2 - y_source));
|
||||
|
||||
if ((x_source_1 >= 0) && (x_source_2 < org_width) && (y_source_1 >= 0) && (y_source_2 < org_height))
|
||||
{
|
||||
@@ -209,72 +228,70 @@ void CRotateImage::RotateAntiAliasing(float _angle, int _centerx, int _centery)
|
||||
p_source_ur = rgb_image + (channels * (y_source_1 * org_width + x_source_2));
|
||||
p_source_or = rgb_image + (channels * (y_source_2 * org_width + x_source_1));
|
||||
p_source_ol = rgb_image + (channels * (y_source_2 * org_width + x_source_2));
|
||||
|
||||
for (int _channels = 0; _channels < channels; ++_channels)
|
||||
{
|
||||
p_target[_channels] = (int)((float)p_source_ul[_channels] * quad_ul
|
||||
+ (float)p_source_ur[_channels] * quad_ur
|
||||
+ (float)p_source_or[_channels] * quad_or
|
||||
+ (float)p_source_ol[_channels] * quad_ol);
|
||||
p_target[_channels] = (int)((float)p_source_ul[_channels] * quad_ul + (float)p_source_ur[_channels] * quad_ur + (float)p_source_or[_channels] * quad_or + (float)p_source_ol[_channels] * quad_ol);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int _channels = 0; _channels < channels; ++_channels)
|
||||
p_target[_channels] = 255;
|
||||
{
|
||||
// p_target[_channels] = 255; // nicht vorhandene Pixel werden Weiß gemacht
|
||||
// p_target[_channels] = 0; // nicht vorhandene Pixel werden Schwarz gemacht
|
||||
// p_target[_channels] = 128; // nicht vorhandene Pixel werden Grau gemacht
|
||||
p_target[_channels] = pixel_fill_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// memcpy(rgb_image, odata, memsize);
|
||||
memCopy(odata, rgb_image, memsize);
|
||||
|
||||
if (!ImageTMP)
|
||||
{
|
||||
free_psram_heap(std::string(TAG) + "->odata", odata);
|
||||
}
|
||||
|
||||
memCopy(temp_image, rgb_image, memsize);
|
||||
|
||||
if (ImageTMP)
|
||||
{
|
||||
ImageTMP->RGBImageRelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
free_psram_heap(std::string(TAG) + "->temp_image", temp_image);
|
||||
}
|
||||
|
||||
RGBImageRelease();
|
||||
}
|
||||
|
||||
|
||||
void CRotateImage::Rotate(float _angle)
|
||||
{
|
||||
// ESP_LOGD(TAG, "width %d, height %d", width, height);
|
||||
Rotate(_angle, width / 2, height / 2);
|
||||
}
|
||||
|
||||
void CRotateImage::RotateAntiAliasing(float _angle)
|
||||
{
|
||||
// ESP_LOGD(TAG, "width %d, height %d", width, height);
|
||||
// ESP_LOGD(TAG, "width %d, height %d", width, height);
|
||||
RotateAntiAliasing(_angle, width / 2, height / 2);
|
||||
}
|
||||
|
||||
void CRotateImage::Translate(int _dx, int _dy)
|
||||
{
|
||||
int memsize = width * height * channels;
|
||||
uint8_t* odata;
|
||||
uint8_t *temp_image;
|
||||
|
||||
if (ImageTMP)
|
||||
{
|
||||
odata = ImageTMP->RGBImageLock();
|
||||
temp_image = ImageTMP->RGBImageLock();
|
||||
}
|
||||
else
|
||||
{
|
||||
odata = (unsigned char*)malloc_psram_heap(std::string(TAG) + "->odata", memsize, MALLOC_CAP_SPIRAM);
|
||||
temp_image = (unsigned char *)malloc_psram_heap(std::string(TAG) + "->temp_image", memsize, MALLOC_CAP_SPIRAM);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int x_source, y_source;
|
||||
stbi_uc* p_target;
|
||||
stbi_uc* p_source;
|
||||
stbi_uc *p_target;
|
||||
stbi_uc *p_source;
|
||||
|
||||
RGBImageLock();
|
||||
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
for (int y = 0; y < height; ++y)
|
||||
{
|
||||
p_target = odata + (channels * (y * width + x));
|
||||
p_target = temp_image + (channels * (y * width + x));
|
||||
|
||||
x_source = x - _dx;
|
||||
y_source = y - _dy;
|
||||
@@ -282,28 +299,35 @@ void CRotateImage::Translate(int _dx, int _dy)
|
||||
if ((x_source >= 0) && (x_source < width) && (y_source >= 0) && (y_source < height))
|
||||
{
|
||||
p_source = rgb_image + (channels * (y_source * width + x_source));
|
||||
|
||||
for (int _channels = 0; _channels < channels; ++_channels)
|
||||
{
|
||||
p_target[_channels] = p_source[_channels];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int _channels = 0; _channels < channels; ++_channels)
|
||||
p_target[_channels] = 255;
|
||||
{
|
||||
// p_target[_channels] = 255; // nicht vorhandene Pixel werden Weiß gemacht
|
||||
// p_target[_channels] = 0; // nicht vorhandene Pixel werden Schwarz gemacht
|
||||
// p_target[_channels] = 128; // nicht vorhandene Pixel werden Grau gemacht
|
||||
p_target[_channels] = pixel_fill_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// memcpy(rgb_image, odata, memsize);
|
||||
memCopy(odata, rgb_image, memsize);
|
||||
if (!ImageTMP)
|
||||
{
|
||||
free_psram_heap(std::string(TAG) + "->odata", odata);
|
||||
}
|
||||
|
||||
memCopy(temp_image, rgb_image, memsize);
|
||||
|
||||
if (ImageTMP)
|
||||
{
|
||||
ImageTMP->RGBImageRelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
free_psram_heap(std::string(TAG) + "->temp_image", temp_image);
|
||||
}
|
||||
|
||||
RGBImageRelease();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user