bool bitmap_resize(struct bitmap *img, HermesHandle hermes_h, HermesFormat *fmt, int nw, int nh) { unsigned int state = 0; short bpp = bitmap_get_bpp( img ); int stride = bitmap_get_rowstride( img ); int err; if( img->resized != NULL ) { if( img->resized->width != nw || img->resized->height != nh ) { bitmap_destroy( img->resized ); img->resized = NULL; } else { /* the bitmap is already resized */ return(true); } } /* allocate the mem for resized bitmap */ if (img->opaque == true) { state |= BITMAP_OPAQUE; } img->resized = bitmap_create_ex( nw, nh, bpp, nw*bpp, state, NULL ); if( img->resized == NULL ) { printf("W: %d, H: %d, bpp: %d\n", nw, nh, bpp); assert(img->resized); return(false); } /* allocate an converter, only for resizing */ err = Hermes_ConverterRequest( hermes_h, fmt, fmt ); if( err == 0 ) { return(false); } err = Hermes_ConverterCopy( hermes_h, img->pixdata, 0, /* x src coord of top left in pixel coords */ 0, /* y src coord of top left in pixel coords */ bitmap_get_width( img ), bitmap_get_height( img ), stride, /* stride as bytes */ img->resized->pixdata, 0, /* x dst coord of top left in pixel coords */ 0, /* y dst coord of top left in pixel coords */ nw, nh, bitmap_get_rowstride(img->resized) /* stride as bytes */ ); if( err == 0 ) { bitmap_destroy( img->resized ); img->resized = NULL; return(false); } return(true); }
void *bitmap_create(int w, int h, unsigned int state) { return bitmap_create_ex( w, h, NS_BMP_DEFAULT_BPP, w * NS_BMP_DEFAULT_BPP, state, NULL ); }