HRESULT CSimpleDataObjectImpl::AddData(UINT cfFormat, HGLOBAL hData) { // Remove existing entry CFormat* pFormat=FindFormat(cfFormat, TYMED_HGLOBAL); if (pFormat) { m_Formats.Remove(pFormat); } // Create a new format entry pFormat=new CFormat(cfFormat, hData); // Add it m_Formats.Add(pFormat); // Add emulated modes... if (cfFormat==CF_TEXT && !FindFormat(CF_UNICODETEXT, TYMED_HGLOBAL) && hData) { AddData(CF_UNICODETEXT, TYMED_HGLOBAL); } if (cfFormat==CF_UNICODETEXT && !FindFormat(CF_TEXT, TYMED_HGLOBAL) && hData) { AddData(CF_TEXT, TYMED_HGLOBAL); } return S_OK; }
int SevenZipPlugin::QueryArchive( const unsigned char* pBuffer, DWORD dwBufferSize, const GUID& uid, const TCHAR* lpFileName, Array<ArchiveQueryResult*>& result ) { for (int i = 0; i < sizeof(signs)/sizeof(signs[0]); i++) { if ( *signs[i].puid == uid ) { FormatPosition Position; if ( FindFormat(pBuffer, dwBufferSize, &signs[i], &Position) || FindSplitFormat(lpFileName, &Position) ) { ArchiveQueryResult* pResult = new ArchiveQueryResult; pResult->uidFormat = uid; pResult->uidPlugin = m_uid; result.add(pResult); } break; } } return 1; }
void Extension::AddSubFormat(const Char *Name) { Formats_t::iterator it = FindFormat(Name); if(!Assert(it != Formats.end(), String(_T("No such format: "))+Name)) return; Format::ItemGroup *g = (*it)->Clone(); g->name = Name; Formats.back()->items.push_back(g); }
void Extension::SaveFormat(const Char *Name, const Char *File) { Formats_t::iterator it = FindFormat(Name); if(!Assert(it != Formats.end(), String(_T("No such format: "))+Name)) return; std::basic_ofstream<Char> f (File, std::ios::out|std::ios::binary|std::ios::trunc); if(!Assert(f.is_open(), String(_T("Failed to open: "))+File)) return; (*it)->Serialize((f << ID << Char(FileVersion), f)); }
DWORD TooltipFindFormat(void) { DWORD dwInfoTooltip = 0; char tip[LEN_TOOLTIP]; // Tooltipのテキストをレジストリから読み込む GetMyRegStrEx("Tooltip", "Tooltip", tip, sizeof(tip), "", gConfigNo); //ファイル指定であった場合 if(tip[0] == 'f' && tip[1] == 'i' && tip[2] == 'l' && tip[3] == 'e' && tip[4] == ':') { //Pathを切り出す memmove( tip, tip + 5, (size_t)((strchr(tip,'\0')-1)-tip)); if(!GetTooltipText(tip)){ strcpy(tip, "ファイル取得失敗"); } } dwInfoTooltip |= FindFormat(tip); // Tooltipのテキストをレジストリから読み込む GetMyRegStrEx("Tooltip", "Tooltip2", tip, sizeof(tip), "", gConfigNo); //ファイル指定であった場合 if(tip[0] == 'f' && tip[1] == 'i' && tip[2] == 'l' && tip[3] == 'e' && tip[4] == ':') { //Pathを切り出す memmove( tip, tip + 5, (size_t)((strchr(tip,'\0')-1)-tip)); if(!GetTooltipText(tip)){ strcpy(tip, "ファイル取得失敗"); } } dwInfoTooltip |= FindFormat(tip); // Tooltipのテキストをレジストリから読み込む GetMyRegStrEx("Tooltip", "Tooltip3", tip, sizeof(tip), "", gConfigNo); //ファイル指定であった場合 if(tip[0] == 'f' && tip[1] == 'i' && tip[2] == 'l' && tip[3] == 'e' && tip[4] == ':') { //Pathを切り出す memmove( tip, tip + 5, (size_t)((strchr(tip,'\0')-1)-tip)); if(!GetTooltipText(tip)){ strcpy(tip, "ファイル取得失敗"); } } dwInfoTooltip |= FindFormat(tip); GetMyRegStrEx("", "TipTitle", tip, sizeof(tip), "", gConfigNo); dwInfoTooltip |= FindFormat(tip); return dwInfoTooltip; }
int main(int argc, char* argv[]) { CxImage image; if (argc<3) { fprintf(stderr, image.GetVersion()); fprintf(stderr, "\nConsole demo\n"); fprintf(stderr, "usage: %s input-file output-file\n", argv[0]); return 1; } CString filein(argv[1]); CString extin(FindExtension(filein)); extin.MakeLower(); int typein = FindFormat(extin); if (typein == CXIMAGE_FORMAT_UNKNOWN) { fprintf(stderr, "unknown extension for %s\n", argv[1]); return 1; } CString fileout(argv[2]); CString extout(FindExtension(fileout)); extout.MakeLower(); int typeout = FindFormat(extout); if (typeout == CXIMAGE_FORMAT_UNKNOWN) { fprintf(stderr, "unknown extension for %s\n", argv[2]); return 1; } if (!image.Load(argv[1],typein)){ fprintf(stderr, "%s\n", image.GetLastError()); fprintf(stderr, "error loading %s\n", argv[1]); return 1; } if (!image.Save(argv[2],typeout)){ fprintf(stderr, "%s\n", image.GetLastError()); fprintf(stderr, "error saving %s\n", argv[2]); return 1; } printf("Done!\n"); return 0; }
void Extension::CreateFormat(const Char *Name) { if(FindFormat(Name) != Formats.end()) { Runtime.GenerateEvent(Trigger::Error); return; } Formats.push_back(new Format::ItemGroup(Name)); }
void Extension::TraverseFile(const Char *File, const Char *Name) // // // // // // // { std::basic_ifstream<Char> f (File, std::ios::in|std::ios::binary); if(!Assert(f.is_open(), String(_T("Failed to open: "))+File)) return; Formats_t::iterator it = FindFormat(Name); if(!Assert(it != Formats.end(), String(_T("No such format: "))+Name)) return; Mode = Deserializing; OfFormat.clear(); (*it)->Traverse(f, *this); Mode = Neither; }
// Implementation of QueryGetData STDMETHODIMP CSimpleDataObjectImpl::QueryGetData(FORMATETC* pformatetc) { // Check format etc if (pformatetc->dwAspect!=DVASPECT_CONTENT) return DV_E_DVASPECT; // Supported format? if (FindFormat(pformatetc->cfFormat, (TYMED)pformatetc->tymed)) return S_OK; // Unsupported return DV_E_FORMATETC; }
int FindFormats(const unsigned char* pBuffer, DWORD dwBufferSize, const TCHAR *lpFileName, Array<FormatPosition*> &formats) { for (size_t i = 0; i < sizeof(signs)/sizeof(signs[0]); i++) { FormatPosition* pPosition = new FormatPosition; if ( FindFormat(pBuffer, dwBufferSize, &signs[i], pPosition) || FindSplitFormat(lpFileName, pPosition) ) { formats.add(pPosition); } } return formats.count(); }
HRESULT CSimpleDataObjectImpl::AddData(UINT cfFormat, IStream* pStream) { // Remove existing entry CFormat* pFormat=FindFormat(cfFormat, TYMED_ISTREAM); if (pFormat) { m_Formats.Remove(pFormat); } // Create a new format entry pFormat=new CFormat(cfFormat, pStream); // Add it m_Formats.Add(pFormat); return S_OK; }
void Extension::LoadFormat(const Char *File, const Char *Name) { Formats_t::iterator it = FindFormat(Name); if(!Assert(it == Formats.end(), String(_T("Format already exists: "))+Name)) return; std::basic_ifstream<Char> f (File, std::ios::in|std::ios::binary); if(!Assert(f.is_open(), String(_T("Failed to open: "))+File)) return; Char id[7] = {0}; f.read(id, 6); if(!Assert(id == ID, String(_T("Not a valid format file: "))+File)) return; unsigned FileVer (unsigned(f.get())); if(!Assert(FileVer <= FileVersion, String(_T("Newer or unkown version: ")))+File) return; String name; for(int c; c = f.get(); name += char(c)); if(!Assert(f.get() == 0, String(_T("Invalid format file: "))+File)) return; try { Formats.push_back(new Format::ItemGroup(f, name)); } catch(Format::ItemGroup *) { GenerateError(_T("Unkown format element")); } }
// Implementation of GetData STDMETHODIMP CSimpleDataObjectImpl::GetData(FORMATETC* pformatetc, STGMEDIUM* pmedium) { // Check format etc if (pformatetc->dwAspect!=DVASPECT_CONTENT) return DV_E_DVASPECT; #ifdef _DEBUG TCHAR szFormat[MAX_PATH]; if (!GetClipboardFormatName(pformatetc->cfFormat, szFormat, MAX_PATH)) { wsprintf(szFormat, _T("%i"), pformatetc->cfFormat); } ATLTRACE(_T("CSimpleDataObjectImpl::GetData - %s %i\n"), szFormat, pformatetc->tymed); #endif // Get the format... CFormat* pFormat=FindFormat(pformatetc->cfFormat, (TYMED)pformatetc->tymed); if (!pFormat) return DATA_E_FORMATETC; // Init STGMEDIUM memset(pmedium, 0, sizeof(*pmedium)); if (pformatetc->tymed & TYMED_HGLOBAL) { // Delayed data? if (!pFormat->m_hData) { if (SUCCEEDED(OnGetData(pformatetc->cfFormat, pformatetc->lindex, &pmedium->hGlobal))) { pmedium->tymed=TYMED_HGLOBAL; return S_OK; } } else if (pformatetc->lindex==-1) { // Allocate memory DWORD_PTR dwSize=GlobalSize(pFormat->m_hData); pmedium->hGlobal=GlobalAlloc(GHND, dwSize); if (!pmedium->hGlobal) return E_OUTOFMEMORY; // Copy it memcpy(GlobalLock(pmedium->hGlobal), GlobalLock(pFormat->m_hData), dwSize); // Unlock GlobalUnlock(pmedium->hGlobal); GlobalUnlock(pFormat->m_hData); pmedium->tymed=TYMED_HGLOBAL; return S_OK; } } if (pformatetc->tymed & TYMED_ISTREAM) { // Delayed data? if (!pFormat->m_spStream) { if (SUCCEEDED(OnGetData(pformatetc->cfFormat, pformatetc->lindex, &pmedium->pstm))) { pmedium->tymed=TYMED_ISTREAM; return S_OK; } } else if (pformatetc->lindex==-1) { pFormat->m_spStream.CopyTo(&pmedium->pstm); pmedium->tymed=TYMED_ISTREAM; return S_OK; } } // Unknown format return DATA_E_FORMATETC; }
HRESULT CSimpleDataObjectImpl::OnGetData(UINT cfFormat, LONG lIndex, HGLOBAL* phData) { if (lIndex!=-1) return DV_E_LINDEX; if (cfFormat==CF_UNICODETEXT) { // Find existing entry CFormat* pFormat=FindFormat(CF_TEXT, TYMED_HGLOBAL); if (!pFormat) return DATA_E_FORMATETC; ASSERT(pFormat->m_hData); // Get ANSI text LPCSTR psz=(LPCSTR)GlobalLock(pFormat->m_hData); int iLenA=lstrlenA(psz)+1; // Work out unicode length int iLenW=MultiByteToWideChar(CP_ACP, 0, psz, iLenA, NULL, 0); // Allocate memory *phData=GlobalAlloc(GHND, iLenW * sizeof(OLECHAR)); // Convert it MultiByteToWideChar(CP_ACP, 0, psz, iLenA, (LPOLESTR)GlobalLock(phData[0]), iLenW); // Unlock and finished GlobalUnlock(phData[0]); return S_OK; } if (cfFormat==CF_TEXT) { // Find existing entry CFormat* pFormat=FindFormat(CF_UNICODETEXT, TYMED_HGLOBAL); if (!pFormat) return DATA_E_FORMATETC; ASSERT(pFormat->m_hData); // Get ANSI text LPCOLESTR psz=(LPCOLESTR)GlobalLock(pFormat->m_hData); int iLenW=lstrlenW(psz)+1; // Work out unicode length int iLenA=WideCharToMultiByte(CP_ACP, 0, psz, iLenW, NULL, 0, NULL, NULL); // Allocate memory *phData=GlobalAlloc(GHND, iLenA * sizeof(OLECHAR)); // Convert it WideCharToMultiByte(CP_ACP, 0, psz, iLenW, (LPSTR)GlobalLock(phData[0]), iLenA, NULL, NULL); // Unlock and finished GlobalUnlock(phData[0]); return S_OK; } return DATA_E_FORMATETC; }
static int Create( vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt, const es_format_t *fmt, picture_sys_t *p_sys ) { if( pix_fmt != AV_PIX_FMT_VAAPI_VLD ) return VLC_EGENERIC; (void) fmt; (void) p_sys; #ifdef VLC_VA_BACKEND_XLIB if( !vlc_xlib_init( VLC_OBJECT(va) ) ) { msg_Warn( va, "Ignoring VA-X11 API" ); return VLC_EGENERIC; } #endif VAProfile i_profile, *p_profiles_list; bool b_supported_profile = false; int i_profiles_nb = 0; unsigned count = 3; /* */ switch( ctx->codec_id ) { case AV_CODEC_ID_MPEG1VIDEO: case AV_CODEC_ID_MPEG2VIDEO: i_profile = VAProfileMPEG2Main; count = 4; break; case AV_CODEC_ID_MPEG4: i_profile = VAProfileMPEG4AdvancedSimple; break; case AV_CODEC_ID_WMV3: i_profile = VAProfileVC1Main; break; case AV_CODEC_ID_VC1: i_profile = VAProfileVC1Advanced; break; case AV_CODEC_ID_H264: i_profile = VAProfileH264High; count = 18; break;; default: return VLC_EGENERIC; } count += ctx->thread_count; vlc_va_sys_t *sys; void *mem; assert(popcount(sizeof (sys->surfaces)) == 1); if (unlikely(posix_memalign(&mem, sizeof (sys->surfaces), sizeof (*sys)))) return VLC_ENOMEM; sys = mem; memset(sys, 0, sizeof (*sys)); /* */ sys->hw_ctx.display = NULL; sys->hw_ctx.config_id = VA_INVALID_ID; sys->hw_ctx.context_id = VA_INVALID_ID; sys->width = ctx->coded_width; sys->height = ctx->coded_height; sys->count = count; sys->available = (1 << sys->count) - 1; assert(count < sizeof (sys->available) * CHAR_BIT); assert(count * sizeof (sys->surfaces[0]) <= sizeof (sys->surfaces)); /* Create a VA display */ #ifdef VLC_VA_BACKEND_XLIB sys->p_display_x11 = XOpenDisplay(NULL); if( !sys->p_display_x11 ) { msg_Err( va, "Could not connect to X server" ); goto error; } sys->hw_ctx.display = vaGetDisplay(sys->p_display_x11); #endif #ifdef VLC_VA_BACKEND_DRM sys->drm_fd = vlc_open("/dev/dri/card0", O_RDWR); if( sys->drm_fd == -1 ) { msg_Err( va, "Could not access rendering device: %m" ); goto error; } sys->hw_ctx.display = vaGetDisplayDRM(sys->drm_fd); #endif if (sys->hw_ctx.display == NULL) { msg_Err( va, "Could not get a VAAPI device" ); goto error; } int major, minor; if (vaInitialize(sys->hw_ctx.display, &major, &minor)) { msg_Err( va, "Failed to initialize the VAAPI device" ); goto error; } /* Check if the selected profile is supported */ i_profiles_nb = vaMaxNumProfiles(sys->hw_ctx.display); p_profiles_list = calloc( i_profiles_nb, sizeof( VAProfile ) ); if( !p_profiles_list ) goto error; if (vaQueryConfigProfiles(sys->hw_ctx.display, p_profiles_list, &i_profiles_nb) == VA_STATUS_SUCCESS) { for( int i = 0; i < i_profiles_nb; i++ ) { if ( p_profiles_list[i] == i_profile ) { b_supported_profile = true; break; } } } free( p_profiles_list ); if ( !b_supported_profile ) { msg_Dbg( va, "Codec and profile not supported by the hardware" ); goto error; } /* Create a VA configuration */ VAConfigAttrib attrib; memset( &attrib, 0, sizeof(attrib) ); attrib.type = VAConfigAttribRTFormat; if (vaGetConfigAttributes(sys->hw_ctx.display, i_profile, VAEntrypointVLD, &attrib, 1)) goto error; /* Not sure what to do if not, I don't have a way to test */ if( (attrib.value & VA_RT_FORMAT_YUV420) == 0 ) goto error; if (vaCreateConfig(sys->hw_ctx.display, i_profile, VAEntrypointVLD, &attrib, 1, &sys->hw_ctx.config_id)) { sys->hw_ctx.config_id = VA_INVALID_ID; goto error; } /* Create surfaces */ assert(ctx->coded_width > 0 && ctx->coded_height > 0); if (vaCreateSurfaces(sys->hw_ctx.display, VA_RT_FORMAT_YUV420, ctx->coded_width, ctx->coded_height, sys->surfaces, sys->count, NULL, 0)) { goto error; } /* Create a context */ if (vaCreateContext(sys->hw_ctx.display, sys->hw_ctx.config_id, ctx->coded_width, ctx->coded_height, VA_PROGRESSIVE, sys->surfaces, sys->count, &sys->hw_ctx.context_id)) { sys->hw_ctx.context_id = VA_INVALID_ID; vaDestroySurfaces(sys->hw_ctx.display, sys->surfaces, sys->count); goto error; } if (FindFormat(sys)) goto error; if (unlikely(CopyInitCache(&sys->image_cache, ctx->coded_width))) goto error; vlc_mutex_init(&sys->lock); msg_Dbg(va, "using %s image format 0x%08x", sys->do_derive ? "derive" : "get", sys->format.fourcc); ctx->hwaccel_context = &sys->hw_ctx; va->sys = sys; va->description = vaQueryVendorString(sys->hw_ctx.display); va->get = Get; va->release = Release; va->extract = Extract; return VLC_SUCCESS; error: if (sys->hw_ctx.context_id != VA_INVALID_ID) { vaDestroyContext(sys->hw_ctx.display, sys->hw_ctx.context_id); vaDestroySurfaces(sys->hw_ctx.display, sys->surfaces, sys->count); } if (sys->hw_ctx.config_id != VA_INVALID_ID) vaDestroyConfig(sys->hw_ctx.display, sys->hw_ctx.config_id); if (sys->hw_ctx.display != NULL) vaTerminate(sys->hw_ctx.display); #ifdef VLC_VA_BACKEND_XLIB if( sys->p_display_x11 != NULL ) XCloseDisplay( sys->p_display_x11 ); #endif #ifdef VLC_VA_BACKEND_DRM if( sys->drm_fd != -1 ) close( sys->drm_fd ); #endif free( sys ); return VLC_EGENERIC; }