File: PRCBriCon.m

package info (click to toggle)
price.app 1.3.0-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 1,828 kB
  • sloc: objc: 8,414; ansic: 192; makefile: 18
file content (147 lines) | stat: -rw-r--r-- 3,725 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
//  PRCBriCon.m
//  PRICE
//
//  Created by Riccardo Mottola on Thu Mar 3 2005.
//  Copyright (c) 2005-2010 Carduus. All rights reserved.
//
// This application is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

// for values > 1
// the minimum is from 126 to 127: 1.008
// 125 to 127: 1.015
// the maximum is from 1 to 127: 127

#include <stdlib.h>

#import "PRCBriCon.h"
#import "PRBriCon.h"
#import "MyDocument.h"

#include <limits.h>

#define HALF_CHAR (UCHAR_MAX >> 1)

@implementation PRCBriCon

- (id)init
{
    if ((self = [super init]))
    {
        filter = [[PRBriCon alloc] init];
    }
    return self;
}

- (IBAction)showFilter:(id)sender
{
    [super showFilter:sender];

    if (!briconWindow)
        [NSBundle loadNibNamed:@"BriCon" owner:self];
    [briconWindow makeKeyAndOrderFront:nil];
    
    [self parametersChanged:self];
}


- (NSArray *)encodeParameters
{
    NSArray  *parameters;
    float    contrast;
    int      level;
    
    level = [conVal intValue];
    contrast = 1 + (float)abs(level)/HALF_CHAR;
    if (level < 0)
        contrast = 1 / contrast;
    
    /* encode parameters */
    parameters = [NSArray arrayWithObjects:
        [NSNumber numberWithInt:[briVal intValue]],
        [NSNumber numberWithFloat:contrast],
        nil];
    
    return parameters;
}

- (void)closeFilterPanel
{
    [briconWindow performClose:nil];
}

- (IBAction)briconReset:(id)sender
{
    [briSlider setIntValue:0];
    [briStep setIntValue:0];
    [briVal setIntValue:0];
    [conSlider setFloatValue:0.0];
    [conStep setFloatValue:0.0];
    [conVal setFloatValue:0.0];
    [self parametersChanged:sender];
}

- (IBAction)changeBri:(id)sender
{
    if (sender == briVal)
    {
        int tempVal;
        
        tempVal = [sender intValue];
        if (tempVal > 255)
        {
            tempVal = 255;
            [briVal setIntValue:tempVal];
        } else if (tempVal < -255)
        {
            tempVal = -255;
            [briVal setIntValue:tempVal];
        }
        [briSlider setIntValue:tempVal];
        [briStep setIntValue:tempVal];
    } else if (sender == briStep)
    {
        [briSlider setIntValue:[sender intValue]];
        [briVal setIntValue:[sender intValue]];
    } else if (sender == briSlider)
    {
        [briVal setIntValue:[sender intValue]];
        [briStep setIntValue:[sender intValue]];
    } else
        NSLog(@"undexpected sender value in changeBri");
    [self parametersChanged:sender];
}

- (IBAction)changeCon:(id)sender
{
    if (sender == conVal)
    {
        int tempVal;
        
        tempVal = [sender intValue];
        if (tempVal > 127)
        {
            tempVal = 127;
            [briVal setIntValue:tempVal];
        } else if (tempVal < -127)
        {
            tempVal = -127;
            [briVal setIntValue:tempVal];
        }
        [conSlider setIntValue:tempVal];
        [conStep setIntValue:tempVal];
    } else if (sender == conStep)
    {
        [conSlider setIntValue:[sender intValue]];
        [conVal setIntValue:[sender intValue]];
    } else if (sender == conSlider)
    {
        [conVal setIntValue:[sender intValue]];
        [conStep setIntValue:[sender intValue]];
    } else
        NSLog(@"undexpected sender value in changeCon");
    [self parametersChanged:sender];
}

@end