/** * VFW frame grab callback function */ static LRESULT PASCAL camera_grabber_callback(HWND hWnd, LPVIDEOHDR lpVHdr) { #define PNG_HEADER_SIZE (1000) int i; char* pOutput; int copyLineBytes; /* Free previous frame buffer */ if (NULL != _pFrameBuffer) { FREE(_pFrameBuffer); _pFrameBuffer = NULL; } /* Free encoding buffer */ if (NULL != _pEncodingBuffer) { FREE(_pEncodingBuffer); _pEncodingBuffer = NULL; } /* Grab current frame */ if (JAVACALL_TRUE == _grabFrame) { copyLineBytes = (_grabWidth * 3); _pFrameBuffer = MALLOC(lpVHdr->dwBytesUsed); _pEncodingBuffer = MALLOC(javautil_media_get_png_size(_grabWidth, _grabHeight)); if (_pFrameBuffer && _pEncodingBuffer) { pOutput = _pFrameBuffer; /* Impl note: - Top / Bottom Reverse */ for (i = _grabHeight - 1; i >= 0; --i) { memcpy(pOutput, lpVHdr->lpData + (i * copyLineBytes), copyLineBytes); pOutput += copyLineBytes; } _encodingDataSize = javautil_media_rgb_to_png( _pFrameBuffer, _pEncodingBuffer, _grabWidth, _grabHeight); javanotify_on_media_notification(JAVACALL_EVENT_MEDIA_SNAPSHOT_FINISHED, _playerId, 0); } else { if (_pFrameBuffer) { FREE(_pFrameBuffer); _pFrameBuffer = NULL; } if (_pEncodingBuffer) { FREE(_pEncodingBuffer); _pEncodingBuffer = NULL; } } _grabFrame = JAVACALL_FALSE; } InvalidateRect(GET_MCIWND_HWND(), NULL, FALSE); return 0; }
static javacall_result convertPNG(javacall_image_filter_handle ifHandle, javacall_amms_frame* pInput, javacall_amms_frame** ppOutput) { javacall_amms_frame_RGB32* pData; int width, height; int outLength; javacall_amms_frame* pOutput; if (ppOutput == NULL) return JAVACALL_INVALID_ARGUMENT; *ppOutput = NULL; if ((ifHandle == NULL) || (pInput == NULL) || (pInput->extType != JAVACALL_AMMS_ET_RGB32_DATA)) return JAVACALL_INVALID_ARGUMENT; pData = (javacall_amms_frame_RGB32*)pInput; width = pData->width; height = pData->height; pOutput = javacall_amms_create_frame_raw_in( javautil_media_get_png_size(width, height)); if (!pOutput) return JAVACALL_OUT_OF_MEMORY; outLength = javautil_media_rgbX888_to_png((unsigned char*)pData->raw.bufferData, (unsigned char*)pOutput->bufferData, width, height); if (outLength <= 0) { javacall_amms_release_frame(pOutput); return JAVACALL_FAIL; } else pOutput->bufferLength = outLength; *ppOutput = pOutput; return JAVACALL_OK; }