-
Nov 27th, 2022, 06:24 AM
#1
Thread Starter
Hyperactive Member
Nearest Neighboor on Arduino
Hi guys I can't really do Nearest Neighboor Resizing on 1D array bitmap with my arduino this is my code
Code:
uint16_t* resizePixels(uint16_t *pixels,int w1,int h1,int w2,int h2) {
uint16_t *temp = new uint16_t[w2*h2] ;
double x_ratio = w1/(double)w2 ;
double y_ratio = h1/(double)h2 ;
double px, py ;
for (int i=0;i<h2;i++) {
for (int j=0;j<w2;j++) {
px = floor(j*x_ratio) ;
py = floor(i*y_ratio) ;
temp[(i*w2)+j] = pixels[(uint16_t)((py*w1)+px)] ;
}
}
return temp ;
}
it seems to do nothing. I use it like this (dbc is drawbitmap function that works)
Code:
dBC(x, y, w,h,resizePixels(Bit1,60,30,w,h));
Nothing happened on the screen. but without resize code,it displays so i know dbc function works
-
Nov 23rd, 2024, 06:30 PM
#2
Re: Nearest Neighboor on Arduino
I know this thread is two years old. Gaouser's code's main issue is due to the use of floor() and the improper handling of pixel indexing. Below is an updated version for anyone who might have a similar problem:
Code:
uint16_t* resizePixels(uint16_t *pixels, int w1, int h1, int w2, int h2) {
uint16_t *temp = new uint16_t[w2 * h2];
double x_ratio = (double)w1 / w2;
double y_ratio = (double)h1 / h2;
int px, py; // Use integer for pixel positions
for (int i = 0; i < h2; i++) {
for (int j = 0; j < w2; j++) {
px = (int)(j * x_ratio); // No need for floor() since casting works here
py = (int)(i * y_ratio); // Same here
// Ensure correct indexing into the original pixel array
temp[(i * w2) + j] = pixels[(py * w1) + px];
}
}
return temp;
}
-
Dec 3rd, 2024, 09:19 AM
#3
Thread Starter
Hyperactive Member
Re: Nearest Neighboor on Arduino
Originally Posted by Peter Porter
I know this thread is two years old. Gaouser's code's main issue is due to the use of floor() and the improper handling of pixel indexing. Below is an updated version for anyone who might have a similar problem:
Code:
uint16_t* resizePixels(uint16_t *pixels, int w1, int h1, int w2, int h2) {
uint16_t *temp = new uint16_t[w2 * h2];
double x_ratio = (double)w1 / w2;
double y_ratio = (double)h1 / h2;
int px, py; // Use integer for pixel positions
for (int i = 0; i < h2; i++) {
for (int j = 0; j < w2; j++) {
px = (int)(j * x_ratio); // No need for floor() since casting works here
py = (int)(i * y_ratio); // Same here
// Ensure correct indexing into the original pixel array
temp[(i * w2) + j] = pixels[(py * w1) + px];
}
}
return temp;
}
Literally thank you man!
-
Dec 3rd, 2024, 09:20 AM
#4
Thread Starter
Hyperactive Member
Re: Nearest Neighboor on Arduino
This forum is really better than Arduino forum. they literally tell you to go resize it on PC there like if the bitmap didnt need to be scaled to 240^240 diffrent combinations
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|