예제 #1
0
/* if requested bpp is not found the mode with closest bpp is returned */
int
get_mode_any_format(int width, int height, int bpp)
{
    int i, closest, delta, min_delta;

    if (PgGetVideoModeList(&mode_list) < 0) {
        return -1;
    }

    SDL_qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short),
              compare_modes_by_res);

    for (i = 0; i < mode_list.num_modes; i++) {
        if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) {
            return 0;
        }
        if ((mode_info.width == width) && (mode_info.height == height)) {
            break;
        }
    }

    if (i < mode_list.num_modes) {
        /* get closest bpp */
        closest = i++;
        if (mode_info.bits_per_pixel == bpp) {
            return mode_list.modes[closest];
        }

        min_delta = abs(mode_info.bits_per_pixel - bpp);

        while (1) {
            if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) {
                return 0;
            }

            if ((mode_info.width != width)
                || (mode_info.height != height)) {
                break;
            } else {
                if (mode_info.bits_per_pixel == bpp) {
                    closest = i;
                    break;
                } else {
                    delta = abs(mode_info.bits_per_pixel - bpp);
                    if (delta < min_delta) {
                        closest = i;
                        min_delta = delta;
                    }
                    i++;
                }
            }
        }
        return mode_list.modes[closest];
    }

    return 0;
}
예제 #2
0
파일: SDL_ph_modes.c 프로젝트: 0-14N/NDroid
/* if there is no mode then zero is returned             */
int ph_GetVideoMode(int width, int height, int bpp)
{
    int i;
    int modestage=0;
    int closestmode=0;

    if (PgGetVideoModeList(&mode_list) < 0)
    {
        return -1;
    }

    /* special case for the double-sized 320x200 mode */
    if ((width==640) && (height==400))
    {
       modestage=1;
    }

    /* search list for exact match */
    for (i=0; i<mode_list.num_modes; i++)
    {
        if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
        {
            return 0;
        }

        if ((mode_info.width == width) && (mode_info.height == height) && 
            (mode_info.bits_per_pixel == bpp))
        {
            return mode_list.modes[i];
        }
        else
        {
           if ((modestage) && (mode_info.width == width) && (mode_info.height == height+80) && 
               (mode_info.bits_per_pixel == bpp))
           {
              modestage=2;
              closestmode=mode_list.modes[i];
           }
        }
    }

    /* if we are here, then no 640x400xbpp mode found and we'll emulate it via 640x480xbpp mode */
    if (modestage==2)
    {
       return closestmode;
    }

    return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
}