Image resampling for thumbnails

This commit is contained in:
Simon Robertshaw 2011-05-28 14:19:01 +01:00
parent abb0ceb981
commit 380a45a4c9
3 changed files with 24 additions and 2 deletions

View File

@ -52,6 +52,8 @@ void *ptif_pack(pixel *src, int w, int h, int *result_size);
pixel *ptif_unpack(void *datain, int size, int *w, int *h); pixel *ptif_unpack(void *datain, int size, int *w, int *h);
pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh);
pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f); pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f);
void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch); void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch);

View File

@ -138,6 +138,23 @@ pixel *ptif_unpack(void *datain, int size, int *w, int *h){
return result; return result;
} }
pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh)
{
int y, x;
//int i,j,x,y,w,h,r,g,b,c;
pixel *q;
q = malloc(rw*rh*PIXELSIZE);
//TODO: Actual resampling, this is just cheap nearest pixel crap
for (y=0; y<rh; y++)
for (x=0; x<rw; x++)
{
q[rw*y+x] = src[sw*(y*sh/rh)+(x*sw/rw)];
}
//*qw = w;
//*qh = h;
return q;
}
pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f) pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f)
{ {
int i,j,x,y,w,h,r,g,b,c; int i,j,x,y,w,h,r,g,b,c;

View File

@ -2493,10 +2493,13 @@ int search_ui(pixel *vid_buf)
{ {
//render_thumb(search_thumbs[pos], search_thsizes[pos], 1, v_buf, gx, gy, GRID_S); //render_thumb(search_thumbs[pos], search_thsizes[pos], 1, v_buf, gx, gy, GRID_S);
int finh, finw; int finh, finw;
char *thumb_imgdata = ptif_unpack(search_thumbs[pos], search_thsizes[pos], &finw, &finh); pixel *thumb_rsdata = NULL;
pixel *thumb_imgdata = ptif_unpack(search_thumbs[pos], search_thsizes[pos], &finw, &finh);
if(thumb_imgdata!=NULL){ if(thumb_imgdata!=NULL){
draw_image(v_buf, thumb_imgdata, gx, gy, finw, finh, 255); thumb_rsdata = resample_img(thumb_imgdata, finw, finh, XRES/GRID_S, YRES/GRID_S);
draw_image(v_buf, thumb_rsdata, gx, gy, XRES/GRID_S, YRES/GRID_S, 255);
free(thumb_imgdata); free(thumb_imgdata);
free(thumb_rsdata);
} }
thumb_drawn[pos] = 1; thumb_drawn[pos] = 1;
} }