File: VDisplay.cc

package info (click to toggle)
vips 7.28.5-1%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 15,372 kB
  • sloc: ansic: 95,587; cpp: 50,751; sh: 11,548; python: 1,290; makefile: 916; perl: 40
file content (190 lines) | stat: -rw-r--r-- 3,680 bytes parent folder | download
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Object part of VDisplay class

/*

    Copyright (C) 1991-2001 The National Gallery

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser 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 Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 */

/*

    These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk

 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /*HAVE_CONFIG_H*/
#include <vips/intl.h>

#include <cstdlib>
#include <cstring>

#include <vips/vips.h>
#include <vips/internal.h>

#include <vips/vipscpp.h>

#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif /*WITH_DMALLOC*/

VIPS_NAMESPACE_START

/* Refcounting stuff first.
 */

// Free an im_col_display
static void
free_display( im_col_display *d )
{
	if( d->d_name )
		im_free( d->d_name );
	im_free( d );
}

// Dupe an im_col_display
static im_col_display *
dup_display( im_col_display *in ) throw( VError )
{
	im_col_display *out;

	if( !(out = IM_NEW( NULL, im_col_display )) )
		verror();

	*out = *in;
	if( in->d_name )
		if( !(out->d_name = strdup( in->d_name )) ) {
			free_display( out );
			verror( "out of memory" );
		}

	return( out );
}

// Remove lut
void VDisplay::refblock::cleanlut()
{
	if( luts ) {
		im_free( luts );
		luts = 0;
	}
}

// Remove attached things
void VDisplay::refblock::cleanref()
{
	if( disp && priv ) {
		free_display( disp );
		disp = 0;
		priv = 0;
	}
	cleanlut();
}

// Get ready to write to disp
void VDisplay::refblock::wready() throw( VError )
{
	cleanlut();
	if( !priv ) {
		disp = dup_display( disp );
		priv = 1;
	}
}

// Check that luts are up-to-date
void VDisplay::refblock::cluts() throw( VError )
{
	if( !luts )
		if( !(luts = im_col_make_tables_RGB( NULL, disp )) )
			verror();
}

VDisplay::~VDisplay()
{
	ref->nrefs--;
	if( !ref->nrefs ) 
		delete ref;
}

VDisplay &VDisplay::operator=( const VDisplay &a )
{ 
	ref->nrefs--;

	if( ref->nrefs > 0 ) 
		// Need fresh
		ref = new refblock;
	else 
		// Recycle old
		ref->cleanref();

	ref = a.ref; 
	ref->nrefs++; 
	
	return( *this ); 
}

VDisplay::VDisplay( const char *name ) throw( VError )
{
	// Search for a matching name in the VIPS colour list
        im_col_display *scr = im_col_display_name( name );
 
	if( !scr ) {
		VError err;

		err.app( "VDisplay error: " );
		err.app( "unknown display type \"" ).app( name ).app( "\"\n" );
		err.app( "display should be one of:" );

		for( int i = 0; (scr = im_col_displays( i )); i++ ) {
			err.app( " \"" );
			err.app( im_col_displays( i )->d_name );
			err.app( "\"" );
		}

		err.app( "\n" );

		throw( err );
	}

	// Install display
	ref = new refblock;
	ref->disp = scr;
}

VDisplay::VDisplay()
{
	// Just use sRGB
	ref = new refblock;
	ref->disp = im_col_displays( 7 );
}

/*

Setters and getters. We used to have a lot of code of the form:
 
float &VDisplay::YCW()
	{ ref->wready(); return( ((im_col_display*)ref->disp)->d_YCW ); }

This should be split to separate setters/getters so we can exploit const. Too 
annoying to do this on such a useless class (I'm certain no one used these 
functions anyway), fix in vips8.

 */

VIPS_NAMESPACE_END