@@ -6964,6 +6964,12 @@ static void _jpeg_term_destination(j_compress_ptr jpeg_ptr) {
69646964#endif
69656965
69666966bool cPng::_write_jpeg (const char *filePathName, SimpleBuffer *jpeg, int quality, string *error) {
6967+ if (!width || !height) {
6968+ if (error) {
6969+ *error = " empty jpeg image" ;
6970+ }
6971+ return (false );
6972+ }
69676973#ifdef HAVE_LIBJPEG
69686974 FILE *fp = NULL ;
69696975 if (filePathName) {
@@ -7327,18 +7333,21 @@ bool create_spectrogram_from_raw(u_char *raw, size_t rawSamples, unsigned sample
73277333 if (rawSamples < 1 ) {
73287334 return (false );
73297335 }
7336+ if (!msPerPixel) {
7337+ msPerPixel = get_audiograph_ms_per_pixel (rawSamples, sampleRate);
7338+ }
7339+ size_t stepSamples = sampleRate * msPerPixel / 1000 ;
7340+ size_t width = rawSamples / stepSamples;
7341+ if (width < 2 ) {
7342+ return (false );
7343+ }
73307344 extern bool opt_fftw_fork_mode;
73317345 if (!opt_fftw_fork_mode) {
73327346 fftw_multithread_init ();
73337347 }
73347348 cPng::pixel palette[256 ];
73357349 set_spectrogram_palette (palette);
73367350 size_t palette_size = sizeof (palette) / sizeof (cPng::pixel);
7337- if (!msPerPixel) {
7338- msPerPixel = get_audiograph_ms_per_pixel (rawSamples, sampleRate);
7339- }
7340- size_t stepSamples = sampleRate * msPerPixel / 1000 ;
7341- size_t width = rawSamples / stepSamples;
73427351 size_t fftSize;
73437352 double *fftw_in;
73447353 fftw_complex *fftw_out;
@@ -7478,6 +7487,14 @@ bool create_spectrogram_from_raw(const char *rawInput, unsigned sampleRate, unsi
74787487 if (rawSamples < 1 ) {
74797488 return (false );
74807489 }
7490+ if (!msPerPixel) {
7491+ msPerPixel = get_audiograph_ms_per_pixel (rawSamples, sampleRate);
7492+ }
7493+ size_t stepSamples = sampleRate * msPerPixel / 1000 ;
7494+ size_t width = rawSamples / stepSamples;
7495+ if (width < 2 ) {
7496+ return (false );
7497+ }
74817498 FILE *inputRawHandle = fopen (rawInput, " rb" );
74827499 if (!inputRawHandle) {
74837500 return (false );
@@ -7489,11 +7506,6 @@ bool create_spectrogram_from_raw(const char *rawInput, unsigned sampleRate, unsi
74897506 cPng::pixel palette[256 ];
74907507 set_spectrogram_palette (palette);
74917508 size_t palette_size = sizeof (palette) / sizeof (cPng::pixel);
7492- if (!msPerPixel) {
7493- msPerPixel = get_audiograph_ms_per_pixel (rawSamples, sampleRate);
7494- }
7495- size_t stepSamples = sampleRate * msPerPixel / 1000 ;
7496- size_t width = rawSamples / stepSamples;
74977509 size_t fftSize;
74987510 double *fftw_in;
74997511 fftw_complex *fftw_out;
0 commit comments