File indexing completed on 2026-04-09 07:49:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <string>
0016 #include <sstream>
0017
0018 #include "spath.h"
0019 #include "ssys.h"
0020
0021 #define STTF_IMPLEMENTATION 1
0022 #include "STTF.h"
0023
0024 #define SIMG_IMPLEMENTATION 1
0025 #include "SIMG.h"
0026
0027
0028 std::string formTEXT()
0029 {
0030 double value = 1.23456789 ;
0031 std::stringstream ss ;
0032 ss << "the quick brown fox jumps over the lazy dog " ;
0033 ss << value ;
0034 ss << std::endl ;
0035 ss << "the quick brown fox jumps over the lazy dog " ;
0036 ss << value ;
0037
0038 std::string text = ss.str();
0039 return text ;
0040 }
0041
0042
0043 int main(int argc, char** argv)
0044 {
0045 const char* path = argc > 1 ? argv[1] : spath::Resolve("$TMP/STTFTest/STTFTest.jpg") ;
0046 std::string _text = formTEXT();
0047 const char* text = _text.c_str();
0048
0049 STTF* ttf = STTF::Create();
0050
0051
0052 int width = 1280;
0053 int height = 720;
0054 int channels = 4 ;
0055 int line_height = ssys::getenvint("LINE_HEIGHT", 32 ) ;
0056 int offset = 0 ;
0057
0058 printf("STTFTest line_height %d \n", line_height );
0059
0060 int magenta[4] = {255,0,255,0} ;
0061 int black[4] = {0,0,0,0} ;
0062
0063 unsigned char* data = (unsigned char*)calloc(width * height * channels, sizeof(unsigned char));
0064 ttf->render_background( data, channels, width, height, magenta ) ;
0065
0066 ttf->render_background( data+offset, channels, width, line_height, black ) ;
0067 ttf->render_text( data+offset, channels, width, line_height, text ) ;
0068
0069 offset = width*height*channels/2 ;
0070 ttf->render_background( data+offset, channels, width, line_height, black ) ;
0071 ttf->render_text( data+offset, channels, width, line_height, text ) ;
0072
0073 bool lowlevel = false ;
0074
0075 if( lowlevel )
0076 {
0077 offset = width*(height-line_height-1)*channels ;
0078 ttf->render_background( data+offset, channels, width, line_height, black ) ;
0079 ttf->render_text( data+offset, channels, width, line_height, text ) ;
0080 }
0081 else
0082 {
0083 ttf->annotate( data , channels, width, height, line_height, text, true );
0084 ttf->annotate( data , channels, width, height, line_height, text, false );
0085 }
0086
0087
0088
0089
0090 SIMG img(width, height, channels, data );
0091
0092 int quality = 50 ;
0093 printf("STTFTest : writing to %s quality %d \n", path, quality );
0094 img.writeJPG(path, quality );
0095
0096 free(data);
0097
0098 return 0 ;
0099 }