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 550 of file Theme.cpp.

Constructor & Destructor Documentation

◆ SourceOutputStream()

SourceOutputStream::SourceOutputStream ( )
inline

Definition at line 553 of file Theme.cpp.

553{;};

◆ ~SourceOutputStream()

SourceOutputStream::~SourceOutputStream ( )
virtual

Destructor. We close our text stream in here.

Definition at line 602 of file Theme.cpp.

603{
604 File.Write( wxT("\r\n") );
605 File.Close();
606}
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 583 of file Theme.cpp.

584{
585 wxString Temp;
586 for(int i=0;i<(int)bufsize;i++)
587 {
588 // Write one byte with a comma
589 Temp = wxString::Format( wxT("%i,"),(int)(((unsigned char*)buffer)[i]) );
590 File.Write( Temp );
591 nBytes++;
592 // New line if more than 20 bytes written since last time.
593 if( (nBytes %20)==0 )
594 {
595 File.Write( wxT("\r\n "));
596 }
597 }
598 return bufsize;
599}

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 564 of file Theme.cpp.

565{
566 nBytes = 0;
567 bool bOk;
568 bOk = File.Open( Filename, wxFile::write );
569 if( bOk )
570 {
571 File.Write( wxString::Format(
572 wxT("/// @file %s\r\n"), wxFileName(Filename).GetFullName()));
573 File.Write( wxT("/// @brief This file was Auto-Generated.\r\n") );
574 File.Write( wxT("///\r\n") );
575 File.Write( wxT("/// It is included by Theme.cpp.\r\n") );
576 File.Write( wxT("/// Only check this into Git if you've read and understood the guidelines!\r\n\r\n ") );
577 }
578 return bOk;
579}

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 559 of file Theme.cpp.

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

◆ nBytes

int SourceOutputStream::nBytes
protected

Definition at line 560 of file Theme.cpp.

Referenced by OnSysWrite(), and OpenFile().


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