// Modify capture window (if necessary) // and calculate downscaling // Return -1 on error static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor) { int maxlen = max - min; int len = *end - *beg + 1; int newlen = w9966_findlen(len, size, maxlen); int err = newlen - len; // Check for bad format if (newlen > maxlen || newlen < size) return -1; // Set factor (6 bit fixed) *factor = (64*size) / newlen; if (*factor == 64) *factor = 0x00; // downscale is disabled else *factor |= 0x80; // set downscale-enable bit // Modify old beginning and end *beg -= err / 2; *end += err - (err / 2); // Move window if outside borders if (*beg < min) { *end += min - *beg; *beg += min - *beg; } if (*end > max) { *beg -= *end - max; *end -= *end - max; } return 0; }
static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor) { int maxlen = max - min; int len = *end - *beg + 1; int newlen = w9966_findlen(len, size, maxlen); int err = newlen - len; if (newlen > maxlen || newlen < size) return -1; *factor = (64*size) / newlen; if (*factor == 64) *factor = 0x00; else *factor |= 0x80; *beg -= err / 2; *end += err - (err / 2); if (*beg < min) { *end += min - *beg; *beg += min - *beg; } if (*end > max) { *beg -= *end - max; *end -= *end - max; } return 0; }