~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/common/tv_filters/atari_ntsc_impl.h

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2012-06-02 07:33:16 UTC
  • mfrom: (1.1.15)
  • Revision ID: package-import@ubuntu.com-20120602073316-20r4hr32t4oj36u9
Tags: 3.7-1
* New upstream version.
* Update description and documentation with new features in 3.7, notably
  Blargg TV filters (replacing the filters available in versions 3.4.1
  and earlier).
* Switch to debhelper compatibility level 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
// See the file "License.txt" for information on usage and redistribution of
15
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
16
//
17
 
// $Id: atari_ntsc_impl.h 2396 2012-02-26 20:11:59Z stephena $
 
17
// $Id: atari_ntsc_impl.h 2466 2012-05-10 15:36:20Z stephena $
18
18
//============================================================================
19
19
 
20
20
/* Based on nes_ntsc 0.2.2. http://www.slack.net/~ant/ */
24
24
#include <assert.h>
25
25
#include <math.h>
26
26
 
27
 
/* Copyright (C) 2006 Shay Green. This module is free software; you
 
27
/* Copyright (C) 2006-2009 Shay Green. This module is free software; you
28
28
can redistribute it and/or modify it under the terms of the GNU Lesser
29
29
General Public License as published by the Free Software Foundation; either
30
30
version 2.1 of the License, or (at your option) any later version. This
35
35
License along with this module; if not, write to the Free Software Foundation,
36
36
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
37
37
 
38
 
#define DISABLE_CORRECTION 0
 
38
#ifndef DISABLE_CORRECTION
 
39
  #define DISABLE_CORRECTION 0
 
40
#endif
39
41
 
40
42
#undef PI
41
43
#define PI 3.14159265358979323846f
211
213
  #endif
212
214
}
213
215
 
214
 
/* Atari change: more accurate values taken from
215
 
   http://en.wikipedia.org/wiki/YIQ */
216
216
static float const default_decoder [6] =
217
217
  { 0.9563f, 0.6210f, -0.2721f, -0.6474f, -1.1070f, 1.7046f };
218
218
 
220
220
{
221
221
  impl->brightness = (float) setup->brightness * (0.5f * rgb_unit) + rgb_offset;
222
222
  impl->contrast   = (float) setup->contrast   * (0.5f * rgb_unit) + rgb_unit;
223
 
  #ifdef default_palette_contrast
224
 
    if ( !setup->palette )
225
 
      impl->contrast *= default_palette_contrast;
226
 
  #endif
227
223
  
228
224
  impl->artifacts = (float) setup->artifacts;
229
225
  if ( impl->artifacts > 0 )
251
247
  
252
248
  /* setup decoder matricies */
253
249
  {
254
 
    /* Atari change:
255
 
       NTSC colorburst angle in YIQ colorspace. Colorburst is at
256
 
       180 degrees in YUV - that is, a gold color. In YIQ, gold is at
257
 
       different angle. However, YIQ is actually YUV turned
258
 
       33 degrees. So by looking at screenshots at Wikipedia we can
259
 
       conclude that the colorburst angle is 180+33 in YIQ.
260
 
       (See http://en.wikipedia.org/wiki/YUV and
261
 
       http://en.wikipedia.org/wiki/YIQ) */
262
 
    static float const colorburst_angle = (213.0f) * PI / 180.0f;
263
 
    float hue = (float) setup->hue * PI + PI / 180 * ext_decoder_hue - PI * setup->burst_phase - colorburst_angle;
 
250
    float hue = (float) setup->hue * PI + PI / 180 * ext_decoder_hue;
264
251
    float sat = (float) setup->saturation + 1;
265
252
    float const* decoder = setup->decoder_matrix;
266
253
    if ( !decoder )
300
287
 
301
288
/* kernel generation */
302
289
 
303
 
/* Atari change: more accurate values taken from
304
 
   http://en.wikipedia.org/wiki/YIQ */
305
290
#define RGB_TO_YIQ( r, g, b, y, i ) (\
306
291
  (y = (r) * 0.299f + (g) * 0.587f + (b) * 0.114f),\
307
292
  (i = (r) * 0.595716f - (g) * 0.274453f - (b) * 0.321263f),\
308
293
  ((r) * 0.211456f - (g) * 0.522591f + (b) * 0.311135f)\
309
294
)
310
 
 
311
295
#define YIQ_TO_RGB( y, i, q, to_rgb, type, r, g ) (\
312
296
  r = (type) (y + to_rgb [0] * i + to_rgb [1] * q),\
313
297
  g = (type) (y + to_rgb [2] * i + to_rgb [3] * q),\
314
298
  (type) (y + to_rgb [4] * i + to_rgb [5] * q)\
315
299
)
316
300
 
317
 
#define PACK_RGB( r, g, b ) ((r) << 21 | (g) << 11 | (b) << 1)
 
301
#ifndef PACK_RGB
 
302
  #define PACK_RGB( r, g, b ) ((r) << 21 | (g) << 11 | (b) << 1)
 
303
#endif
318
304
 
319
305
enum { rgb_kernel_size = burst_size / alignment_count };
320
306
enum { rgb_bias = rgb_unit * 2 * atari_ntsc_rgb_builder };
349
335
  /* generate for each scanline burst phase */
350
336
  float const* to_rgb = impl->to_rgb;
351
337
  int burst_remain = burst_count;
352
 
 
353
338
  y -= rgb_offset;
354
339
  do
355
340
  {
412
397
 
413
398
static void correct_errors( atari_ntsc_rgb_t color, atari_ntsc_rgb_t* out );
414
399
 
415
 
/* Atari change: adjust DISTRIBUTE_ERROR to 4/7 pixel ratio. */
416
400
#if DISABLE_CORRECTION
417
401
  #define CORRECT_ERROR( a ) { out [i] += rgb_bias; }
418
 
  #define DISTRIBUTE_ERROR( a, b, c, d ) { out [i] += rgb_bias; }
 
402
  #define DISTRIBUTE_ERROR( a, b, c ) { out [i] += rgb_bias; }
419
403
#else
420
404
  #define CORRECT_ERROR( a ) { out [a] += error; }
421
 
  #define DISTRIBUTE_ERROR( a, b, c, d ) {\
 
405
  #define DISTRIBUTE_ERROR( a, b, c ) {\
422
406
    atari_ntsc_rgb_t fourth = (error + 2 * atari_ntsc_rgb_builder) >> 2;\
423
407
    fourth &= (rgb_bias >> 1) - atari_ntsc_rgb_builder;\
424
408
    fourth -= rgb_bias >> 2;\
425
409
    out [a] += fourth;\
426
410
    out [b] += fourth;\
427
411
    out [c] += fourth;\
428
 
    out [d] += fourth;\
429
 
    out [i] += error - (fourth * 4);\
 
412
    out [i] += error - (fourth * 3);\
430
413
  }
431
414
#endif
432
415
 
452
435
    #define restrict
453
436
  #endif
454
437
#endif
455
 
 
456
 
#include <limits.h>
457
 
 
458
 
#if ATARI_NTSC_OUT_DEPTH <= 16
459
 
  #if USHRT_MAX == 0xFFFF
460
 
    typedef unsigned short atari_ntsc_out_t;
461
 
  #else
462
 
    #error "Need 16-bit int type"
463
 
  #endif
464
 
 
465
 
#else
466
 
  #if UINT_MAX == 0xFFFFFFFF
467
 
    typedef unsigned int  atari_ntsc_out_t;
468
 
  #elif ULONG_MAX == 0xFFFFFFFF
469
 
    typedef unsigned long atari_ntsc_out_t;
470
 
  #else
471
 
    #error "Need 32-bit int type"
472
 
  #endif
473
 
 
474
 
#endif