Does this look right for enlarging?
Download adjust_yt.cLanguage: c
#include <stdio.h>
#include <stdbool.h>
static const unsigned int w_min = 1920, h_min = 1080,
w_max = 4096, h_max = 3072;
static unsigned int round_to(unsigned int x, unsigned int scale)
{
return(((x+scale-1)/scale)*scale);
}
static bool is_mult_of(unsigned int x, unsigned int mult)
{
unsigned int x2 = round_to(x, mult);
return(x == x2);
}
static inline unsigned int enlarge_pow2(unsigned int w, unsigned int h)
{
unsigned int m = 1;
while ((w < w_min) && (h < h_min)) //while ((w <= w_min) && (h <= h_min))
{
w <<= 1;
h <<= 1;
if ((w > w_max) || (h > h_max)) { break; }
m <<= 1;
}
return(m);
}
static void output(unsigned int w, unsigned int h, unsigned int m)
{
printf("In: %ux%u Out: %ux%u Multiplier: %u 16: %d\n", w, h, w*m, h*m, m, is_mult_of(w*m, 16) && is_mult_of(h*m, 16));
}
static void adjust(unsigned int width, unsigned int height)
{
unsigned int multiplier = enlarge_pow2(width, height);
output(width, height, multiplier);
}
int main()
{
adjust(160, 144);
adjust(240, 160);
adjust(256, 192);
adjust(256, 224);
adjust(256, 240);
adjust(256, 384);
adjust(320, 200);
adjust(320, 224);
adjust(320, 240);
adjust(384, 216);
adjust(384, 224);
adjust(640, 480);
adjust(800, 600);
adjust(1024, 768);
adjust(1280, 1024);
adjust(720, 404);
adjust(1280, 800);
adjust(1024, 1024);
adjust(1920, 1080);
adjust(1440, 1050);
adjust(1440, 900);
adjust(1440, 960);
adjust(1440, 1024);
adjust(1440, 1080);
adjust(1366, 768);
adjust(1024, 770);
adjust(80, 72);
adjust(330, 180);
adjust(1964, 1064);
return(0);
}
Output:
In: 160x144 Out: 1280x1152 Multiplier: 8 16: 1
In: 240x160 Out: 1920x1280 Multiplier: 8 16: 1
In: 256x192 Out: 2048x1536 Multiplier: 8 16: 1
In: 256x224 Out: 2048x1792 Multiplier: 8 16: 1
In: 256x240 Out: 2048x1920 Multiplier: 8 16: 1
In: 256x384 Out: 1024x1536 Multiplier: 4 16: 1
In: 320x200 Out: 2560x1600 Multiplier: 8 16: 1
In: 320x224 Out: 2560x1792 Multiplier: 8 16: 1
In: 320x240 Out: 2560x1920 Multiplier: 8 16: 1
In: 384x216 Out: 3072x1728 Multiplier: 8 16: 1
In: 384x224 Out: 3072x1792 Multiplier: 8 16: 1
In: 640x480 Out: 2560x1920 Multiplier: 4 16: 1
In: 800x600 Out: 1600x1200 Multiplier: 2 16: 1
In: 1024x768 Out: 2048x1536 Multiplier: 2 16: 1
In: 1280x1024 Out: 2560x2048 Multiplier: 2 16: 1
In: 720x404 Out: 2880x1616 Multiplier: 4 16: 1
In: 1280x800 Out: 2560x1600 Multiplier: 2 16: 1
In: 1024x1024 Out: 2048x2048 Multiplier: 2 16: 1
In: 1920x1080 Out: 1920x1080 Multiplier: 1 16: 0
In: 1440x1050 Out: 2880x2100 Multiplier: 2 16: 0
In: 1440x900 Out: 2880x1800 Multiplier: 2 16: 0
In: 1440x960 Out: 2880x1920 Multiplier: 2 16: 1
In: 1440x1024 Out: 2880x2048 Multiplier: 2 16: 1
In: 1440x1080 Out: 1440x1080 Multiplier: 1 16: 0
In: 1366x768 Out: 2732x1536 Multiplier: 2 16: 0
In: 1024x770 Out: 2048x1540 Multiplier: 2 16: 0
In: 80x72 Out: 1280x1152 Multiplier: 16 16: 1
In: 330x180 Out: 2640x1440 Multiplier: 8 16: 1
In: 1964x1064 Out: 1964x1064 Multiplier: 1 16: 0
Or do we prefer this? (swap commented out while loop)
In: 160x144 Out: 1280x1152 Multiplier: 8 16: 1
In: 240x160 Out: 1920x1280 Multiplier: 8 16: 1
In: 256x192 Out: 2048x1536 Multiplier: 8 16: 1
In: 256x224 Out: 2048x1792 Multiplier: 8 16: 1
In: 256x240 Out: 2048x1920 Multiplier: 8 16: 1
In: 256x384 Out: 1024x1536 Multiplier: 4 16: 1
In: 320x200 Out: 2560x1600 Multiplier: 8 16: 1
In: 320x224 Out: 2560x1792 Multiplier: 8 16: 1
In: 320x240 Out: 2560x1920 Multiplier: 8 16: 1
In: 384x216 Out: 3072x1728 Multiplier: 8 16: 1
In: 384x224 Out: 3072x1792 Multiplier: 8 16: 1
In: 640x480 Out: 2560x1920 Multiplier: 4 16: 1
In: 800x600 Out: 1600x1200 Multiplier: 2 16: 1
In: 1024x768 Out: 2048x1536 Multiplier: 2 16: 1
In: 1280x1024 Out: 2560x2048 Multiplier: 2 16: 1
In: 720x404 Out: 2880x1616 Multiplier: 4 16: 1
In: 1280x800 Out: 2560x1600 Multiplier: 2 16: 1
In: 1024x1024 Out: 2048x2048 Multiplier: 2 16: 1
In: 1920x1080 Out: 3840x2160 Multiplier: 2 16: 1
In: 1440x1050 Out: 2880x2100 Multiplier: 2 16: 0
In: 1440x900 Out: 2880x1800 Multiplier: 2 16: 0
In: 1440x960 Out: 2880x1920 Multiplier: 2 16: 1
In: 1440x1024 Out: 2880x2048 Multiplier: 2 16: 1
In: 1440x1080 Out: 2880x2160 Multiplier: 2 16: 1
In: 1366x768 Out: 2732x1536 Multiplier: 2 16: 0
In: 1024x770 Out: 2048x1540 Multiplier: 2 16: 0
In: 80x72 Out: 1280x1152 Multiplier: 16 16: 1
In: 330x180 Out: 2640x1440 Multiplier: 8 16: 1
In: 1964x1064 Out: 1964x1064 Multiplier: 1 16: 0
Are there any cases that need to be handled that may not be handled here?