Changeset 1230d35


Ignore:
Timestamp:
04/17/15 12:32:41 (16 months ago)
Author:
ritsuka <damiog@…>
Branches:
master
Children:
db6ef00
Parents:
ee3b6d6
Message:

MacGui: use the new the filter preset/tune lookup and setting validation functions.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7089 b64f7644-9d1e-0410-96f1-a4d463321fa5

Location:
macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • macosx/HBFilters+UIAdditions.m

    rdf8b2ff r1230d35  
    66
    77#import "HBFilters+UIAdditions.h"
    8 
    9 extern NSDictionary *_HandBrake_denoiseTypesDict;
    10 extern NSDictionary *_HandBrake_denoisePresetsDict;
    11 extern NSDictionary *_HandBrake_nlmeansTunesDict;
     8#import "hb.h"
     9
     10/**
     11 *  Converts a hb_filter_param_t * array to a NSArray of NSString.
     12 *
     13 *  @param f a function which returns a hb_filter_param_t * array
     14 *
     15 *  @return a NSArray that contains the name field of hb_filter_param_t.
     16 */
     17static NSArray * filterParamsToNamesArray(hb_filter_param_t * (f)(int), int filter_id) {
     18    NSMutableArray *presets = [NSMutableArray array];
     19
     20    for (hb_filter_param_t *preset = f(filter_id); preset->name != NULL; preset++)
     21    {
     22        [presets addObject:@(preset->name)];
     23    }
     24
     25    return [presets copy];
     26}
     27
     28/**
     29 *  Converts a hb_filter_param_t * array to a NSDictionary, with name as the key and short_name as the value.
     30 *
     31 *  @param f a function which returns a hb_filter_param_t * array
     32 *
     33 *  @return a NSDictionary
     34 */
     35static NSDictionary * filterParamsToNamesDict(hb_filter_param_t * (f)(int), int filter_id) {
     36    NSMutableDictionary *presets = [NSMutableDictionary dictionary];
     37
     38    for (hb_filter_param_t *preset = f(filter_id); preset->name != NULL; preset++)
     39    {
     40        [presets setObject:NSLocalizedString(@(preset->short_name), nil) forKey:@(preset->name)];
     41    }
     42
     43    return [presets copy];
     44}
    1245
    1346@implementation HBGenericDictionaryTransformer
     
    99132+ (NSDictionary *)denoisePresetDict
    100133{
    101     return _HandBrake_denoisePresetsDict;
     134    return filterParamsToNamesDict(hb_filter_param_get_presets, HB_FILTER_NLMEANS);
    102135}
    103136
    104137+ (NSDictionary *)nlmeansTunesDict
    105138{
    106     return _HandBrake_nlmeansTunesDict;
     139    return filterParamsToNamesDict(hb_filter_param_get_tunes, HB_FILTER_NLMEANS);
    107140}
    108141
    109142+ (NSDictionary *)denoiseTypesDict
    110143{
    111     return _HandBrake_denoiseTypesDict;
     144    return @{NSLocalizedString(@"Off", nil):      @"off",
     145             NSLocalizedString(@"NLMeans", nil):  @"nlmeans",
     146             NSLocalizedString(@"HQDN3D", nil):   @"hqdn3d"};;
    112147}
    113148
    114149- (NSArray *)detelecineSettings
    115150{
    116     return @[@"Off", @"Custom", @"Default"];
     151    return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DETELECINE);
    117152}
    118153
    119154- (NSArray *)decombSettings
    120155{
    121     return @[@"Off", @"Custom", @"Default", @"Fast", @"Bob"];
     156    return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DECOMB);
    122157}
    123158
    124159- (NSArray *)deinterlaceSettings
    125160{
    126     return @[@"Off", @"Custom", @"Fast", @"Slow", @"Slower", @"Bob"];
     161    return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_DEINTERLACE);
    127162}
    128163
     
    134169- (NSArray *)denoisePresets
    135170{
    136     return @[@"Custom", @"Ultralight", @"Light", @"Medium", @"Strong"];
     171    return filterParamsToNamesArray(hb_filter_param_get_presets, HB_FILTER_NLMEANS);
    137172}
    138173
    139174- (NSArray *)denoiseTunes
    140175{
    141     return @[@"None", @"Film", @"Grain", @"High Motion", @"Animation"];
     176    return filterParamsToNamesArray(hb_filter_param_get_tunes, HB_FILTER_NLMEANS);
    142177}
    143178
     
    225260    if (![self.denoise isEqualToString:@"off"])
    226261    {
    227         [summary appendFormat:@" - Denoise (%@", [[_HandBrake_denoiseTypesDict allKeysForObject:self.denoise] firstObject]];
    228         if (![self.denoisePreset isEqualToString:@"none"])
    229         {
    230             [summary appendFormat:@", %@", [[_HandBrake_denoisePresetsDict allKeysForObject:self.denoisePreset] firstObject]];
     262        [summary appendFormat:@" - Denoise (%@", self.denoise];
     263        if (![self.denoisePreset isEqualToString:@"custom"])
     264        {
     265            [summary appendFormat:@", %@", self.denoisePreset];
    231266
    232267            if ([self.denoise isEqualToString:@"nlmeans"])
    233268            {
    234                 [summary appendFormat:@", %@", [[_HandBrake_nlmeansTunesDict allKeysForObject:self.denoiseTune] firstObject]];
     269                [summary appendFormat:@", %@", self.denoiseTune];
    235270            }
    236271        }
  • macosx/HBFilters.m

    rf360714 r1230d35  
    77#import "HBFilters.h"
    88#import "NSCodingMacro.h"
     9#include "hb.h"
    910
    1011NSString * const HBFiltersChangedNotification = @"HBFiltersChangedNotification";
    1112
    12 NSDictionary *_HandBrake_denoiseTypesDict;
    13 NSDictionary *_HandBrake_denoisePresetsDict;
    14 NSDictionary *_HandBrake_nlmeansTunesDict;
    15 
    1613@interface HBFilters ()
    1714
     
    2118
    2219@implementation HBFilters
    23 
    24 + (void)initialize
    25 {
    26     if (self == [HBFilters class])
    27     {
    28         _HandBrake_denoiseTypesDict = @{NSLocalizedString(@"Off", nil):      @"off",
    29                                NSLocalizedString(@"NLMeans", nil):  @"nlmeans",
    30                                NSLocalizedString(@"HQDN3D", nil):   @"hqdn3d"};
    31 
    32         _HandBrake_denoisePresetsDict = @{NSLocalizedString(@"Custom", nil):     @"none",
    33                                  NSLocalizedString(@"Ultralight", nil): @"ultralight",
    34                                  NSLocalizedString(@"Light", nil):      @"light",
    35                                  NSLocalizedString(@"Medium", nil) :    @"medium",
    36                                  NSLocalizedString(@"Strong", nil) :    @"strong"};
    37 
    38         _HandBrake_nlmeansTunesDict = @{NSLocalizedString(@"None", nil):         @"none",
    39                                NSLocalizedString(@"Film", nil):         @"film",
    40                                NSLocalizedString(@"Grain", nil):        @"grain",
    41                                NSLocalizedString(@"High Motion", nil):  @"highmotion",
    42                                NSLocalizedString(@"Animation", nil) :   @"animation"};
    43     }
    44 }
    4520
    4621- (instancetype)init
     
    424399        {
    425400            // New format, read the values directly
    426             if ([[_HandBrake_denoiseTypesDict allValues] containsObject:preset[@"PictureDenoiseFilter"]])
     401            if ([@[@"off", @"nlmeans", @"hqdn3d"] containsObject:preset[@"PictureDenoiseFilter"]])
    427402            {
    428403                self.denoise = preset[@"PictureDenoiseFilter"];
     
    430405            else
    431406            {
    432                 self.denoise = [[_HandBrake_denoiseTypesDict allValues] firstObject];
    433             }
    434 
    435             if ([[_HandBrake_denoisePresetsDict allValues] containsObject:preset[@"PictureDenoisePreset"]])
     407                self.denoise = @"off";
     408            }
     409
     410            if (hb_validate_filter_preset(HB_FILTER_DENOISE, [preset[@"PictureDenoisePreset"] UTF8String], [preset[@"PictureDenoiseTune"] UTF8String]))
    436411            {
    437412                self.denoisePreset = preset[@"PictureDenoisePreset"];
     413                self.denoiseTune = preset[@"PictureDenoiseTune"];
    438414            }
    439415            else
    440416            {
    441                 self.denoisePreset = [[_HandBrake_denoisePresetsDict allValues] firstObject];
    442             }
    443 
    444             if ([[_HandBrake_nlmeansTunesDict allValues] containsObject:preset[@"PictureDenoiseTune"]])
    445             {
    446                 self.denoiseTune = preset[@"PictureDenoiseTune"];
    447             }
    448             else
    449             {
    450                 self.denoiseTune = [[_HandBrake_nlmeansTunesDict allKeys] firstObject];
     417                self.denoisePreset = @"medium";
     418                self.denoiseTune = @"none";
    451419            }
    452420
  • macosx/HBJob+HBJobConversion.m

    rf4fae8f r1230d35  
    402402    // Detelecine
    403403    hb_filter_object_t *filter;
    404     if (self.filters.detelecine == 1)
    405     {
    406         filter = hb_filter_init(HB_FILTER_DETELECINE);
    407         // use a custom detelecine string
    408         hb_add_filter(job, filter, self.filters.detelecineCustomString.UTF8String);
    409     }
    410     else if (self.filters.detelecine == 2)
    411     {
    412         filter = hb_filter_init(HB_FILTER_DETELECINE);
    413         // Use libhb's default values
    414         hb_add_filter(job, filter, NULL);
     404    if (self.filters.detelecine)
     405    {
     406        int filter_id = HB_FILTER_DETELECINE;
     407        const char *filter_str = hb_generate_filter_settings_by_index(filter_id,
     408                                                                      (int)self.filters.detelecine,
     409                                                                      self.filters.detelecineCustomString.UTF8String);
     410        filter = hb_filter_init(filter_id);
     411        hb_add_filter(job, filter, filter_str);
    415412    }
    416413
     
    418415    {
    419416        // Decomb
    420         filter = hb_filter_init(HB_FILTER_DECOMB);
    421         if (self.filters.decomb == 1)
    422         {
    423             // use a custom decomb string */
    424             hb_add_filter(job, filter, self.filters.decombCustomString.UTF8String);
    425         }
    426         else if (self.filters.decomb == 2)
    427         {
    428             // use libhb defaults
    429             hb_add_filter(job, filter, NULL);
    430         }
    431         else if (self.filters.decomb == 3)
    432         {
    433             // use old defaults (decomb fast)
    434             hb_add_filter(job, filter, "7:2:6:9:1:80");
    435         }
    436         else if (self.filters.decomb == 4)
    437         {
    438             // decomb 3 with bobbing enabled
    439             hb_add_filter(job, filter, "455");
    440         }
     417        int filter_id = HB_FILTER_DECOMB;
     418        const char *filter_str = hb_generate_filter_settings_by_index(filter_id,
     419                                                                      (int)self.filters.decomb,
     420                                                                      self.filters.decombCustomString.UTF8String);
     421        filter = hb_filter_init(filter_id);
     422        hb_add_filter(job, filter, filter_str);
    441423    }
    442424    else if (!self.filters.useDecomb && self.filters.deinterlace)
    443425    {
    444426        // Deinterlace
    445         filter = hb_filter_init(HB_FILTER_DEINTERLACE);
    446         if (self.filters.deinterlace == 1)
    447         {
    448             // we add the custom string if present
    449             hb_add_filter(job, filter, self.filters.deinterlaceCustomString.UTF8String);
    450         }
    451         else if (self.filters.deinterlace == 2)
    452         {
    453             // Run old deinterlacer fd by default
    454             hb_add_filter(job, filter, "0");
    455         }
    456         else if (self.filters.deinterlace == 3)
    457         {
    458             // Yadif mode 0 (without spatial deinterlacing)
    459             hb_add_filter(job, filter, "1");
    460         }
    461         else if (self.filters.deinterlace == 4)
    462         {
    463             // Yadif (with spatial deinterlacing)
    464             hb_add_filter(job, filter, "3");
    465         }
    466         else if (self.filters.deinterlace == 5)
    467         {
    468             // Yadif (with spatial deinterlacing and bobbing)
    469             hb_add_filter(job, filter, "15");
    470         }
    471     }
     427        int filter_id = HB_FILTER_DEINTERLACE;
     428        const char *filter_str = hb_generate_filter_settings_by_index(filter_id,
     429                                                                      (int)self.filters.deinterlace,
     430                                                                      self.filters.deinterlaceCustomString.UTF8String);
     431        filter = hb_filter_init(filter_id);
     432        hb_add_filter(job, filter, filter_str);
     433    }
     434
    472435    // Denoise
    473436    if (![self.filters.denoise isEqualToString:@"off"])
     
    499462    // the macgui's purposes a value of 0 actually means to not even use the filter
    500463    // current hb_filter_deblock.settings valid ranges are from 5 - 15
    501     if (self.filters.deblock != 0)
     464    if (self.filters.deblock)
    502465    {
    503466        filter = hb_filter_init(HB_FILTER_DEBLOCK);
Note: See TracChangeset for help on using the changeset viewer.