File indexing completed on 2025-01-19 04:22:52
0001 /* 0002 SPDX-FileCopyrightText: 2010 Dirk Vanden Boer <dirk.vdb@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "filmstripfilter.h" 0008 #include "filmstrip.h" 0009 0010 namespace ffmpegthumbnailer 0011 { 0012 0013 //static const int FILMHOLE_WIDTH = 12; 0014 //static const int FILMHOLE_HEIGHT = 10; 0015 0016 static const quint8* determineFilmStrip(quint32 videoWidth, quint32& filmStripWidth, quint32& filmStripHeight) 0017 { 0018 if (videoWidth <= SMALLEST_FILM_STRIP_WIDTH * 2) 0019 { 0020 return nullptr; 0021 } 0022 0023 if (videoWidth <= 96) 0024 { 0025 filmStripWidth = filmStripHeight = 4; 0026 return filmStrip4; 0027 } 0028 0029 if (videoWidth <= 192) 0030 { 0031 filmStripWidth = filmStripHeight = 8; 0032 return filmStrip8; 0033 } 0034 0035 if (videoWidth <= 384) 0036 { 0037 filmStripWidth = filmStripHeight = 16; 0038 return filmStrip16; 0039 } 0040 0041 if (videoWidth <= 768) 0042 { 0043 filmStripWidth = filmStripHeight = 32; 0044 return filmStrip32; 0045 } 0046 0047 filmStripWidth = filmStripHeight = 64; 0048 return filmStrip64; 0049 } 0050 0051 0052 0053 void FilmStripFilter::process(VideoFrame& videoFrame) 0054 { 0055 quint32 filmStripWidth; 0056 quint32 filmStripHeight; 0057 const quint8* filmHole = determineFilmStrip(videoFrame.width, filmStripWidth, filmStripHeight); 0058 0059 if (!filmHole) 0060 { 0061 return; 0062 } 0063 0064 int frameIndex = 0; 0065 int filmHoleIndex = 0; 0066 int offset = (videoFrame.width * 3) - 3; 0067 0068 for (quint32 i = 0; i < videoFrame.height; ++i) 0069 { 0070 for (quint32 j = 0; j < filmStripWidth * 3; j+=3) 0071 { 0072 int currentFilmHoleIndex = filmHoleIndex + j; 0073 0074 videoFrame.frameData[frameIndex + j] = filmHole[currentFilmHoleIndex]; 0075 videoFrame.frameData[frameIndex + j + 1] = filmHole[currentFilmHoleIndex + 1]; 0076 videoFrame.frameData[frameIndex + j + 2] = filmHole[currentFilmHoleIndex + 2]; 0077 0078 videoFrame.frameData[frameIndex + offset - j] = filmHole[currentFilmHoleIndex]; 0079 videoFrame.frameData[frameIndex + offset - j + 1] = filmHole[currentFilmHoleIndex + 1]; 0080 videoFrame.frameData[frameIndex + offset - j + 2] = filmHole[currentFilmHoleIndex + 2]; 0081 } 0082 frameIndex += videoFrame.lineSize; 0083 filmHoleIndex = (i % filmStripHeight) * filmStripWidth * 3; 0084 } 0085 } 0086 0087 }