Copyright 2011 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package jpeg
This file implements a Forward Discrete Cosine Transformation.
It is based on the code in jfdctint.c from the Independent JPEG Group,found at http:www.ijg.org/files/jpegsrc.v8c.tar.gz.
The "LEGAL ISSUES" section of the README in that archive says:
In plain English:
1. We don't promise that this software works. (But if you find any bugs, please let us know!)2. You can use this software for whatever you want. You don't have to pay us.3. You may not pretend that you wrote this software. If you use it in a program, you must acknowledge somewhere in your documentation that you've used the IJG code.
In legalese:
The authors make NO WARRANTY or representation, either express or implied,with respect to this software, its quality, accuracy, merchantability, orfitness for a particular purpose. This software is provided "AS IS", and you,its user, assume the entire risk as to its quality and accuracy.
This software is copyright (C) 1991-2011, Thomas G. Lane, Guido Vollbeding.All Rights Reserved except as specified below.
Permission is hereby granted to use, copy, modify, and distribute thissoftware (or portions thereof) for any purpose, without fee, subject to theseconditions:(1) If any part of the source code for this software is distributed, then thisREADME file must be included, with this copyright and no-warranty noticeunaltered; and any additions, deletions, or changes to the original filesmust be clearly indicated in accompanying documentation.(2) If only executable code is distributed, then the accompanyingdocumentation must state that "this software is based in part on the work ofthe Independent JPEG Group".(3) Permission for use of this software is granted only if the user acceptsfull responsibility for any undesirable consequences; the authors acceptNO LIABILITY for damages of any kind.
These conditions apply to any software derived from or based on the IJG code,not just to the unmodified library. If you use our work, you ought toacknowledge us.
Permission is NOT granted for the use of any IJG author's name or company namein advertising or publicity relating to this software or products derived fromit. This software may be referred to only as "the Independent JPEG Group'ssoftware".
We specifically permit and encourage the use of this software as the basis ofcommercial products, provided that all warranty or liability claims areassumed by the product vendor.
Trigonometric constants in 13-bit fixed point format.
fdct performs a forward DCT on an 8x8 block of coefficients, including a level shift.
Pass 1: process rows.
	for  := 0;  < 8; ++ {
		 :=  * 8
		 := [ : +8 : +8] // Small cap improves performance, see https://golang.org/issue/27857
		 := [0]
		 := [1]
		 := [2]
		 := [3]
		 := [4]
		 := [5]
		 := [6]
		 := [7]

		 :=  + 
		 :=  + 
		 :=  + 
		 :=  + 

		 :=  + 
		 :=  - 
		 :=  + 
		 :=  - 

		 =  - 
		 =  - 
		 =  - 
		 =  - 

		[0] = ( +  - 8*centerJSample) << pass1Bits
		[4] = ( - ) << pass1Bits
		 := ( + ) * fix_0_541196100
		 += 1 << (constBits - pass1Bits - 1)
		[2] = ( + *fix_0_765366865) >> (constBits - pass1Bits)
		[6] = ( - *fix_1_847759065) >> (constBits - pass1Bits)

		 =  + 
		 =  + 
		 =  + 
		 =  + 
		 = ( + ) * fix_1_175875602
		 += 1 << (constBits - pass1Bits - 1)
		 *= fix_1_501321110
		 *= fix_3_072711026
		 *= fix_2_053119869
		 *= fix_0_298631336
		 *= -fix_0_899976223
		 *= -fix_2_562915447
		 *= -fix_0_390180644
		 *= -fix_1_961570560

		 += 
		 += 
		[1] = ( +  + ) >> (constBits - pass1Bits)
		[3] = ( +  + ) >> (constBits - pass1Bits)
		[5] = ( +  + ) >> (constBits - pass1Bits)
		[7] = ( +  + ) >> (constBits - pass1Bits)
Pass 2: process columns. We remove pass1Bits scaling, but leave results scaled up by an overall factor of 8.
	for  := 0;  < 8; ++ {
		 := [0*8+] + [7*8+]
		 := [1*8+] + [6*8+]
		 := [2*8+] + [5*8+]
		 := [3*8+] + [4*8+]

		 :=  +  + 1<<(pass1Bits-1)
		 :=  - 
		 :=  + 
		 :=  - 

		 = [0*8+] - [7*8+]
		 = [1*8+] - [6*8+]
		 = [2*8+] - [5*8+]
		 = [3*8+] - [4*8+]

		[0*8+] = ( + ) >> pass1Bits
		[4*8+] = ( - ) >> pass1Bits

		 := ( + ) * fix_0_541196100
		 += 1 << (constBits + pass1Bits - 1)
		[2*8+] = ( + *fix_0_765366865) >> (constBits + pass1Bits)
		[6*8+] = ( - *fix_1_847759065) >> (constBits + pass1Bits)

		 =  + 
		 =  + 
		 =  + 
		 =  + 
		 = ( + ) * fix_1_175875602
		 += 1 << (constBits + pass1Bits - 1)
		 *= fix_1_501321110
		 *= fix_3_072711026
		 *= fix_2_053119869
		 *= fix_0_298631336
		 *= -fix_0_899976223
		 *= -fix_2_562915447
		 *= -fix_0_390180644
		 *= -fix_1_961570560

		 += 
		 += 
		[1*8+] = ( +  + ) >> (constBits + pass1Bits)
		[3*8+] = ( +  + ) >> (constBits + pass1Bits)
		[5*8+] = ( +  + ) >> (constBits + pass1Bits)
		[7*8+] = ( +  + ) >> (constBits + pass1Bits)
	}