2007-01-21 07:30:19 +01:00
|
|
|
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-01-21 07:30:19 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file video_frame.cpp
|
|
|
|
/// @brief Wrapper around a frame of video data
|
|
|
|
/// @ingroup video
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
#include "video_frame.h"
|
2007-04-03 04:31:51 +02:00
|
|
|
#include "utils.h"
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Reset
|
|
|
|
///
|
2007-03-24 03:07:06 +01:00
|
|
|
void AegiVideoFrame::Reset() {
|
2007-03-28 03:11:52 +02:00
|
|
|
// Note that this function DOES NOT unallocate memory.
|
|
|
|
// Use Clear() for that
|
|
|
|
|
|
|
|
// Zero variables
|
2007-01-21 07:30:19 +01:00
|
|
|
for (int i=0;i<4;i++) {
|
|
|
|
data[i] = NULL;
|
|
|
|
pitch[i] = 0;
|
|
|
|
}
|
2007-01-28 04:26:03 +01:00
|
|
|
memSize = 0;
|
2007-01-21 07:30:19 +01:00
|
|
|
w = 0;
|
|
|
|
h = 0;
|
2007-03-28 03:11:52 +02:00
|
|
|
|
|
|
|
// Set properties
|
2007-03-28 00:29:35 +02:00
|
|
|
format = FORMAT_NONE;
|
2007-01-21 07:30:19 +01:00
|
|
|
flipped = false;
|
|
|
|
cppAlloc = true;
|
|
|
|
invertChannels = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Constructor
|
|
|
|
///
|
2007-03-24 03:07:06 +01:00
|
|
|
AegiVideoFrame::AegiVideoFrame() {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Create default
|
|
|
|
/// @param width
|
|
|
|
/// @param height
|
|
|
|
/// @param fmt
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
AegiVideoFrame::AegiVideoFrame(int width,int height,VideoFrameFormat fmt) {
|
2007-03-28 03:11:52 +02:00
|
|
|
// Clear
|
2007-03-24 03:07:06 +01:00
|
|
|
Reset();
|
2007-03-28 03:11:52 +02:00
|
|
|
|
|
|
|
// Set format
|
2007-01-21 07:30:19 +01:00
|
|
|
format = fmt;
|
|
|
|
w = width;
|
|
|
|
h = height;
|
2007-03-24 03:07:06 +01:00
|
|
|
pitch[0] = w * GetBpp();
|
2007-03-28 03:11:52 +02:00
|
|
|
if (fmt == FORMAT_YV12) {
|
|
|
|
pitch[1] = w/2;
|
|
|
|
pitch[2] = w/2;
|
|
|
|
}
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2007-03-28 03:11:52 +02:00
|
|
|
// Allocate
|
2007-01-21 07:30:19 +01:00
|
|
|
Allocate();
|
2007-03-28 03:11:52 +02:00
|
|
|
|
|
|
|
// Clear data
|
|
|
|
int size = pitch[0]*height + (pitch[1]+pitch[2])*height/2;
|
|
|
|
memset(data[0],0,size);
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Allocate
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
void AegiVideoFrame::Allocate() {
|
2007-03-28 00:29:35 +02:00
|
|
|
// Check consistency
|
|
|
|
wxASSERT(pitch[0] > 0 && pitch[0] < 10000);
|
|
|
|
wxASSERT(w > 0 && w < 10000);
|
|
|
|
wxASSERT(h > 0 && h < 10000);
|
|
|
|
wxASSERT(format != FORMAT_NONE);
|
|
|
|
|
2007-01-28 04:26:03 +01:00
|
|
|
// Get size
|
|
|
|
int height = h;
|
2007-03-24 03:07:06 +01:00
|
|
|
unsigned int size;
|
2007-03-28 00:29:35 +02:00
|
|
|
if (format == FORMAT_YV12) {
|
|
|
|
wxASSERT(pitch[1] > 0 && pitch[1] < 10000);
|
|
|
|
wxASSERT(pitch[2] > 0 && pitch[2] < 10000);
|
|
|
|
size = pitch[0]*height + (pitch[1]+pitch[2])*height/2;
|
|
|
|
}
|
2007-03-24 03:07:06 +01:00
|
|
|
else size = pitch[0] * height;
|
2007-01-28 04:26:03 +01:00
|
|
|
|
|
|
|
// Reallocate, if necessary
|
|
|
|
if (memSize != size) {
|
2007-03-24 03:07:06 +01:00
|
|
|
if (data[0]) {
|
|
|
|
if (cppAlloc) delete[] data[0];
|
|
|
|
else free(data[0]);
|
|
|
|
}
|
2007-01-28 04:26:03 +01:00
|
|
|
data[0] = new unsigned char[size];
|
|
|
|
for (int i=1;i<4;i++) data[i] = NULL;
|
|
|
|
memSize = size;
|
|
|
|
|
|
|
|
// Planar
|
|
|
|
if (format == FORMAT_YV12) {
|
|
|
|
data[1] = data[0] + (pitch[0]*height);
|
2007-03-28 00:29:35 +02:00
|
|
|
data[2] = data[0] + (pitch[0]*height+pitch[1]*height/2);
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
2007-03-28 00:29:35 +02:00
|
|
|
// Flag as allocated by C++
|
|
|
|
cppAlloc = true;
|
|
|
|
}
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Clear
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
void AegiVideoFrame::Clear() {
|
2007-03-28 03:11:52 +02:00
|
|
|
// Free memory
|
2007-01-28 04:26:03 +01:00
|
|
|
if (cppAlloc) delete[] data[0];
|
|
|
|
else free(data[0]);
|
2007-03-28 03:11:52 +02:00
|
|
|
|
|
|
|
// Zero variables
|
2007-01-21 07:30:19 +01:00
|
|
|
for (int i=0;i<4;i++) {
|
2007-01-28 04:26:03 +01:00
|
|
|
data[i] = NULL;
|
2007-01-21 07:30:19 +01:00
|
|
|
pitch[i] = 0;
|
|
|
|
}
|
2007-01-28 04:26:03 +01:00
|
|
|
memSize = 0;
|
2007-01-21 07:30:19 +01:00
|
|
|
w = 0;
|
|
|
|
h = 0;
|
2007-03-28 03:11:52 +02:00
|
|
|
|
|
|
|
// Reset properties
|
|
|
|
format = FORMAT_NONE;
|
2007-01-21 07:30:19 +01:00
|
|
|
flipped = false;
|
|
|
|
cppAlloc = true;
|
|
|
|
invertChannels = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Create copy
|
|
|
|
/// @param source
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
void AegiVideoFrame::CopyFrom(const AegiVideoFrame &source) {
|
|
|
|
w = source.w;
|
|
|
|
h = source.h;
|
|
|
|
format = source.format;
|
|
|
|
for (int i=0;i<4;i++) pitch[i] = source.pitch[i];
|
|
|
|
Allocate();
|
2007-01-28 04:26:03 +01:00
|
|
|
memcpy(data[0],source.data[0],memSize);
|
2007-01-21 07:30:19 +01:00
|
|
|
flipped = source.flipped;
|
|
|
|
invertChannels = source.invertChannels;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief This function is only used on screenshots, so it doesn't have to be fast ------ Get wxImage
|
|
|
|
/// @return
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
wxImage AegiVideoFrame::GetImage() const {
|
2007-03-28 03:11:52 +02:00
|
|
|
// RGB
|
2007-01-21 07:30:19 +01:00
|
|
|
if (format == FORMAT_RGB32 || format == FORMAT_RGB24) {
|
|
|
|
// Create
|
|
|
|
unsigned char *buf = (unsigned char*)malloc(w*h*3);
|
|
|
|
const unsigned char *src = data[0];
|
|
|
|
unsigned char *dst = buf;
|
|
|
|
|
|
|
|
// Bytes per pixel
|
|
|
|
int Bpp = GetBpp();
|
|
|
|
|
|
|
|
// Convert
|
|
|
|
for (unsigned int y=0;y<h;y++) {
|
|
|
|
dst = buf + y*w*3;
|
|
|
|
if (flipped) src = data[0] + (h-y-1)*pitch[0];
|
|
|
|
else src = data[0] + y*pitch[0];
|
|
|
|
for (unsigned int x=0;x<w;x++) {
|
|
|
|
*dst++ = *(src+2);
|
|
|
|
*dst++ = *(src+1);
|
|
|
|
*dst++ = *(src);
|
|
|
|
src += Bpp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make image
|
|
|
|
wxImage img(w,h);
|
|
|
|
img.SetData(buf);
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
2007-03-28 03:11:52 +02:00
|
|
|
// YV12
|
2007-04-03 04:31:51 +02:00
|
|
|
else if (format == FORMAT_YV12) {
|
|
|
|
AegiVideoFrame temp;
|
|
|
|
temp.w = w;
|
|
|
|
temp.h = h;
|
|
|
|
temp.pitch[0] = w*4;
|
|
|
|
temp.format = FORMAT_RGB32;
|
|
|
|
temp.ConvertFrom(*this);
|
|
|
|
return temp.GetImage();
|
|
|
|
}
|
2007-03-28 03:11:52 +02:00
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
else {
|
|
|
|
return wxImage(w,h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Get float luminosity data
|
|
|
|
/// @param buffer
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
void AegiVideoFrame::GetFloat(float *buffer) const {
|
|
|
|
int Bpp = GetBpp();
|
|
|
|
const unsigned char *src = data[0];
|
|
|
|
float *dst = buffer;
|
|
|
|
float temp;
|
|
|
|
|
|
|
|
// Convert
|
|
|
|
if (format == FORMAT_RGB32 || format == FORMAT_RGB24) {
|
|
|
|
int delta = 4-Bpp;
|
|
|
|
for (unsigned int y=0;y<h;y++) {
|
|
|
|
dst = buffer + y*w;
|
|
|
|
if (flipped) src = data[0] + (h-y-1)*pitch[0]; // I think that it requires flipped data - amz
|
|
|
|
else src = data[0] + y*pitch[0];
|
|
|
|
for (unsigned int x=0;x<w;x++) {
|
2007-04-06 00:01:33 +02:00
|
|
|
//temp = (*src++)*0.3 + (*src++)*0.4 + (*src++)*0.3;
|
|
|
|
temp = (*src++)*0.3;
|
|
|
|
temp += (*src++)*0.4;
|
|
|
|
temp += (*src++)*0.3;
|
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
src += delta;
|
|
|
|
*dst++ = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Get Bytes per Pixel
|
|
|
|
/// @param plane
|
|
|
|
/// @return
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
int AegiVideoFrame::GetBpp(int plane) const {
|
|
|
|
switch (format) {
|
|
|
|
case FORMAT_RGB32: return 4;
|
|
|
|
case FORMAT_RGB24: return 3;
|
|
|
|
case FORMAT_YUY2: return 2;
|
|
|
|
case FORMAT_YV12:
|
|
|
|
if (plane == 0) return 1;
|
|
|
|
else return 0;
|
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
}
|
2007-04-03 04:31:51 +02:00
|
|
|
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// @brief Convert from another frame
|
|
|
|
/// @param source
|
|
|
|
///
|
2007-04-03 04:31:51 +02:00
|
|
|
void AegiVideoFrame::ConvertFrom(const AegiVideoFrame &source) {
|
|
|
|
// Ensure compatibility
|
|
|
|
if (w != source.w) throw _T("AegiVideoFrame::ConvertFrom: Widths don't match.");
|
|
|
|
if (h != source.h) throw _T("AegiVideoFrame::ConvertFrom: Heights don't match.");
|
|
|
|
if (format != FORMAT_RGB32) throw _T("AegiVideoFrame::ConvertFrom: Unsupported destination format.");
|
|
|
|
if (source.format != FORMAT_YV12) throw _T("AegiVideoFrame::ConvertFrom: Unsupported source format.");
|
|
|
|
|
|
|
|
// Allocate
|
|
|
|
Allocate();
|
|
|
|
|
|
|
|
// Set up pointers
|
|
|
|
const unsigned char *src_y = source.data[0];
|
|
|
|
const unsigned char *src_u = source.data[1];
|
|
|
|
const unsigned char *src_v = source.data[2];
|
|
|
|
unsigned char *dst = data[0];
|
|
|
|
|
|
|
|
// Set up pitches
|
|
|
|
const int src_delta1 = source.pitch[0]-w;
|
|
|
|
const int src_delta2 = source.pitch[1]-w/2;
|
|
|
|
const int src_delta3 = source.pitch[2]-w/2;
|
|
|
|
const int dst_delta = pitch[0]-w*4;
|
2007-04-03 22:41:33 +02:00
|
|
|
register int y,u,v;
|
2007-04-03 04:31:51 +02:00
|
|
|
|
|
|
|
// Loop
|
|
|
|
for (unsigned int py=0;py<h;py++) {
|
|
|
|
for (unsigned int px=0;px<w/2;px++) {
|
2007-04-03 22:41:33 +02:00
|
|
|
u = *src_u++ - 128;
|
|
|
|
v = *src_v++ - 128;
|
2007-04-03 04:31:51 +02:00
|
|
|
for (unsigned int i=0;i<2;i++) {
|
2007-04-03 22:41:33 +02:00
|
|
|
y = (*src_y++ - 16) * 298;
|
2007-04-03 04:31:51 +02:00
|
|
|
|
|
|
|
// Assign
|
2007-04-03 23:05:33 +02:00
|
|
|
*dst++ = ClampSignedInteger32((y + 516 * u + 128) >> 8,0,255); // Blue
|
|
|
|
*dst++ = ClampSignedInteger32((y - 100 * u - 208 * v + 128) >> 8,0,255); // Green
|
|
|
|
*dst++ = ClampSignedInteger32((y + 409 * v + 128) >> 8,0,255); // Red
|
2007-04-03 04:31:51 +02:00
|
|
|
*dst++ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increase pointers
|
|
|
|
src_y += src_delta1;
|
|
|
|
src_u += src_delta2;
|
|
|
|
src_v += src_delta3;
|
|
|
|
dst += dst_delta;
|
|
|
|
|
|
|
|
// Roll back u/v on even lines
|
|
|
|
if (!(py & 1)) {
|
|
|
|
src_u -= source.pitch[1];
|
|
|
|
src_v -= source.pitch[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-29 07:43:02 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|