Exemplo n.º 1
0
void mfc_render_flip(void *mfc_render_handle)
{
	HRESULT                hRet;

	_MFC_RENDER_OVERLAY   *pMFC_RENDER_OVERLAY;
	LPDIRECTDRAWSURFACE    pDDSOverlay;

	if (mfc_render_handle == NULL) {
		PRINT_ERRMSG(TEXT("\nmfc_render_handle is NULL."));
		return;
	}

	pMFC_RENDER_OVERLAY = (_MFC_RENDER_OVERLAY *) mfc_render_handle;


	if (pMFC_RENDER_OVERLAY->show == 0) {
		RECT  rs, rd;

		rs.left   = 0; 
		rs.top    = 0;
		rs.right  = pMFC_RENDER_OVERLAY->src_wd;
		rs.bottom = pMFC_RENDER_OVERLAY->src_hi;
		rd.left   = pMFC_RENDER_OVERLAY->x; 
		rd.top    = pMFC_RENDER_OVERLAY->y;
		rd.right  = pMFC_RENDER_OVERLAY->dst_wd;
		rd.bottom = pMFC_RENDER_OVERLAY->dst_hi;


		pDDSOverlay = pMFC_RENDER_OVERLAY->pDD;

	    // Update the overlay parameters.
	    hRet = pDDSOverlay->UpdateOverlay(&rs, g_pDDSPrimary, &rd, DDOVER_SHOW, NULL);
		if (hRet != DD_OK) {
			PRINT_ERRMSG(TEXT("Unable to show overlay surface!"));
			return;
		}
	
	
		hRet = pDDSOverlay->SetOverlayPosition(0, 0);
		if (hRet != DD_OK) {
			PRINT_ERRMSG(TEXT("Unable to SetOverlayPosition!"));
			return;
		}

		pMFC_RENDER_OVERLAY->show = 1;
	}

	if (pMFC_RENDER_OVERLAY->which == 0) {
		pMFC_RENDER_OVERLAY->pDD->Flip(NULL, 0);
		pMFC_RENDER_OVERLAY->which = 1;
	}
	else if (pMFC_RENDER_OVERLAY->which == 1) {
		pMFC_RENDER_OVERLAY->pDD_back->Flip(NULL, 0);
		pMFC_RENDER_OVERLAY->which = 0;
	}
}
Exemplo n.º 2
0
void mfc_render_delete_overlay(void *mfc_render_handle)
{
	_MFC_RENDER_OVERLAY   *pMFC_RENDER_OVERLAY;
	LPDIRECTDRAWSURFACE    pDDSOverlay;


	if (mfc_render_handle == NULL) {
		PRINT_ERRMSG(TEXT("\nmfc_render_handle is NULL."));
		return;
	}

	pMFC_RENDER_OVERLAY = (_MFC_RENDER_OVERLAY *) mfc_render_handle;

	pDDSOverlay = pMFC_RENDER_OVERLAY->pDD;
	if (pDDSOverlay != NULL) {
		// Use UpdateOverlay() with the DDOVER_HIDE flag to remove an overlay 
		// from the display.
		pDDSOverlay->UpdateOverlay(NULL, g_pDDSPrimary, NULL, DDOVER_HIDE, NULL);
		pDDSOverlay->Release();
		pDDSOverlay = NULL;
	}

	pDDSOverlay = (LPDIRECTDRAWSURFACE) pMFC_RENDER_OVERLAY->pDD_back;
	if (pDDSOverlay != NULL) {
		// Use UpdateOverlay() with the DDOVER_HIDE flag to remove an overlay 
		// from the display.
		pDDSOverlay->UpdateOverlay(NULL, g_pDDSPrimary, NULL, DDOVER_HIDE, NULL);
		pDDSOverlay->Release();
		pDDSOverlay = NULL;
	}
}
Exemplo n.º 3
0
BOOL mfc_render_init(HWND hWnd)
{
	DDSURFACEDESC    ddsd;
	DDCAPS           ddcaps;

	HRESULT          hRet;

	///////////////////////////////////////////////////////////////////////////
	// Create the main DirectDraw object
	///////////////////////////////////////////////////////////////////////////
	hRet = DirectDrawCreate(NULL, &g_pDD, NULL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("DirectDrawCreate FAILED"));

	// Get exclusive mode
	hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("SetCooperativeLevel FAILED"));


	// Get a primary surface interface pointer (only needed for init.)

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
	hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("CreateSurface FAILED"));

	// See if we can support overlays.
	memset(&ddcaps, 0, sizeof(ddcaps));
	ddcaps.dwSize = sizeof(ddcaps);
	hRet = g_pDD->GetCaps(&ddcaps, NULL);
	if (hRet != DD_OK)
		return PRINT_ERRMSG(TEXT("GetCaps FAILED"));

	if (ddcaps.dwOverlayCaps == 0)
		return PRINT_ERRMSG(TEXT("Overlays are not supported in hardware!"));


	// SW YUV->RGB conversion table initialization
	_initConvTab();

	return TRUE;
}
Exemplo n.º 4
0
char *
my_getopt(int nargc, char **nargv, char *ostr, char **errMsg)
{
    char svstr [256];
    char *cp1 = svstr;
    char *cp2 = svstr;
    char *optName;
    int i, num_arg;

    if ((optName = nargv[optind]) == NULL)
        return (NULL);
    if (optind >= nargc || *optName != '-')
        return (NULL);
    if (optName[1] && *++optName == '-') {
        ++optind;
        return(NULL);
    }
    if (ostr == NULL)
        return(NULL);
    strcpy (svstr, ostr);
    num_arg = 0;
    optarg = NULL;

    while (*cp2) {
        int cp2len = strlen(cp2);
        for (i=0; i<cp2len; i++) {
            if (cp2[i] == '|') {
                num_arg = 0;
                cp2[i] = '\0';
                break;
            }
            else if (cp2[i] == ':') {
                num_arg = 1;
                cp2[i] = '\0';
                break;
            }
        }
        if (i >= cp2len)
            return (BADCH);

        if (!strcmp (optName, cp1)) {
            if (num_arg) {
                if (nargc <= optind + 1) {
                    PRINT_ERRMSG (errMsg, (_i18n_msg_get(ls_catd,NL_SETN,650, "%s: option requires an argument -- %s\n")), nargv[0], optName);  /* catgets 650 */
                    return (BADCH);
                }
                optarg = nargv[++optind];
            }
            ++optind;
            return (optName);
        } else if (!strncmp(optName, cp1, strlen(cp1))) {
            if (num_arg == 0) {
                PRINT_ERRMSG (errMsg, (_i18n_msg_get(ls_catd,NL_SETN,651, "%s: option cannot have an argument -- %s\n")),  /* catgets 651 */
                              nargv[0], cp1);
                return (BADCH);
            }

            optarg = optName + strlen(cp1);
            ++optind;
            return (cp1);
        }

        cp1 = &cp2[i];
        cp2 = ++cp1;
    }
    PRINT_ERRMSG (errMsg, (_i18n_msg_get(ls_catd,NL_SETN,652, "%s: illegal option -- %s\n")), nargv[0], optName); /* catgets 652 */
    return (BADCH);

}
Exemplo n.º 5
0
void mfc_render_do(void *mfc_render_handle, unsigned char *pImg, int width, int height, int img_type)
{
	_MFC_RENDER_OVERLAY   *pMFC_RENDER_OVERLAY;

	DDSURFACEDESC          ddsd;
	HRESULT                hRet;

	LPDIRECTDRAWSURFACE    pDDSOverlay;	// Overlay Surface.

	unsigned char *pSurf;
	int            y_size, u_size;


	switch (img_type) {
	case MFC_RENDER_IMAGE_TYPE_YUV420:
	case MFC_RENDER_IMAGE_TYPE_RGB565:
	case MFC_RENDER_IMAGE_TYPE_YV12:
		break;

	default:
		PRINT_ERRMSG(TEXT("img_type is not supported."));
		return;
	}


	if (mfc_render_handle == NULL) {
		PRINT_ERRMSG(TEXT("\nmfc_render_handle is NULL."));
		return;
	}
	if (pImg == NULL) {
		PRINT_ERRMSG(TEXT("Input image is NULL."));
		return;
	}

	pMFC_RENDER_OVERLAY = (_MFC_RENDER_OVERLAY *) mfc_render_handle;


	if (pMFC_RENDER_OVERLAY->which == 1) {
		pDDSOverlay = pMFC_RENDER_OVERLAY->pDD;
	}
	else if (pMFC_RENDER_OVERLAY->which == 0) {
		pDDSOverlay = pMFC_RENDER_OVERLAY->pDD_back;
	}


	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);

	// Lock down the surface so we can modify it's contents.
	hRet = pDDSOverlay->Lock( NULL, &ddsd, DDLOCK_WAITNOTBUSY, NULL);
	if (hRet != DD_OK) {
		PRINT_ERRMSG(TEXT("Unable to show overlay surface!"));
		return;
	}

	pSurf = (LPBYTE)ddsd.lpSurface;

	y_size = width * height;
	u_size = y_size >> 2;


	switch (pMFC_RENDER_OVERLAY->surface_type) {
	case MFC_RENDER_SURFACE_TYPE_YV12:	// YV12의 경우는 그대로 복사한다.
		if (img_type == MFC_RENDER_IMAGE_TYPE_YUV420) {
			memcpy(pSurf, pImg, y_size);
			memcpy(pSurf + y_size, pImg + y_size + u_size, u_size);
			memcpy(pSurf + y_size + u_size, pImg + y_size, u_size);
		}
		else if (img_type == MFC_RENDER_IMAGE_TYPE_YV12) {
			memcpy(pSurf, pImg, y_size + (u_size << 1));
		}
		else if (img_type == MFC_RENDER_IMAGE_TYPE_RGB565) {
			PRINT_ERRMSG(TEXT("This case is not supported. : (Surface type is YV12 and Image type is RGB565)"));
		}
		break;

	case MFC_RENDER_SURFACE_TYPE_RGB565:	// RGB565의 경우는 SW YUV->RGB 변환 수행
		if (img_type == MFC_RENDER_IMAGE_TYPE_YUV420) {
			_yuv420ToRgb565(pImg, pImg + y_size, pImg + y_size + u_size, width, height,
							pSurf, width, height,
							0);
		}
		else if (img_type == MFC_RENDER_IMAGE_TYPE_YV12) {
			_yuv420ToRgb565(pImg, pImg + y_size + u_size, pImg + y_size, width, height,
							pSurf, width, height,
							0);
		}
		else if (img_type == MFC_RENDER_IMAGE_TYPE_RGB565) {
			memcpy(pSurf, pImg, y_size << 1);
		}
		break;

	default:
		break;
	}

    pDDSOverlay->Unlock(NULL);

}
Exemplo n.º 6
0
void *mfc_render_create_overlay(int surface_type,
                                int x, int y,
                                int src_wd, int src_hi,
                                int dst_wd, int dst_hi)
{
	_MFC_RENDER_OVERLAY   *pMFC_RENDER_OVERLAY;
	LPDIRECTDRAWSURFACE    pDDSOverlay = NULL;	// Overlay Surface.
	DDSURFACEDESC          ddsd;

	HRESULT                hRet;


	switch (surface_type) {
	case MFC_RENDER_SURFACE_TYPE_YV12:
	case MFC_RENDER_SURFACE_TYPE_RGB565:
		break;

	default:
		PRINT_ERRMSG(TEXT("surface_type is not supported."));
		return NULL;
	}


	pMFC_RENDER_OVERLAY = (_MFC_RENDER_OVERLAY *) malloc(sizeof(_MFC_RENDER_OVERLAY));
	if (pMFC_RENDER_OVERLAY == NULL) {
		PRINT_ERRMSG(TEXT("malloc failed."));
		return NULL;
	}

	// Create the overlay flipping surface. We will attempt the pixel formats
	// in our table one at a time until we find one that jives.

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize            = sizeof(ddsd);
	ddsd.ddsCaps.dwCaps    = DDSCAPS_OVERLAY | DDSCAPS_FLIP;
	ddsd.dwFlags           = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_BACKBUFFERCOUNT | DDSD_PIXELFORMAT;
	ddsd.dwWidth           = src_wd;
	ddsd.dwHeight          = src_hi;
	ddsd.dwBackBufferCount = 1;
	ddsd.ddpfPixelFormat   = ddpfOverlayFormats[surface_type];

	hRet = g_pDD->CreateSurface(&ddsd, &pDDSOverlay, NULL);
	if (hRet != DD_OK) {
		PRINT_ERRMSG(TEXT("Unable to create overlay surface!"));
		free(pMFC_RENDER_OVERLAY);
		return NULL;
	}

RETAILMSG(1,(L"\n\t  OVERLAY SURFACE TYPE %d\n", surface_type));

	pMFC_RENDER_OVERLAY->pDD       = pDDSOverlay;
	pMFC_RENDER_OVERLAY->pDD_back  = NULL;	// 아래 EnumAttachedSurface을 통하여 세팅됨
	pMFC_RENDER_OVERLAY->which     = 0;
	pMFC_RENDER_OVERLAY->show      = 0;

	pMFC_RENDER_OVERLAY->x             = x;
	pMFC_RENDER_OVERLAY->y             = y;
	pMFC_RENDER_OVERLAY->src_wd        = src_wd;
	pMFC_RENDER_OVERLAY->src_hi        = src_hi;
	pMFC_RENDER_OVERLAY->dst_wd        = dst_wd;
	pMFC_RENDER_OVERLAY->dst_hi        = dst_hi;

	pMFC_RENDER_OVERLAY->surface_type  = surface_type;


	hRet = pDDSOverlay->EnumAttachedSurfaces((LPVOID)(&pMFC_RENDER_OVERLAY->pDD_back), EnumSurfacesCallback);
	if (hRet != DD_OK) {
		PRINT_ERRMSG(TEXT("Unable to EnumAttachedSurfaces!"));
		pDDSOverlay->Release();
		free(pMFC_RENDER_OVERLAY);
		return NULL;
	}


	return (void *) pMFC_RENDER_OVERLAY;
}