| 2928 | } |
| 2929 | |
| 2930 | void |
| 2931 | ViewerGL::fitImageToFormat() |
| 2932 | { |
| 2933 | // always running in the main thread |
| 2934 | assert( qApp && qApp->thread() == QThread::currentThread() ); |
| 2935 | // size in Canonical = Zoom coordinates ! |
| 2936 | double w, h; |
| 2937 | const RectD& tex0Format = _imp->displayTextures[0].format; |
| 2938 | if (tex0Format.isNull()) { |
| 2939 | return; |
| 2940 | } |
| 2941 | w = tex0Format.width(); |
| 2942 | h = tex0Format.height(); |
| 2943 | |
| 2944 | if (w <= 0 || h <= 0) { |
| 2945 | return; |
| 2946 | } |
| 2947 | |
| 2948 | double old_zoomFactor; |
| 2949 | double zoomFactor; |
| 2950 | unsigned int oldMipMapLevel, newMipMapLevel; |
| 2951 | { |
| 2952 | QMutexLocker(&_imp->zoomCtxMutex); |
| 2953 | old_zoomFactor = _imp->zoomCtx.factor(); |
| 2954 | //oldMipMapLevel = std::log( old_zoomFactor >= 1 ? 1 : |
| 2955 | // std::pow( 2, -std::ceil(std::log(old_zoomFactor) / M_LN2) ) ) / M_LN2; |
| 2956 | oldMipMapLevel = old_zoomFactor >= 1 ? 0 : -std::ceil(std::log(old_zoomFactor) / M_LN2); |
| 2957 | |
| 2958 | // set the PAR first |
| 2959 | //_imp->zoomCtx.setZoom(0., 0., 1., 1.); |
| 2960 | // leave 4% of margin around |
| 2961 | _imp->zoomCtx.fit(-0.02 * w, 1.02 * w, -0.02 * h, 1.02 * h); |
| 2962 | zoomFactor = _imp->zoomCtx.factor(); |
| 2963 | } |
| 2964 | _imp->zoomOrPannedSinceLastFit = false; |
| 2965 | //newMipMapLevel = std::log( zoomFactor >= 1 ? 1 : |
| 2966 | // std::pow( 2, -std::ceil(std::log(zoomFactor) / M_LN2) ) ) / M_LN2; |
| 2967 | newMipMapLevel = zoomFactor >= 1 ? 0 : -std::ceil(std::log(zoomFactor) / M_LN2); |
| 2968 | |
| 2969 | _imp->oldClick = QPoint(); // reset mouse posn |
| 2970 | |
| 2971 | if (old_zoomFactor != zoomFactor) { |
| 2972 | int zoomFactorInt = zoomFactor * 100; |
| 2973 | if (zoomFactorInt == 0) { |
| 2974 | zoomFactorInt = 1; |
| 2975 | } |
| 2976 | Q_EMIT zoomChanged(zoomFactorInt); |
| 2977 | } |
| 2978 | |
| 2979 | if ( _imp->viewerTab->isViewersSynchroEnabled() ) { |
| 2980 | _imp->viewerTab->synchronizeOtherViewersProjection(); |
| 2981 | } |
| 2982 | |
| 2983 | if (newMipMapLevel != oldMipMapLevel) { |
| 2984 | ///Clear green cached line so the user doesn't expect to see things in the cache |
| 2985 | ///since we're changing the zoom factor |
| 2986 | _imp->viewerTab->clearTimelineCacheLine(); |
| 2987 | } |
no test coverage detected