Verified Commit 1987a0a4 authored by Mark Harris's avatar Mark Harris
Browse files

Split out tag comparison from picture.c

Avoids the need to link picture.c into opusenc.
parent ae5d6d59
......@@ -19,6 +19,7 @@ noinst_HEADERS = src/arch.h \
src/opus_header.h \
src/opusinfo.h \
src/picture.h \
src/tagcompare.h \
src/resample_sse.h \
src/speex_resampler.h \
src/stack_alloc.h \
......@@ -51,7 +52,7 @@ dist_man_MANS = man/opusenc.1 man/opusdec.1 man/opusinfo.1
resampler_CPPFLAGS = -DRANDOM_PREFIX=opustools -DOUTSIDE_SPEEX -DRESAMPLE_FULL_SINC_TABLE
opusenc_SOURCES = src/opus_header.c src/opusenc.c src/picture.c src/audio-in.c src/diag_range.c src/flac.c win32/unicode_support.c
opusenc_SOURCES = src/opus_header.c src/opusenc.c src/tagcompare.c src/audio-in.c src/diag_range.c src/flac.c win32/unicode_support.c
opusenc_CPPFLAGS = $(AM_CPPFLAGS)
opusenc_CFLAGS = $(AM_CFLAGS) $(LIBOPUSENC_CFLAGS) $(FLAC_CFLAGS)
opusenc_LDADD = $(LIBOPUSENC_LIBS) $(OPUS_LIBS) $(FLAC_LIBS) $(OGG_LIBS) $(LIBM)
......@@ -63,7 +64,7 @@ opusdec_CFLAGS = $(AM_CFLAGS) $(OPUSURL_CFLAGS)
opusdec_LDADD = $(OPUSURL_LIBS) $(OPUS_LIBS) $(LIBM)
opusdec_MANS = man/opusdec.1
opusinfo_SOURCES = src/opus_header.c src/opusinfo.c src/info_opus.c src/picture.c win32/unicode_support.c
opusinfo_SOURCES = src/opus_header.c src/opusinfo.c src/info_opus.c src/picture.c src/tagcompare.c win32/unicode_support.c
opusinfo_CPPFLAGS = $(AM_CPPFLAGS) -DOPUSTOOLS
opusinfo_LDADD = $(OGG_LIBS)
opusinfo_MANS = man/opusinfo.1
......
......@@ -33,7 +33,7 @@
#include "encoder.h"
#include "flac.h"
#include "opus_header.h"
#include "picture.h"
#include "tagcompare.h"
#if defined(HAVE_LIBFLAC)
......@@ -133,7 +133,7 @@ static void metadata_callback(const FLAC__StreamDecoder *decoder,
if(!entry)continue;
/*Check for ReplayGain tags.
Parse the ones we have R128 equivalents for, and skip the others.*/
if(oi_strncasecmp(entry,"REPLAYGAIN_REFERENCE_LOUDNESS=",30)==0){
if(tagcompare(entry,"REPLAYGAIN_REFERENCE_LOUDNESS=",30)==0){
gain=strtod(entry+30,&end);
if(end<=entry+30){
fprintf(stderr,_("WARNING: Invalid ReplayGain tag: %s\n"),entry);
......@@ -141,7 +141,7 @@ static void metadata_callback(const FLAC__StreamDecoder *decoder,
else reference_loudness=gain;
continue;
}
if(oi_strncasecmp(entry,"REPLAYGAIN_ALBUM_GAIN=",22)==0){
if(tagcompare(entry,"REPLAYGAIN_ALBUM_GAIN=",22)==0){
gain=strtod(entry+22,&end);
if(end<=entry+22){
fprintf(stderr,_("WARNING: Invalid ReplayGain tag: %s\n"),entry);
......@@ -152,7 +152,7 @@ static void metadata_callback(const FLAC__StreamDecoder *decoder,
}
continue;
}
if(oi_strncasecmp(entry,"REPLAYGAIN_TRACK_GAIN=",22)==0){
if(tagcompare(entry,"REPLAYGAIN_TRACK_GAIN=",22)==0){
gain=strtod(entry+22,&end);
if(end<entry+22){
fprintf(stderr,_("WARNING: Invalid ReplayGain tag: %s\n"),entry);
......@@ -163,8 +163,8 @@ static void metadata_callback(const FLAC__StreamDecoder *decoder,
}
continue;
}
if(oi_strncasecmp(entry,"REPLAYGAIN_ALBUM_PEAK=",22)==0
||oi_strncasecmp(entry,"REPLAYGAIN_TRACK_PEAK=",22)==0){
if(tagcompare(entry,"REPLAYGAIN_ALBUM_PEAK=",22)==0
||tagcompare(entry,"REPLAYGAIN_TRACK_PEAK=",22)==0){
continue;
}
if(!strchr(entry,'=')){
......
......@@ -31,6 +31,7 @@
#include "opus_header.h"
#include "info_opus.h"
#include "picture.h"
#include "tagcompare.h"
#if defined WIN32 || defined _WIN32
# include "unicode_support.h"
......@@ -256,7 +257,7 @@ void check_xiph_comment(stream_processor *stream, int i, const char *comment,
}
if(sep - comment == 22
&& oi_strncasecmp(comment, "METADATA_BLOCK_PICTURE", 22) == 0) {
&& tagcompare(comment, "METADATA_BLOCK_PICTURE", 22) == 0) {
ogg_uint32_t picture_type;
ogg_uint32_t mime_type_length;
ogg_uint32_t description_length;
......@@ -440,7 +441,7 @@ void check_xiph_comment(stream_processor *stream, int i, const char *comment,
is_url = 0;
format = -1;
if(mime_type_length == 10
&& oi_strncasecmp((const char*)data+8, "image/jpeg",
&& tagcompare((const char*)data+8, "image/jpeg",
mime_type_length) == 0) {
if(!is_jpeg(data+j, image_length)) {
oi_warn(_("WARNING: Invalid image data in "
......@@ -453,7 +454,7 @@ void check_xiph_comment(stream_processor *stream, int i, const char *comment,
format = PIC_FORMAT_JPEG;
}
else if(mime_type_length == 9
&& oi_strncasecmp((const char *)data+8, "image/png",
&& tagcompare((const char *)data+8, "image/png",
mime_type_length) == 0) {
if(!is_png(data+j, image_length)) {
oi_warn(_("WARNING: Invalid image data in "
......@@ -466,7 +467,7 @@ void check_xiph_comment(stream_processor *stream, int i, const char *comment,
format = PIC_FORMAT_PNG;
}
else if(mime_type_length == 9
&& oi_strncasecmp((const char *)data+8, "image/gif",
&& tagcompare((const char *)data+8, "image/gif",
mime_type_length) == 0) {
if(!is_gif(data+j, image_length)) {
oi_warn(_("WARNING: Invalid image data in "
......@@ -484,7 +485,7 @@ void check_xiph_comment(stream_processor *stream, int i, const char *comment,
/*TODO: validate URL.*/
}
else if(mime_type_length == 0 || (mime_type_length == 6 &&
oi_strncasecmp((const char *)data+8, "image/",
tagcompare((const char *)data+8, "image/",
mime_type_length) == 0)) {
if(is_jpeg(data+j, image_length)) {
format = PIC_FORMAT_JPEG;
......
......@@ -29,37 +29,11 @@
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "picture.h"
/*A version of strncasecmp() that is guaranteed to only ignore the case of
ASCII characters.*/
int oi_strncasecmp(const char *a, const char *b, int n)
{
int i;
for(i=0;i<n;i++){
int aval;
int bval;
int diff;
aval=a[i];
bval=b[i];
if(aval>='a'&&aval<='z') {
aval-='a'-'A';
}
if(bval>='a'&&bval<='z'){
bval-='a'-'A';
}
diff=aval-bval;
if(diff){
return diff;
}
}
return 0;
}
int is_jpeg(const unsigned char *buf, size_t length)
{
return length>=3&&memcmp(buf,"\xFF\xD8\xFF",3)==0;
......
......@@ -6,8 +6,6 @@ typedef enum {
PIC_FORMAT_GIF
} picture_format;
int oi_strncasecmp(const char *a, const char *b, int n);
int is_jpeg(const unsigned char *buf, size_t length);
int is_png(const unsigned char *buf, size_t length);
int is_gif(const unsigned char *buf, size_t length);
......
/* Copyright (C)2007-2021 Xiph.Org Foundation
File: tagcompare.c
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.
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 FOUNDATION 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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
/*A version of strncasecmp() that is guaranteed to only ignore the case of
ASCII characters.*/
int tagcompare(const char *a, const char *b, size_t n)
{
size_t i;
for (i = 0; i < n; i++)
{
int aval = (unsigned char)a[i];
int bval = (unsigned char)b[i];
int diff;
if (aval >= 'a' && aval <= 'z') aval -= 'a' - 'A';
if (bval >= 'a' && bval <= 'z') bval -= 'a' - 'A';
diff = aval - bval;
if (diff) return diff;
}
return 0;
}
#include <stdlib.h>
int tagcompare(const char *a, const char *b, size_t n);
......@@ -23,7 +23,7 @@
<ClCompile Include="..\..\share\getopt1.c" />
<ClCompile Include="..\..\src\opus_header.c" />
<ClCompile Include="..\..\src\opusenc.c" />
<ClCompile Include="..\..\src\picture.c" />
<ClCompile Include="..\..\src\tagcompare.c" />
<ClCompile Include="..\..\src\audio-in.c" />
<ClCompile Include="..\..\src\diag_range.c" />
<ClCompile Include="..\..\src\flac.c" />
......@@ -37,7 +37,7 @@
<ClInclude Include="..\..\src\encoder.h" />
<ClInclude Include="..\..\src\flac.h" />
<ClInclude Include="..\..\src\opus_header.h" />
<ClInclude Include="..\..\src\picture.h" />
<ClInclude Include="..\..\src\tagcompare.h" />
<ClInclude Include="..\..\src\stack_alloc.h" />
<ClInclude Include="..\..\src\wav_io.h" />
<ClInclude Include="..\..\win32\config.h" />
......
......@@ -32,7 +32,7 @@
<ClCompile Include="..\..\src\opus_header.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\picture.c">
<ClCompile Include="..\..\src\tagcompare.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\win32\unicode_support.c">
......@@ -55,7 +55,7 @@
<ClInclude Include="..\..\src\opus_header.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\picture.h">
<ClInclude Include="..\..\src\tagcompare.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\stack_alloc.h">
......
......@@ -25,6 +25,7 @@
<ClCompile Include="..\..\src\opusinfo.c" />
<ClCompile Include="..\..\src\info_opus.c" />
<ClCompile Include="..\..\src\picture.c" />
<ClCompile Include="..\..\src\tagcompare.c" />
<ClCompile Include="..\..\win32\unicode_support.c" />
</ItemGroup>
<ItemGroup>
......@@ -33,6 +34,7 @@
<ClInclude Include="..\..\src\opusinfo.h" />
<ClInclude Include="..\..\src\opus_header.h" />
<ClInclude Include="..\..\src\picture.h" />
<ClInclude Include="..\..\src\tagcompare.h" />
<ClInclude Include="..\..\win32\config.h" />
<ClInclude Include="..\..\win32\unicode_support.h" />
</ItemGroup>
......@@ -90,4 +92,4 @@
<PropertyGroup Label="UserMacros" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
</Project>
\ No newline at end of file
</Project>
......@@ -29,6 +29,9 @@
<ClCompile Include="..\..\src\picture.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\tagcompare.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\win32\unicode_support.c">
<Filter>Source Files</Filter>
</ClCompile>
......@@ -46,6 +49,9 @@
<ClInclude Include="..\..\src\picture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\tagcompare.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\win32\config.h">
<Filter>Header Files</Filter>
</ClInclude>
......@@ -56,4 +62,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
</Project>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment