COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 07-13-2020, 05:05 AM   #1
random_id
Human being with feelings
 
random_id's Avatar
 
Join Date: May 2012
Location: PA, USA
Posts: 356
Default Better bitmap resizing in IPlug1

I have been using Youlean’s branch of IPlug1 for resizable graphics. Through some experimentation, I found a way to greatly improve bitmap resizing. The original resizing was done with bilinear resampling in IGraphics.cpp. The bitmaps can get fuzzy very quickly, even when close to their original size.

I found Aleksey Vaneev (from Voxengo) has created a library for resampling images. It is very easy to replace within IGraphics. The repo is located at https://github.com/avaneev/avir. It includes 5 header files, but I think only one is needed for simple resizing.

The main resizing is handled by avir::CImageResizer<>; however, after emailing Aleksey, he suggested to use avir::CLancIR. CLancIR produces great resizing and is very fast for good realtime results. I did use CImageResizer initially, and it would work in realtime, but CLancIR is much smoother.

So, here are the changes I added to IGraphics.h/cpp to use the different resizing. Please note, this is not the prettiest way of adding the code. You could easily create different functions and keep the bilinear resampling if you wanted to. I did this as a test and decided to keep everything within the original ResizeBilinear() function.

In IGraphics.h, add the header file wherever you same the lancir.h file within your project. Example,
Code:
#include "../../avir/lancir.h"
In IGraphics.cpp, comment out the entire body of the ResizeBilinear() function. In it’s place, add the following as the new ResizeBilinear() function. I have added comments to explain things.
Code:
//declare the resizer class one time, but this could be moved as a private member in IGraphics.h
static avir::CLancIR ImageResizer; 

//you could also try other resizers like the following, but CLancIR appears to be much faster
//If you try the following, replace the lancir.h include with avir.h
//static avir::CImageResizer<> ImageResizer(8, 0, avir::CImageResizerParamsHigh());

//since ints are used, some problems with rounding can occur.  To help, calculate ratio with the largest
//between width and height.  
double ratio = 1.; 
if(h1 > w1)  ratio = (double)h1 / (double)h2;
else ratio = (double)w1 / (double)w2;

ImageResizer.resizeImage((uint8_t *)input, sourceRowSpan, h1, 0, (uint8_t*)out, destinationRowSpan, h2, 4, ratio);
__________________
Website: LVC-Audio
random_id is offline   Reply With Quote
Old 07-14-2020, 10:32 AM   #2
Nonlinear
Human being with feelings
 
Join Date: Apr 2018
Posts: 396
Default

Thank you for sharing this! 👍
Nonlinear is offline   Reply With Quote
Old 07-15-2020, 08:03 AM   #3
olilarkin
Human being with feelings
 
Join Date: Apr 2009
Location: Berlin, Germany
Posts: 1,248
Default

cool stuff. may look at integrating this in iPlug2 :-)
__________________
VirtualCZ | Endless Series | iPlug2 | Linkedin | Facebook
olilarkin is offline   Reply With Quote
Old 07-17-2020, 08:50 AM   #4
boysya
Human being with feelings
 
Join Date: Jul 2020
Posts: 1
Default

Thank you so much! it's that I looking for
boysya is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.