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/
|
|
|
|
|
|
|
|
/// @file video_frame.cpp
|
|
|
|
/// @brief Wrapper around a frame of video data
|
|
|
|
/// @ingroup video
|
|
|
|
///
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-04-03 04:31:51 +02:00
|
|
|
#include "utils.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_frame.h"
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2007-03-24 03:07:06 +01:00
|
|
|
void AegiVideoFrame::Reset() {
|
2007-03-28 03:11:52 +02:00
|
|
|
// Zero variables
|
2010-12-31 22:03:11 +01:00
|
|
|
data = 0;
|
|
|
|
pitch = 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-01-21 07:30:19 +01:00
|
|
|
flipped = false;
|
|
|
|
invertChannels = true;
|
2009-10-24 04:07:56 +02:00
|
|
|
ownMem = true;
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
2007-03-24 03:07:06 +01:00
|
|
|
AegiVideoFrame::AegiVideoFrame() {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
2009-10-24 04:07:56 +02:00
|
|
|
/// @brief Create a solid black frame of the request size and format
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @param width
|
|
|
|
/// @param height
|
2010-12-31 22:03:11 +01:00
|
|
|
AegiVideoFrame::AegiVideoFrame(unsigned int width, unsigned int height) {
|
|
|
|
assert(width > 0 && width < 10000);
|
|
|
|
assert(height > 0 && height < 10000);
|
|
|
|
|
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
|
|
|
w = width;
|
|
|
|
h = height;
|
2010-12-31 22:03:11 +01:00
|
|
|
pitch = w * GetBpp();
|
2007-01-21 07:30:19 +01:00
|
|
|
|
|
|
|
Allocate();
|
2010-12-31 22:03:11 +01:00
|
|
|
memset(data, 0, pitch * height);
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AegiVideoFrame::Allocate() {
|
2010-12-31 22:03:11 +01:00
|
|
|
assert(pitch > 0 && pitch < 10000);
|
|
|
|
assert(w > 0 && w < 10000);
|
|
|
|
assert(h > 0 && h < 10000);
|
2007-03-28 00:29:35 +02:00
|
|
|
|
2010-12-31 22:03:11 +01:00
|
|
|
unsigned int size = pitch * h;
|
2007-01-28 04:26:03 +01:00
|
|
|
|
|
|
|
// Reallocate, if necessary
|
2009-10-24 04:07:56 +02:00
|
|
|
if (memSize != size || !ownMem) {
|
2010-12-31 22:03:11 +01:00
|
|
|
if (ownMem) {
|
|
|
|
delete[] data;
|
2007-03-24 03:07:06 +01:00
|
|
|
}
|
2010-12-31 22:03:11 +01:00
|
|
|
data = new unsigned char[size];
|
2007-01-28 04:26:03 +01:00
|
|
|
memSize = size;
|
2007-03-28 00:29:35 +02:00
|
|
|
}
|
2009-10-24 04:07:56 +02:00
|
|
|
|
|
|
|
ownMem = true;
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AegiVideoFrame::Clear() {
|
2010-12-31 22:03:11 +01:00
|
|
|
if (ownMem) delete[] data;
|
2009-10-24 04:07:56 +02:00
|
|
|
Reset();
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void AegiVideoFrame::CopyFrom(const AegiVideoFrame &source) {
|
|
|
|
w = source.w;
|
|
|
|
h = source.h;
|
2010-12-31 22:03:11 +01:00
|
|
|
pitch = source.pitch;
|
2007-01-21 07:30:19 +01:00
|
|
|
Allocate();
|
2010-12-31 22:03:11 +01:00
|
|
|
memcpy(data, source.data, memSize);
|
2007-01-21 07:30:19 +01:00
|
|
|
flipped = source.flipped;
|
|
|
|
invertChannels = source.invertChannels;
|
|
|
|
}
|
|
|
|
|
2010-12-31 22:03:11 +01:00
|
|
|
void AegiVideoFrame::SetTo(const unsigned char *source, unsigned int width, unsigned int height, unsigned int pitch) {
|
|
|
|
assert(pitch > 0 && pitch < 10000);
|
|
|
|
assert(width > 0 && width < 10000);
|
|
|
|
assert(height > 0 && height < 10000);
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2009-10-24 04:07:56 +02:00
|
|
|
ownMem = false;
|
|
|
|
w = width;
|
|
|
|
h = height;
|
2010-12-31 22:03:11 +01:00
|
|
|
// Note that despite this cast, the contents of data should still never be modified
|
|
|
|
data = const_cast<unsigned char*>(source);
|
|
|
|
this->pitch = pitch;
|
2009-10-24 04:07:56 +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
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
wxImage AegiVideoFrame::GetImage() const {
|
2010-12-31 22:03:11 +01:00
|
|
|
unsigned char *buf = (unsigned char*)malloc(w*h*3);
|
|
|
|
if (!buf) throw std::bad_alloc();
|
|
|
|
|
|
|
|
int Bpp = GetBpp();
|
|
|
|
|
|
|
|
// Convert
|
|
|
|
for (unsigned int y=0;y<h;y++) {
|
2012-09-14 16:55:01 +02:00
|
|
|
unsigned char *dst = buf + y*w*3;
|
|
|
|
const unsigned char *src;
|
2010-12-31 22:03:11 +01:00
|
|
|
if (flipped) src = data + (h-y-1)*pitch;
|
|
|
|
else src = data + y*pitch;
|
|
|
|
for (unsigned int x=0;x<w;x++) {
|
|
|
|
*dst++ = *(src+2);
|
|
|
|
*dst++ = *(src+1);
|
|
|
|
*dst++ = *(src);
|
|
|
|
src += Bpp;
|
2007-01-21 07:30:19 +01:00
|
|
|
}
|
2007-04-03 04:31:51 +02:00
|
|
|
}
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2010-12-31 22:03:11 +01:00
|
|
|
wxImage img(w,h);
|
|
|
|
img.SetData(buf);
|
|
|
|
return img;
|
2007-04-03 04:31:51 +02:00
|
|
|
}
|