[haiku-commits] Re: r34140 - haiku/trunk/src/apps/screenshot

  • From: Fredrik Modèen <fredrik@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 20 Nov 2009 10:45:30 +0100 (CET)

> Hi,
>
> On 2009-11-20 at 06:42:58 [+0100], Fredrik Modèen <fredrik@xxxxxxxxx>
> wrote:
>> > About the hard-coded fTranslator:
>> >
>> >> +    fRefsReceived(false),
>> >> +    fImageFileType(B_PNG_FORMAT),
>> >> +    fTranslator(8)
>> >>  {
>> >>  }
>> >>
>> >
>> > [...]
>> >
>> >> +void
>> >> +Screenshot::_SetImageTypeSilence(const char* name)
>> >> +{
>> >> +    if (strcmp(name, "bmp") == 0) {
>> >> +        fImageFileType = B_BMP_FORMAT;
>> >> +        fTranslator = 1;
>> >> +    } else if (strcmp(name, "gif") == 0) {
>> >> +        fImageFileType = B_GIF_FORMAT;
>> >> +        fTranslator = 3;
>> >> +    } else if (strcmp(name, "jpg") == 0) {
>> >> +        fImageFileType = B_JPEG_FORMAT;
>> >> +        fTranslator = 6;
>> >> +    } else if (strcmp(name, "ppm") == 0) {
>> >> +        fImageFileType = B_PPM_FORMAT;
>> >> +        fTranslator = 9;
>> >> +    } else if (strcmp(name, "targa") == 0) {
>> >> +        fImageFileType = B_TGA_FORMAT;
>> >> +        fTranslator = 14;
>> >> +    } else if (strcmp(name, "tif") == 0) {
>> >> +        fImageFileType = B_TIFF_FORMAT;
>> >> +        fTranslator = 15;
>> >> +    } else { //png
>> >> +        fImageFileType = B_PNG_FORMAT;
>> >> +        fTranslator = 8;
>> >> +    }
>> >> +}
>> >
>> > Can you elaborate on that? It looks a bit like you have hard-coded
>> > values that depend on the runtime configuration of currently installed
>> > translators.
>> Yes I have and if there are a better way please tell me :) I actually
>> had
>> int values (taken with a printf) instead of the define values like
>> B_PNG_FORMAT.
>
> The point is that it should work perfectly fine without fTranslator. From
> what I recall, this parameter lets you specify a specific translator. Like
> if you had two translators installed to handle B_PNG_FORMAT, you could
> tell
> the system which one of the two you want to use. If you ommit the
> parameter
> (like you should do in this case), the system will simply pick the best
> translator suitable to translate B_PNG_FORMAT in this example. So just
> remove everything related to fTranslator and it should be fine.
ok will do, thought it was needed as the original code used it.

If you look at BeBook says that GetOutputFormats needs translator_id
(fTranslator). Have I missed something?

>
> Best regards,
> -Stephan
>
>


-- 
MVH
Fredrik Modèen


Other related posts: