From 342322cea50f199c1c350e51b9b3cc96c77d6218 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Thu, 30 Mar 2006 03:53:29 +0000 Subject: [PATCH] Originally committed to SVN as r258. --- core/ram_output_stream.cpp | 49 +++++++++++++++++++++++++++++++++ core/ram_output_stream.h | 52 ++++++++++++++++++++++++++++++++++++ core/subtitle_format_prs.cpp | 20 +++++++++----- core/subtitle_format_prs.h | 3 ++- 4 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 core/ram_output_stream.cpp create mode 100644 core/ram_output_stream.h diff --git a/core/ram_output_stream.cpp b/core/ram_output_stream.cpp new file mode 100644 index 000000000..90d893f85 --- /dev/null +++ b/core/ram_output_stream.cpp @@ -0,0 +1,49 @@ +// Copyright (c) 2006, 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "ram_output_stream.h" + + +///////// +// Write +wxOutputStream& RAMOutputStream::Write(const void *buffer, size_t size) { + size_t start = data.size(); + data.resize(start+size); + memcpy(&data[start],buffer,size); + return *this; +} diff --git a/core/ram_output_stream.h b/core/ram_output_stream.h new file mode 100644 index 000000000..28e5fb5cf --- /dev/null +++ b/core/ram_output_stream.h @@ -0,0 +1,52 @@ +// Copyright (c) 2006, 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +#pragma once + + +/////////// +// Headers +#include +#include + + +/////////////////////////// +// RAM output stream class +class RAMOutputStream : public wxOutputStream { +public: + std::vector data; + wxOutputStream& Write(const void *buffer, size_t size); +}; diff --git a/core/subtitle_format_prs.cpp b/core/subtitle_format_prs.cpp index 6a14b897c..2d249388e 100644 --- a/core/subtitle_format_prs.cpp +++ b/core/subtitle_format_prs.cpp @@ -112,22 +112,26 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) { PVideoFrame frame2 = clip2->GetFrame(framen,env2); // Convert to PNG - wxImage bmp = CalculateAlpha(frame1->GetReadPtr(),frame2->GetReadPtr(),frame1->GetRowSize(),frame1->GetHeight(),frame1->GetPitch()); - bmp.SaveFile(filename + wxString::Format(_T("%i.png"),id),wxBITMAP_TYPE_PNG); + int x=0,y=0; + wxImage bmp = CalculateAlpha(frame1->GetReadPtr(),frame2->GetReadPtr(),frame1->GetRowSize(),frame1->GetHeight(),frame1->GetPitch(),&x,&y); + //bmp.SaveFile(filename + wxString::Format(_T("%i.png"),id),wxBITMAP_TYPE_PNG); + RAMOutputStream stream; + bmp.SaveFile(stream,wxBITMAP_TYPE_PNG); // Create PRSImage PRSImage *img = new PRSImage; img->id = id; - img->dataLen = 0; - img->data = NULL; + img->dataLen = stream.data.size(); + img->data = new char[img->dataLen]; + memcpy(img->data,&stream.data[0],img->dataLen); // Create PRSDisplay PRSDisplay *display = new PRSDisplay; display->start = diag->Start.GetMS(); display->end = diag->End.GetMS(); display->id = id; - display->x = 0; - display->y = 0; + display->x = x; + display->y = y; display->alpha = 255; display->blend = 0; @@ -158,7 +162,7 @@ void PRSSubtitleFormat::WriteFile(wxString filename,wxString encoding) { // ------------------------------------------ // Frame 1 should have the image on a BLACK background // Frame 2 should have the same image on a WHITE background -wxImage PRSSubtitleFormat::CalculateAlpha(const unsigned char* frame1, const unsigned char* frame2, int w, int h, int pitch) { +wxImage PRSSubtitleFormat::CalculateAlpha(const unsigned char* frame1, const unsigned char* frame2, int w, int h, int pitch, int *dstx, int *dsty) { // Allocate image data unsigned char *data = (unsigned char*) malloc(sizeof(unsigned char)*w*h*3); unsigned char *alpha = (unsigned char*) malloc(sizeof(unsigned char)*w*h); @@ -232,6 +236,8 @@ wxImage PRSSubtitleFormat::CalculateAlpha(const unsigned char* frame1, const uns // Return subimage minx /= 4; maxx /= 4; + if (dstx) *dstx = minx; + if (dsty) *dsty = miny; wxImage subimg = SubImageWithAlpha(img,wxRect(minx,miny,maxx-minx+1,maxy-miny+1)); return subimg; } diff --git a/core/subtitle_format_prs.h b/core/subtitle_format_prs.h index 29c51353d..478e3c385 100644 --- a/core/subtitle_format_prs.h +++ b/core/subtitle_format_prs.h @@ -40,6 +40,7 @@ /////////// // Headers #include "subtitle_format.h" +#include "ram_output_stream.h" ////////////// @@ -47,7 +48,7 @@ class PRSSubtitleFormat : public SubtitleFormat { private: wxImage SubImageWithAlpha(wxImage src,const wxRect &area); - wxImage CalculateAlpha(const unsigned char* frame1, const unsigned char* frame2, int w, int h, int pitch); + wxImage CalculateAlpha(const unsigned char* frame1, const unsigned char* frame2, int w, int h, int pitch, int *x=NULL, int *y=NULL); public: bool CanWriteFile(wxString filename);