Scale background image over X11 window -
now want scale background image, stretch until fits while size of x11 window. there xlib api offers or have "manually"?
have data of image stored in vector of unsigned chars , can play before set background don't know how that. image smaller or bigger window. hints or examples?
new code
i found code here
i tried adapt it. image data stored in vector <unsigned char>
variable
vector<unsigned char> image; int width = 600; int height = 400; int new_width = 820; int new_height = 420; lanczos_size = 3.0; double col_rat = static_cast<double>(width) / static_cast<double>(new_width); double row_rat = static_cast<double>(height) / static_cast<double>(new_height); vector<unsigned char> himage(new_width * height); (unsigned int r=0; r<height; r++) { (unsigned int c=0; c<new_width; c++) { double x = static_cast<double>(c) * col_rat; int floor_x = static_cast<int>(x); himage[r * c] = 0.0; double weight = 0.0; // add terms across filter (unsigned i=floor_x-lanczos_size + 1; i<floor_x+lanczos_size; i++) { if (i >= 0 && < width) { double lanc_term = lanczosfilter(x - i); himage[r * c] += image[r * i] * lanc_term; weight += lanc_term; } } // normalize filter himage[r * c] /= weight; // strap pixel values valid values himage[r * c] = (himage[r * c] > 1.0) ? 1.0 : himage[r * c]; himage[r * c] = (himage[r * c] < 0.0) ? 0.0 : himage[r * c]; } } // apply vertical filter horiz image vector<unsigned char> newimage(new_width * new_height); (unsigned int r=0; r<new_height; r++) { double x = static_cast<double>(r) * row_rat; int floor_x = static_cast<int>(x); (unsigned int c = 0; c < new_width; c++) { newimage[r * c] = 0.0; double weight = 0.0; (unsigned int = floor_x-lanczos_size+1; i<floorx+lanczos_size; i++) { if (i >= 0 && < height) { double lanc_term = lanczosfilter(x - i); newimage[r * c] += himage[i * c] * lanc_term; weight += lanc_term; } } newimage[r * c] /= weight; newimage[r * c] = (newimage[r * c] > 1.0) ? 1.0 : newimage[r * c]; newimage[r * c] = (newimage[r * c] < 0.0) ? 0.0 : newimage[r * c]; } } // store new data image = newimage; // save new size width = new_width; height = new_height;
the lanczos algorithm taken here don't think has problem. now, when use re-size image weird result wonder problem. maybe faster eye see before me.
the data of images stored argbargbargb
Comments
Post a Comment