void SDLScreen::TexRect(int x, int y, Image* tex, bool repeat) { ng::Rect s = tex->GetImageCropRegion(); if(s.w == 0 || s.h == 0 || !tex->GetImage() ) return; CacheImage(tex); // std::cout << "rendering tex2\n"; TexRect(x, y, s.w, s.h, tex, repeat, s.w, s.h); }
void CMyDlg::OnPaint() { CPaintDC dc(this); CRect rcClient; GetClientRect(&rcClient); Graphics graphics(dc); if (version&&bIsAero) graphics.Clear(Color.Black); else graphics.Clear(Color.White); Bitmap CacheImage(rcClient.Width(),rcClient.Height()); Graphics buffer(&CacheImage); buffer.SetSmoothingMode(SmoothingModeAntiAlias); buffer.SetInterpolationMode(InterpolationModeHighQualityBicubic); Image *logo; Image *button; ImageFromIDResource(2,"png",logo); ImageFromIDResource(1,"png",button); buffer.DrawImage(logo, -5,20); buffer.DrawImage(button, 165,122); buffer.DrawImage(button, 350,122); FontFamily fontFamily(version?L"微软雅黑":L"宋体"); StringFormat strformat; wchar_t pszbuf[512]; wsprintfW(pszbuf,L"本程序适用于 迅雷5.9 系列\n如果本软件有错,我概不负责,但我会尽力解决。\n只有极少数时候需要您指定安装目录(比如非官方版)。\n如果会员补丁失效,重新破解即可。\n\n\n请选择: 一键增强 %s取消增强\n\n2010年4月7日更新 www.shuax.com",version?L" ":L" "); GraphicsPath path; path.AddString(pszbuf, wcslen(pszbuf), &fontFamily, FontStyleRegular, version?15:16, Gdiplus::Point(version?90:80,version?9:20), &strformat ); Pen pen(Color(18, 255, 255, 255), 3.0); //pen.SetLineJoin(LineJoinRound); buffer.DrawPath(&pen, &path); SolidBrush brush(Color(0,0,0)); buffer.FillPath(&brush, &path); graphics.DrawImage(&CacheImage, 0, 0); graphics.ReleaseHDC(dc); }
MythImage *MythUIHelper::LoadCacheImage(QString srcfile, QString label, MythPainter *painter, ImageCacheMode cacheMode) { LOG(VB_GUI | VB_FILE, LOG_INFO, LOC + QString("LoadCacheImage(%1,%2)").arg(srcfile).arg(label)); if (srcfile.isEmpty() || label.isEmpty()) return NULL; if (!(kCacheForceStat & cacheMode)) { // Some screens include certain images dozens or even hundreds of // times. Even if the image is in the cache, there is still a // stat system call on the original file to see if it has changed. // This code relaxes the original-file check so that the check // isn't repeated if it was already done within kImageCacheTimeout // seconds. // This only applies to the MEMORY cache const uint kImageCacheTimeout = 60; uint now = MythDate::current().toTime_t(); QMutexLocker locker(d->m_cacheLock); if (d->imageCache.contains(label) && d->CacheTrack[label] + kImageCacheTimeout > now) { d->imageCache[label]->IncrRef(); return d->imageCache[label]; } } MythImage *ret = NULL; // Check Memory Cache ret = GetImageFromCache(label); // If the image is in the memory or we are not ignoring the disk cache // then proceed to check whether the source file is newer than our cached // copy if (ret || !(cacheMode & kCacheIgnoreDisk)) { // Create url to image in disk cache QString cachefilepath = GetThemeCacheDir() + '/' + label; QFileInfo cacheFileInfo(cachefilepath); // If the file isn't in the disk cache, then we don't want to bother // checking the last modified times of the original if (!cacheFileInfo.exists()) return NULL; // Now compare the time on the source versus our cached copy QDateTime srcLastModified; // For internet images this involves querying the headers of the remote // image. This is slow even without redownloading the whole image if ((srcfile.startsWith("http://")) || (srcfile.startsWith("https://")) || (srcfile.startsWith("ftp://"))) { // If the image is in the memory cache then skip the last modified // check, since memory cached images are loaded in the foreground // this can cause an intolerable delay. The images won't stay in // the cache forever and so eventually they will be checked. if (ret) srcLastModified = cacheFileInfo.lastModified(); else { srcLastModified = GetMythDownloadManager()->GetLastModified(srcfile); } } else if (srcfile.startsWith("myth://")) srcLastModified = RemoteFile::LastModified(srcfile); else { if (!FindThemeFile(srcfile)) return NULL; QFileInfo original(srcfile); if (original.exists()) srcLastModified = original.lastModified(); } // Now compare the timestamps, if the cached image is newer than the // source image we can use it, otherwise we want to remove it from the // cache if (cacheFileInfo.lastModified() >= srcLastModified) { // If we haven't already loaded the image from the memory cache // and we're not ignoring the disk cache, then it's time to load // it from there instead if (!ret && (cacheMode == kCacheNormal)) { if (painter) ret = painter->GetFormatImage(); // Load file from disk cache to memory cache if (ret->Load(cachefilepath)) { // Add to ram cache, and skip saving to disk since that is // where we found this in the first place. CacheImage(label, ret, true); } else { LOG(VB_GUI | VB_FILE, LOG_WARNING, LOC + QString("LoadCacheImage: Could not load :%1") .arg(cachefilepath)); ret->SetIsInCache(false); ret->DecrRef(); ret = NULL; } } } else { ret = NULL; // If file has changed on disk, then remove it from the memory // and disk cache RemoveFromCacheByURL(label); } } return ret; }
//void TexRect(int x, int y, int w, int h, GLuint texture) { void SDLScreen::TexRect(int x, int y, int w, int h, Image* texture, bool repeat, int texWidth, int texHeight) { // Size s = texture->GetImageSize(); // if(s.w == 0 || s.h == 0 || !texture->GetImage() ) return; CacheImage(texture); // std::cout << "rendering tex\n"; glUseProgram(shader2); glBindVertexArray(vao); Size s = texture->GetImageSize(); ng::Rect crop = texture->GetImageCropRegion(); float crop_x1 = ((float)crop.x / (float)s.w); float crop_y1 = ((float)crop.y / (float)s.h); float crop_x2 = ((float)crop.w / (float)s.w) + crop_x1; float crop_y2 = ((float)crop.h / (float)s.h) + crop_y1; float x1 = ((float)(x) / sizeX) * 2.0 - 1.0; float y1 = -(((float)(y) / sizeY) * 2.0 - 1.0); float x2 = ((float)(x+w) / sizeX) * 2.0 - 1.0; float y2 = -(((float)(y+h) / sizeY) * 2.0 - 1.0); GLfloat positions[] = { x1, y1, x1, y2, x2, y2, x2, y1, }; crop_x2 = repeat ? (float)w/texWidth : crop_x2; crop_y2 = repeat ? (float)h/texHeight : crop_y2; GLfloat texCoords[] = { crop_x1, crop_y1, crop_x1, crop_y2, crop_x2, crop_y2, crop_x2, crop_y1, }; GLuint indices[] = { 0, 1, 2, 2, 3, 0, }; if(rotation != 0.0f) { rotate(&positions[0]); rotate(&positions[2]); rotate(&positions[4]); rotate(&positions[6]); } glBindBuffer(GL_ARRAY_BUFFER, vbo_position); glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); glBindBuffer(GL_ARRAY_BUFFER, vbo_color); //rename vbo_position to vbo1 and vbo2 or create vbo_texcoord, cuz vbo_color is confusing here glBufferData(GL_ARRAY_BUFFER, sizeof(texCoords), texCoords, GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture->GetTextureId()); glUniform1i(glGetUniformLocation(shader2, "textureUniform"), 0); glUniform1f(glGetUniformLocation(shader2, "max_alpha"), max_alpha); glUniform1f(glGetUniformLocation(shader2, "custom_color_interp"), custom_color_interp); glUniform4fv(glGetUniformLocation(shader2, "custom_color"), 1, custom_color); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); glDisable(GL_BLEND); glBindVertexArray(0); glUseProgram(0); }
MythImage *MythUIHelper::LoadCacheImage(QString srcfile, QString label, MythPainter *painter, ImageCacheMode cacheMode) { LOG(VB_GUI | VB_FILE, LOG_INFO, LOC + QString("LoadCacheImage(%1,%2)").arg(srcfile).arg(label)); if (srcfile.isEmpty() || label.isEmpty()) return NULL; if (!(kCacheForceStat & cacheMode)) { // Some screens include certain images dozens or even hundreds of // times. Even if the image is in the cache, there is still a // stat system call on the original file to see if it has changed. // This code relaxes the original-file check so that the check // isn't repeated if it was already done within kImageCacheTimeout // seconds. const uint kImageCacheTimeout = 5; uint now = MythDate::current().toTime_t(); QMutexLocker locker(d->m_cacheLock); if (d->imageCache.contains(label) && d->CacheTrack[label] + kImageCacheTimeout > now) { d->imageCache[label]->IncrRef(); return d->imageCache[label]; } } QString cachefilepath = GetThemeCacheDir() + '/' + label; QFileInfo fi(cachefilepath); MythImage *ret = NULL; if (!!(cacheMode & kCacheIgnoreDisk) || fi.exists()) { // Now compare the time on the source versus our cached copy if (!(cacheMode & kCacheIgnoreDisk)) FindThemeFile(srcfile); QDateTime srcLastModified; QFileInfo original(srcfile); if ((srcfile.startsWith("http://")) || (srcfile.startsWith("https://")) || (srcfile.startsWith("ftp://"))) { srcLastModified = GetMythDownloadManager()->GetLastModified(srcfile); } else if (srcfile.startsWith("myth://")) srcLastModified = RemoteFile::LastModified(srcfile); else if (original.exists()) srcLastModified = original.lastModified(); if (!!(cacheMode & kCacheIgnoreDisk) || (fi.lastModified() > srcLastModified)) { // Check Memory Cache ret = GetImageFromCache(label); if (!ret && (cacheMode == kCacheNormal) && painter) { // Load file from disk cache to memory cache ret = painter->GetFormatImage(); if (!ret->Load(cachefilepath, false)) { LOG(VB_GUI | VB_FILE, LOG_WARNING, LOC + QString("LoadCacheImage: Could not load :%1") .arg(cachefilepath)); ret->SetIsInCache(false); ret->DecrRef(); ret = NULL; } else { // Add to ram cache, and skip saving to disk since that is // where we found this in the first place. CacheImage(label, ret, true); } } } else { // If file has changed on disk, then remove it from the memory // and disk cache RemoveFromCacheByURL(label); } } return ret; }