Audacity 3.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SourceOutputStream Class Referencefinal

Helper class based on wxOutputStream used to get a png file in text format. More...

Inheritance diagram for SourceOutputStream:
[legend]
Collaboration diagram for SourceOutputStream:
[legend]

Public Member Functions

 SourceOutputStream ()
 
int OpenFile (const FilePath &Filename)
 Opens the file and also adds a standard comment at the start of it. More...
 
virtual ~SourceOutputStream ()
 Destructor. We close our text stream in here. More...
 

Protected Member Functions

size_t OnSysWrite (const void *buffer, size_t bufsize) override
 

Protected Attributes

wxFile File
 
int nBytes
 

Detailed Description

Helper class based on wxOutputStream used to get a png file in text format.

Allows us to capture output of the Save .png and 'pipe' it into our own output function which gives a series of numbers.

The trick used here is that wxWidgets can write a PNG image to a stream. By writing to a custom stream, we get to see each byte of data in turn, convert it to text, put in commas, and then write that out to our own text stream.

This class is currently used by Theme to pack its images into the image cache. Perhaps someday we will improve FlowPacker and make it more flexible, and use it for toolbar and window layouts too.

Definition at line 492 of file Theme.cpp.

Constructor & Destructor Documentation

◆ SourceOutputStream()

SourceOutputStream::SourceOutputStream ( )
inline

Definition at line 495 of file Theme.cpp.

495{;};

◆ ~SourceOutputStream()

SourceOutputStream::~SourceOutputStream ( )
virtual

Destructor. We close our text stream in here.

Definition at line 544 of file Theme.cpp.

545{
546 File.Write( wxT("\r\n") );
547 File.Close();
548}
wxT("CloseDown"))

References File, and wxT().

Here is the call graph for this function:

Member Function Documentation

◆ OnSysWrite()

size_t SourceOutputStream::OnSysWrite ( const void *  buffer,
size_t  bufsize 
)
overrideprotected

This is the 'callback' function called with each write of PNG data to the stream. This is where we conveet to text and add commas.

Definition at line 525 of file Theme.cpp.

526{
527 wxString Temp;
528 for(int i=0;i<(int)bufsize;i++)
529 {
530 // Write one byte with a comma
531 Temp = wxString::Format( wxT("%i,"),(int)(((unsigned char*)buffer)[i]) );
532 File.Write( Temp );
533 nBytes++;
534 // New line if more than 20 bytes written since last time.
535 if( (nBytes %20)==0 )
536 {
537 File.Write( wxT("\r\n "));
538 }
539 }
540 return bufsize;
541}

References File, nBytes, and wxT().

Here is the call graph for this function:

◆ OpenFile()

int SourceOutputStream::OpenFile ( const FilePath Filename)

Opens the file and also adds a standard comment at the start of it.

Definition at line 506 of file Theme.cpp.

507{
508 nBytes = 0;
509 bool bOk;
510 bOk = File.Open( Filename, wxFile::write );
511 if( bOk )
512 {
513 File.Write( wxString::Format(
514 wxT("/// @file %s\r\n"), wxFileName(Filename).GetFullName()));
515 File.Write( wxT("/// @brief This file was Auto-Generated.\r\n") );
516 File.Write( wxT("///\r\n") );
517 File.Write( wxT("/// It is included by Theme.cpp.\r\n") );
518 File.Write( wxT("/// Only check this into Git if you've read and understood the guidelines!\r\n\r\n ") );
519 }
520 return bOk;
521}

References File, nBytes, and wxT().

Referenced by ThemeBase::CreateOneImageCache().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ File

wxFile SourceOutputStream::File
protected

Definition at line 501 of file Theme.cpp.

Referenced by OnSysWrite(), OpenFile(), and ~SourceOutputStream().

◆ nBytes

int SourceOutputStream::nBytes
protected

Definition at line 502 of file Theme.cpp.

Referenced by OnSysWrite(), and OpenFile().


The documentation for this class was generated from the following file: