[haiku-commits] r35186 - in haiku/trunk/src/add-ons/translators: ico shared

Author: julun
Date: 2010-01-19 23:52:09 +0100 (Tue, 19 Jan 2010)
New Revision: 35186
Changeset: http://dev.haiku-os.org/changeset/35186/haiku
Ticket: http://dev.haiku-os.org/ticket/4874

Modified:
   haiku/trunk/src/add-ons/translators/ico/ICO.cpp
   haiku/trunk/src/add-ons/translators/ico/ICO.h
   haiku/trunk/src/add-ons/translators/ico/ICOTranslator.cpp
   haiku/trunk/src/add-ons/translators/ico/ICOTranslator.h
   haiku/trunk/src/add-ons/translators/shared/BaseTranslator.cpp
   haiku/trunk/src/add-ons/translators/shared/BaseTranslator.h
Log:
* Introduce a new method to ask the translator if it can handle the image
  output size, if not it will not show up in the dynamically generated
  translator list. Folow up on ticket #4874.

Modified: haiku/trunk/src/add-ons/translators/ico/ICO.cpp
===================================================================
--- haiku/trunk/src/add-ons/translators/ico/ICO.cpp     2010-01-19 22:05:18 UTC 
(rev 35185)
+++ haiku/trunk/src/add-ons/translators/ico/ICO.cpp     2010-01-19 22:52:09 UTC 
(rev 35186)
@@ -166,13 +166,6 @@
 }
 
 
-static bool
-is_valid_size(int32 size)
-{
-       return size == 16 || size == 32 || size == 48;
-}
-
-
 static uint8
 get_alpha_value(color_space space, uint32 value)
 {
@@ -495,6 +488,13 @@
 //     #pragma mark -
 
 
+bool
+ICO::is_valid_size(int32 size)
+{
+       return size == 16 || size == 32 || size == 48;
+}
+
+
 status_t
 ICO::identify(BMessage *settings, BPositionIO &stream, uint8 &type, int32 
&bitsPerPixel)
 {

Modified: haiku/trunk/src/add-ons/translators/ico/ICO.h
===================================================================
--- haiku/trunk/src/add-ons/translators/ico/ICO.h       2010-01-19 22:05:18 UTC 
(rev 35185)
+++ haiku/trunk/src/add-ons/translators/ico/ICO.h       2010-01-19 22:52:09 UTC 
(rev 35186)
@@ -83,7 +83,7 @@
        }
 };
 
-
+extern bool is_valid_size(int32 size);
 extern status_t identify(BMessage *settings, BPositionIO &stream, uint8 &type, 
int32 &bitsPerPixel);
 extern status_t convert_ico_to_bits(BMessage *settings, BPositionIO &source, 
BPositionIO &target);
 extern status_t convert_bits_to_ico(BMessage *settings, BPositionIO &source,

Modified: haiku/trunk/src/add-ons/translators/ico/ICOTranslator.cpp
===================================================================
--- haiku/trunk/src/add-ons/translators/ico/ICOTranslator.cpp   2010-01-19 
22:05:18 UTC (rev 35185)
+++ haiku/trunk/src/add-ons/translators/ico/ICOTranslator.cpp   2010-01-19 
22:52:09 UTC (rev 35186)
@@ -156,6 +156,15 @@
 }
 
 
+status_t
+ICOTranslator::DerivedCanHandleImageSize(float width, float height) const
+{
+       if (!ICO::is_valid_size(width) || !ICO::is_valid_size(height))
+               return B_NO_TRANSLATOR;
+       return B_OK;
+}
+
+
 BView *
 ICOTranslator::NewConfigView(TranslatorSettings *settings)
 {

Modified: haiku/trunk/src/add-ons/translators/ico/ICOTranslator.h
===================================================================
--- haiku/trunk/src/add-ons/translators/ico/ICOTranslator.h     2010-01-19 
22:05:18 UTC (rev 35185)
+++ haiku/trunk/src/add-ons/translators/ico/ICOTranslator.h     2010-01-19 
22:52:09 UTC (rev 35186)
@@ -44,6 +44,9 @@
                        const translator_info *inInfo, BMessage *ioExtension,
                        uint32 outType, BPositionIO *outDestination, int32 
baseType);
 
+               virtual status_t DerivedCanHandleImageSize(float width,
+                       float height) const;
+
                virtual BView *NewConfigView(TranslatorSettings *settings);     
 
        protected:

Modified: haiku/trunk/src/add-ons/translators/shared/BaseTranslator.cpp
===================================================================
--- haiku/trunk/src/add-ons/translators/shared/BaseTranslator.cpp       
2010-01-19 22:05:18 UTC (rev 35185)
+++ haiku/trunk/src/add-ons/translators/shared/BaseTranslator.cpp       
2010-01-19 22:52:09 UTC (rev 35186)
@@ -383,8 +383,7 @@
        memcpy(&sourceMagic, ch, sizeof(uint32));
        if (sourceMagic == kBitsMagic)
                return B_OK;
-       else
-               return B_OK + 1;
+       return B_OK + 1;
 }
 
 status_t
@@ -392,17 +391,19 @@
        const translation_format *inFormat, BMessage *ioExtension,
        translator_info *outInfo, uint32 outType)
 {
-       status_t result;
-
-       result = BitsCheck(inSource, ioExtension, outType);
-       if (result == B_OK)
-               result = identify_bits_header(inSource, outInfo);
-       else if (result == B_OK + 1)
+       status_t result = BitsCheck(inSource, ioExtension, outType);
+       if (result == B_OK) {
+               TranslatorBitmap bitmap;
+               result = identify_bits_header(inSource, outInfo, &bitmap);
+               if (result == B_OK)
+                       result = 
DerivedCanHandleImageSize(bitmap.bounds.Width() + 1.0,
+                               bitmap.bounds.Height() + 1.0);
+       } else if (result >= B_OK) {
                // if NOT B_TRANSLATOR_BITMAP, it could be an image in the
                // derived format
                result = DerivedIdentify(inSource, inFormat, ioExtension,
                        outInfo, outType);
-               
+       }
        return result;
 }
 
@@ -452,7 +453,7 @@
                case B_TRANSLATOR_BITMAP:
                        return BitsIdentify(inSource, inFormat, ioExtension,
                                outInfo, outType);
-                       
+
                default:
                        return DerivedIdentify(inSource, inFormat, ioExtension,
                                outInfo, outType);
@@ -595,7 +596,7 @@
                case B_TRANSLATOR_BITMAP:
                        return BitsTranslate(inSource, inInfo, ioExtension, 
outType,
                                outDestination);
-                               
+
                default:
                        return DerivedTranslate(inSource, inInfo, ioExtension, 
outType,
                                outDestination, -1);
@@ -677,6 +678,13 @@
 }
 
 
+status_t
+BaseTranslator::DerivedCanHandleImageSize(float width, float height) const
+{
+       return B_OK;
+}
+
+
 BView *
 BaseTranslator::NewConfigView(TranslatorSettings *settings)
 {

Modified: haiku/trunk/src/add-ons/translators/shared/BaseTranslator.h
===================================================================
--- haiku/trunk/src/add-ons/translators/shared/BaseTranslator.h 2010-01-19 
22:05:18 UTC (rev 35185)
+++ haiku/trunk/src/add-ons/translators/shared/BaseTranslator.h 2010-01-19 
22:52:09 UTC (rev 35186)
@@ -110,6 +110,8 @@
                const translator_info *inInfo, BMessage *ioExtension,
                uint32 outType, BPositionIO *outDestination, int32 baseType);
                
+       virtual status_t DerivedCanHandleImageSize(float width, float height) 
const;
+
        virtual BView *NewConfigView(TranslatorSettings *settings);
        
 


Other related posts:

  • » [haiku-commits] r35186 - in haiku/trunk/src/add-ons/translators: ico shared - host . haiku