Пример #1
0
        /// <summary>
        /// The last parameter, sec2X is used to porperly position the wave within the given x1..x1+clipw space if it is too short
        /// </summary>
        public void DrawWaveform(
            Graphics g,
            IVidkaOpContext context,
            ImageCacheManager imgCache,
            string mediaFilename,
            double audioLengthSec,
            double videoLengthSec,
            double audioOffsetSec,
            int x1, int y1, int clipw, int cliph,
            double secStart, double secEnd,
            bool isMuted, bool hasCustomAudio)
        {
            double audioT1 = (audioOffsetSec + secStart) / audioLengthSec;
            double audioT2 = (audioOffsetSec + secEnd) / audioLengthSec;

            if (audioT1 > 1)
            {
                return;
            }
            if (audioT2 < 0)
            {
                return;
            }

            string waveFile = context.FileMapping.AddGetWaveFilenameJpg(mediaFilename);

            if (File.Exists(waveFile))
            {
                Bitmap bmpWave = imgCache.getWaveImg(waveFile);//Image ot

                double audioT1L = 0, audioT2R = 0;
                if (audioT1 < 0)
                {
                    audioT1L = -audioT1;
                    audioT1  = 0;
                }
                if (audioT2 > 1)
                {
                    audioT2R = audioT2 - 1;
                    audioT2  = 1;
                }
                var totalT = audioT1L + (audioT2 - audioT1) + audioT2R;
                var xAud1  = audioT1L * clipw / totalT;
                var xAud2  = (audioT1L + (audioT2 - audioT1)) * clipw / totalT;
                var xSrc1  = (int)(bmpWave.Width * audioT1);
                var xSrc2  = (int)(bmpWave.Width * audioT2);
                srcRect.X       = xSrc1;
                srcRect.Width   = xSrc2 - xSrc1;
                srcRect.Y       = 0;
                srcRect.Height  = bmpWave.Height; //TODO: use constant from Ops
                destRect.X      = x1 + (int)xAud1;
                destRect.Y      = y1;
                destRect.Width  = (int)(xAud2 - xAud1);
                destRect.Height = cliph;
                g.DrawImage(bmpWave, destRect: destRect, srcRect: srcRect, srcUnit: GraphicsUnit.Pixel);
            }
            if (isMuted)
            {
                g.FillRectangle(PPP.brushHazyMute, destRect);
            }
            if (hasCustomAudio)
            {
                g.FillRectangle(PPP.brushHazyCustomAudio, destRect);
            }
        }
Пример #2
0
        /// <summary>
        /// The last parameter, sec2X is used to porperly position the wave within the given x1..x1+clipw space if it is too short
        /// </summary>
        public void DrawWaveform(
            Graphics g,
            IVidkaOpContext context,
            ImageCacheManager imgCache,
            string mediaFilename,
            double audioLengthSec,
            double videoLengthSec,
            double audioOffsetSec,
            int x1, int y1, int clipw, int cliph,
            double secStart, double secEnd,
            bool isMuted, bool hasCustomAudio)
        {
            double audioT1 = (audioOffsetSec + secStart) / audioLengthSec;
            double audioT2 = (audioOffsetSec + secEnd) / audioLengthSec;
            if (audioT1 > 1)
                return;
            if (audioT2 < 0)
                return;

            string waveFile = context.FileMapping.AddGetWaveFilenameJpg(mediaFilename);
            if (File.Exists(waveFile))
            {
                Bitmap bmpWave = imgCache.getWaveImg(waveFile);//Image ot

                double audioT1L = 0, audioT2R = 0;
                if (audioT1 < 0)
                {
                    audioT1L = -audioT1;
                    audioT1 = 0;
                }
                if (audioT2 > 1)
                {
                    audioT2R = audioT2 - 1;
                    audioT2 = 1;
                }
                var totalT = audioT1L + (audioT2 - audioT1) + audioT2R;
                var xAud1 = audioT1L * clipw / totalT;
                var xAud2 = (audioT1L + (audioT2 - audioT1)) * clipw / totalT;
                var xSrc1 = (int)(bmpWave.Width * audioT1);
                var xSrc2 = (int)(bmpWave.Width * audioT2);
                srcRect.X = xSrc1;
                srcRect.Width = xSrc2 - xSrc1;
                srcRect.Y = 0;
                srcRect.Height = bmpWave.Height; //TODO: use constant from Ops
                destRect.X = x1 + (int)xAud1;
                destRect.Y = y1;
                destRect.Width = (int)(xAud2 - xAud1);
                destRect.Height = cliph;
                g.DrawImage(bmpWave, destRect: destRect, srcRect: srcRect, srcUnit: GraphicsUnit.Pixel);
            }
            if (isMuted)
                g.FillRectangle(PPP.brushHazyMute, destRect);
            if (hasCustomAudio)
                g.FillRectangle(PPP.brushHazyCustomAudio, destRect);
        }