boards: cxd56_imageproc: Fix some bugs in imageproc driver
- Fix resize scaling factor setting mistakes - Fix input vertical size check is not worked - Fix comment mistakes and style in header file
This commit is contained in:
parent
feabe52fd8
commit
987ca0c682
@ -83,7 +83,6 @@
|
||||
#define ISE_SRC_VSIZE_MAX (2160)
|
||||
#define ISE_DST_HSIZE_MAX (768)
|
||||
#define ISE_DST_VSIZE_MAX (1024)
|
||||
#define MAX_RATIO (64)
|
||||
|
||||
/* Command code */
|
||||
|
||||
@ -228,55 +227,33 @@ static int intr_handler_rot(int irq, void *context, void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ratio_check(uint16_t src, uint16_t dest)
|
||||
{
|
||||
uint16_t ratio = 1;
|
||||
|
||||
if (src > dest)
|
||||
{
|
||||
ratio = src / dest;
|
||||
}
|
||||
else if (src < dest)
|
||||
{
|
||||
ratio = dest / src;
|
||||
}
|
||||
|
||||
if (ratio > MAX_RATIO)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint16_t calc_ratio(uint16_t src, uint16_t dest)
|
||||
{
|
||||
uint16_t r;
|
||||
|
||||
if (src > dest)
|
||||
/* Calculate scale factor for the ratio
|
||||
*
|
||||
* ratio = 256 / scalefactor
|
||||
*
|
||||
* scalefactor is from 16383 (=x1/64) to 4 (=x64).
|
||||
* Actually, scalefactor of x1/64 is 16384, but hardware
|
||||
* can take 14 bits (0x3fff), so we need set 16383 for x1/64.
|
||||
*/
|
||||
|
||||
r = (uint32_t)src * 256 / dest;
|
||||
if (r == 16384)
|
||||
{
|
||||
r = src / dest;
|
||||
if (r == 2 || r == 4 || r == 8 || r == 16 || r == 32 || r == 64)
|
||||
{
|
||||
return 256 * r;
|
||||
}
|
||||
}
|
||||
else if (src < dest)
|
||||
{
|
||||
r = dest / src;
|
||||
if (r == 2 || r == 4 || r == 8 || r == 16 || r == 32 || r == 64)
|
||||
{
|
||||
return 256 / r;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 256;
|
||||
r = 16383;
|
||||
}
|
||||
|
||||
if (r < 4 || r > 16383)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void *set_rop_cmd(void *cmdbuf,
|
||||
void *srcaddr,
|
||||
void *destaddr,
|
||||
@ -356,8 +333,8 @@ static void *set_rop_cmd(void *cmdbuf,
|
||||
|
||||
sc->desth = destwidth - 1;
|
||||
sc->destv = destheight - 1;
|
||||
sc->ratiov = rv - 1;
|
||||
sc->ratioh = rh - 1;
|
||||
sc->ratiov = rv;
|
||||
sc->ratioh = rh;
|
||||
sc->hphaseinit = 1;
|
||||
sc->vphaseinit = 1;
|
||||
sc->intpmode = 0; /* XXX: HV Linear interpolation */
|
||||
@ -629,19 +606,13 @@ int imageproc_resize(uint8_t * ibuf,
|
||||
}
|
||||
|
||||
if ((ihsize > ISE_SRC_HSIZE_MAX || ihsize < HSIZE_MIN) ||
|
||||
(ivsize > ISE_SRC_VSIZE_MAX || ihsize < VSIZE_MIN) ||
|
||||
(ivsize > ISE_SRC_VSIZE_MAX || ivsize < VSIZE_MIN) ||
|
||||
(ohsize > ISE_DST_HSIZE_MAX || ohsize < HSIZE_MIN) ||
|
||||
(ovsize > ISE_DST_VSIZE_MAX || ovsize < VSIZE_MIN))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((ratio_check(ihsize, ohsize) != 0) ||
|
||||
(ratio_check(ivsize, ovsize) != 0))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = nxmutex_lock(&g_gelock);
|
||||
if (ret)
|
||||
{
|
||||
@ -714,7 +685,7 @@ int imageproc_clip_and_resize(uint8_t * ibuf,
|
||||
}
|
||||
|
||||
if ((ihsize > ISE_SRC_HSIZE_MAX || ihsize < HSIZE_MIN) ||
|
||||
(ivsize > ISE_SRC_VSIZE_MAX || ihsize < VSIZE_MIN) ||
|
||||
(ivsize > ISE_SRC_VSIZE_MAX || ivsize < VSIZE_MIN) ||
|
||||
(ohsize > ISE_DST_HSIZE_MAX || ohsize < HSIZE_MIN) ||
|
||||
(ovsize > ISE_DST_VSIZE_MAX || ovsize < VSIZE_MIN))
|
||||
{
|
||||
@ -737,24 +708,12 @@ int imageproc_clip_and_resize(uint8_t * ibuf,
|
||||
clip_width = clip_rect->x2 - clip_rect->x1 + 1;
|
||||
clip_height = clip_rect->y2 - clip_rect->y1 + 1;
|
||||
|
||||
if ((ratio_check(clip_width, ohsize) != 0) ||
|
||||
(ratio_check(clip_height, ovsize) != 0))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
pix_bytes = bpp >> 3;
|
||||
ibuf = ibuf + (clip_rect->x1 * pix_bytes +
|
||||
clip_rect->y1 * ihsize * pix_bytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((ratio_check(ihsize, ohsize) != 0) ||
|
||||
(ratio_check(ivsize, ovsize) != 0))
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
clip_width = ihsize;
|
||||
clip_height = ivsize;
|
||||
}
|
||||
|
@ -145,10 +145,10 @@ extern "C"
|
||||
* image will be stored to obuf.
|
||||
*
|
||||
* For ohsize and ovsize, specify output size calculated by multiply
|
||||
* in range 1/2^n to 2^n (n=0..5) against ihsize and ivsize.
|
||||
* in range from x1/64 to x64 against ihsize and ivsize.
|
||||
*
|
||||
* This function can be processing for YUV422 color format.
|
||||
* So all of specified sizes must be multiple of 2.
|
||||
* So all of specified horizontal size must be multiple of 2.
|
||||
*
|
||||
* And there is limitation about output size below.
|
||||
*
|
||||
@ -168,6 +168,9 @@ extern "C"
|
||||
* [in] bpp: Bits per pixel (16 or 8)
|
||||
*
|
||||
* return 0 on success, otherwise error code.
|
||||
*
|
||||
* CAUTION: In enlarge by higher scaling ratio, it may not be output
|
||||
* all of the pixels.
|
||||
*/
|
||||
|
||||
int imageproc_resize(uint8_t * ibuf, uint16_t ihsize, uint16_t ivsize,
|
||||
|
Loading…
Reference in New Issue
Block a user