Ticket #4874: translator.diff

File translator.diff, 4.8 KB (added by julun, 11 years ago)
  • src/add-ons/translators/ico/ICO.h

     
    8383    }
    8484};
    8585
    86 
     86extern bool is_valid_size(int32 size);
    8787extern status_t identify(BMessage *settings, BPositionIO &stream, uint8 &type, int32 &bitsPerPixel);
    8888extern status_t convert_ico_to_bits(BMessage *settings, BPositionIO &source, BPositionIO &target);
    8989extern status_t convert_bits_to_ico(BMessage *settings, BPositionIO &source,
  • src/add-ons/translators/ico/ICOTranslator.cpp

     
    156156}
    157157
    158158
     159status_t
     160ICOTranslator::DerivedCanHandleImageSize(float width, float height) const
     161{
     162    if (!ICO::is_valid_size(width) || !ICO::is_valid_size(height))
     163        return B_NO_TRANSLATOR;
     164    return B_OK;
     165}
     166
     167
    159168BView *
    160169ICOTranslator::NewConfigView(TranslatorSettings *settings)
    161170{
  • src/add-ons/translators/ico/ICOTranslator.h

     
    4444            const translator_info *inInfo, BMessage *ioExtension,
    4545            uint32 outType, BPositionIO *outDestination, int32 baseType);
    4646
     47        virtual status_t DerivedCanHandleImageSize(float width,
     48            float height) const;
     49
    4750        virtual BView *NewConfigView(TranslatorSettings *settings);
    4851
    4952    protected:
  • src/add-ons/translators/ico/ICO.cpp

     
    166166}
    167167
    168168
    169 static bool
    170 is_valid_size(int32 size)
    171 {
    172     return size == 16 || size == 32 || size == 48;
    173 }
    174 
    175 
    176169static uint8
    177170get_alpha_value(color_space space, uint32 value)
    178171{
     
    495488//  #pragma mark -
    496489
    497490
     491bool
     492ICO::is_valid_size(int32 size)
     493{
     494    return size == 16 || size == 32 || size == 48;
     495}
     496
     497
    498498status_t
    499499ICO::identify(BMessage *settings, BPositionIO &stream, uint8 &type, int32 &bitsPerPixel)
    500500{
  • src/add-ons/translators/shared/BaseTranslator.cpp

     
    383383    memcpy(&sourceMagic, ch, sizeof(uint32));
    384384    if (sourceMagic == kBitsMagic)
    385385        return B_OK;
    386     else
    387         return B_OK + 1;
     386    return B_OK + 1;
    388387}
    389388
    390389status_t
     
    392391    const translation_format *inFormat, BMessage *ioExtension,
    393392    translator_info *outInfo, uint32 outType)
    394393{
    395     status_t result;
    396 
    397     result = BitsCheck(inSource, ioExtension, outType);
    398     if (result == B_OK)
    399         result = identify_bits_header(inSource, outInfo);
    400     else if (result == B_OK + 1)
     394    status_t result = BitsCheck(inSource, ioExtension, outType);
     395    if (result == B_OK) {
     396        TranslatorBitmap bitmap;
     397        result = identify_bits_header(inSource, outInfo, &bitmap);
     398        if (result == B_OK)
     399            result = DerivedCanHandleImageSize(bitmap.bounds.Width() + 1.0,
     400                bitmap.bounds.Height() + 1.0);
     401    } else if (result >= B_OK) {
    401402        // if NOT B_TRANSLATOR_BITMAP, it could be an image in the
    402403        // derived format
    403404        result = DerivedIdentify(inSource, inFormat, ioExtension,
    404405            outInfo, outType);
    405        
     406    }
    406407    return result;
    407408}
    408409
     
    452453        case B_TRANSLATOR_BITMAP:
    453454            return BitsIdentify(inSource, inFormat, ioExtension,
    454455                outInfo, outType);
    455            
     456
    456457        default:
    457458            return DerivedIdentify(inSource, inFormat, ioExtension,
    458459                outInfo, outType);
     
    595596        case B_TRANSLATOR_BITMAP:
    596597            return BitsTranslate(inSource, inInfo, ioExtension, outType,
    597598                outDestination);
    598                
     599
    599600        default:
    600601            return DerivedTranslate(inSource, inInfo, ioExtension, outType,
    601602                outDestination, -1);
     
    677678}
    678679
    679680
     681status_t
     682BaseTranslator::DerivedCanHandleImageSize(float width, float height) const
     683{
     684    return B_OK;
     685}
     686
     687
    680688BView *
    681689BaseTranslator::NewConfigView(TranslatorSettings *settings)
    682690{
  • src/add-ons/translators/shared/BaseTranslator.h

     
    110110        const translator_info *inInfo, BMessage *ioExtension,
    111111        uint32 outType, BPositionIO *outDestination, int32 baseType);
    112112       
     113    virtual status_t DerivedCanHandleImageSize(float width, float height) const;
     114
    113115    virtual BView *NewConfigView(TranslatorSettings *settings);
    114116   
    115117