#include <linux/module.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/autoconf.h>
#include <linux/vmalloc.h>
#include <asm/system.h>
#include <asm/byteorder.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/delay.h>
#include <asm/uaccess.h>
#include <asm/elphel/c313a.h>
#include <asm/elphel/exifa.h>
#include "fpgactrl.h"
#include "fpga_io.h"
#include "x3x3.h"
#include "framepars.h"
#include "quantization_tables.h"
Include dependency graph for quantization_tables.c:
Go to the source code of this file.
Defines | |
#define | D1I(x) x |
optional debug output | |
#define | D15(x) |
#define | MDF15(x) |
#define | D14(x) |
#define | MDF14(x) |
#define | MDF(x) |
#define | QTABLE_SIZE 64 |
#define | QTABLE_HEAD_CACHE 8 |
Functions | |
void | reset_qtables (void) |
force (re-)initilaization of quantization tables cache and FPGA qunatization table (in FPGA) when next used. | |
void | init_qtable_head_cache (void) |
initialization of quantization tables (direct - JPEG header ones) cache TODO: add init_qtable_head_cache to module initialization | |
int | get_qtable (int quality2, unsigned char *y_tab, unsigned char *c_tab) |
calculates a pair of direct (JPEG header) tables for the specified quality (2-bytes ) | |
void | init_qtable_fpga (void) |
initialization of quantization tables (reverse, for the FPGA) cache TODO: add init_qtable_fpga to module initialization | |
int | set_qtable_fpga (int quality2) |
Finds an already programmed FPGA page or calculates (an programms FPGA with) a new one. | |
Variables | |
static unsigned int | std_quant_tbls [2 *QTABLE_SIZE] |
static unsigned char | qtable_cache [QTABLE_SIZE *2 *QTABLE_HEAD_CACHE] |
static int | qtable_cache_values [QTABLE_HEAD_CACHE] |
quantization tables cache | |
static int | qtable_cache_next [QTABLE_HEAD_CACHE] |
quality values for the tables in cache | |
static int | qtable_cache_mre |
index of the next (not used longer than this) slot | |
static int | qtable_fpga_values [FPGA_NQTAB] |
index of most recently used slot | |
static int | qtable_fpga_next [FPGA_NQTAB] |
quality values for the tables in FPGA | |
static int | qtable_fpga_mre |
index of the next (not used longer than this) slot in FPGA quantization tables | |
static int | qtable_cache_initialized |
index of most recently used slot | |
static int | qtable_fpga_initialized |
#define D14 | ( | x | ) |
Definition at line 115 of file quantization_tables.c.
Referenced by get_qtable(), and set_qtable_fpga().
#define D15 | ( | x | ) |
#define MDF | ( | x | ) |
Definition at line 117 of file quantization_tables.c.
#define MDF14 | ( | x | ) |
Definition at line 116 of file quantization_tables.c.
Referenced by get_qtable(), init_qtable_fpga(), and set_qtable_fpga().
#define MDF15 | ( | x | ) |
Definition at line 114 of file quantization_tables.c.
Referenced by get_qtable(), and set_qtable_fpga().
#define QTABLE_HEAD_CACHE 8 |
Definition at line 122 of file quantization_tables.c.
Referenced by get_qtable(), and init_qtable_head_cache().
#define QTABLE_SIZE 64 |
Definition at line 121 of file quantization_tables.c.
Referenced by get_qtable(), and set_qtable_fpga().
int get_qtable | ( | int | quality2, | |
unsigned char * | y_tab, | |||
unsigned char * | c_tab | |||
) |
calculates a pair of direct (JPEG header) tables for the specified quality (2-bytes )
quality2 | single byte (standard) or a pair of bytes (see file header description) | |
y_tab | caller-provided pointer to a 64-byte Y (intensity) quantization table (NULL - don't copy) | |
c_tab | caller-provided pointer to a 64-byte C (color) quantization table (NULL - don't copy) |
look if such q value is already in cache
End of cache?
yes, re-use the LRE slot
no, hit or never used so far, and not the first - anyway use this slot
bypass this
this points to the old mre
this is now mre
is it a hit or a miss?
miss, calculate the table and save it to cache first
Safety limit on quality factor. Convert 0 to 1 to avoid zero divide.
The basic table is used as-is (scaling 100) for a quality of 50. Qualities 50..100 are converted to scaling percentage 200 - 2*Q; note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table to make all the table entries 1 (hence, minimum quantization loss). Qualities 1..50 are converted to scaling percentage 5000/Q.
limit the values to the valid range
now table pair is calculated and stored in cache
copy tables to the output
Definition at line 193 of file quantization_tables.c.
References D14, D1I, flags, init_qtable_head_cache(), local_irq_restore, local_irq_save, MDF14, MDF15, memcpy(), printk, qtable_cache, qtable_cache_initialized, qtable_cache_mre, qtable_cache_next, qtable_cache_values, QTABLE_HEAD_CACHE, QTABLE_SIZE, and std_quant_tbls.
Referenced by jpegheader_create(), and qtables_create().
void init_qtable_fpga | ( | void | ) |
initialization of quantization tables (reverse, for the FPGA) cache
TODO: add init_qtable_fpga to module initialization
needs to turn off IRQ
Definition at line 288 of file quantization_tables.c.
References D1I, flags, FPGA_NQTAB, local_irq_restore, local_irq_save, MDF14, printk, qtable_fpga_initialized, qtable_fpga_mre, qtable_fpga_next, and qtable_fpga_values.
Referenced by set_qtable_fpga().
void init_qtable_head_cache | ( | void | ) |
initialization of quantization tables (direct - JPEG header ones) cache
TODO: add init_qtable_head_cache to module initialization
needs to turn off IRQ
undefined
last value is invalid, but that's OK - it should not be used
Definition at line 171 of file quantization_tables.c.
References D1I, flags, local_irq_restore, local_irq_save, MDF, printk, qtable_cache_initialized, qtable_cache_mre, qtable_cache_next, qtable_cache_values, and QTABLE_HEAD_CACHE.
Referenced by get_qtable().
void reset_qtables | ( | void | ) |
force (re-)initilaization of quantization tables cache and FPGA qunatization table (in FPGA) when next used.
Definition at line 161 of file quantization_tables.c.
References qtable_cache_initialized, and qtable_fpga_initialized.
Referenced by image_acq_init().
int set_qtable_fpga | ( | int | quality2 | ) |
Finds an already programmed FPGA page or calculates (an programms FPGA with) a new one.
quality2 | single byte (standard) or a pair of bytes (see file header description) |
look if such q value is already in cache
NOTE: never
End of cache?
yes, re-use the LRE slot
NOTE: never
no, hit or never used so far, and not the latest - anyway use this slot
bypass this
this points to the old mre
this is now mre
NOTE: never
is it a hit or miss?
miss, calculate the table and send it to the FPGA
Safety limit on quality factor. Convert 0 to 1 to avoid zero divide.
The basic table is used as-is (scaling 100) for a quality of 50. Qualities 50..100 are converted to scaling percentage 200 - 2*Q; note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table to make all the table entries 1 (hence, minimum quantization loss). Qualities 1..50 are converted to scaling percentage 5000/Q.
limit the values to the valid range
now table pair is calculated and stored in cache
copy tables to the FPGA
Definition at line 307 of file quantization_tables.c.
References CX313_FPGA_TABLES_QUANT, D14, D15, D1I, flags, FPGA_NQTAB, fpga_table_write_nice(), init_qtable_fpga(), local_irq_restore, local_irq_save, MDF14, MDF15, printk, qtable_fpga_initialized, qtable_fpga_mre, qtable_fpga_next, qtable_fpga_values, QTABLE_SIZE, and std_quant_tbls.
Referenced by pgm_quality().
unsigned char qtable_cache[QTABLE_SIZE *2 *QTABLE_HEAD_CACHE] [static] |
with a number of programmed tables equal to PARS_FRAMES, and that "this" table is not needed it will always be possible to find an unused table slot LRU cache for JPEG headers
Definition at line 146 of file quantization_tables.c.
Referenced by get_qtable().
int qtable_cache_initialized [static] |
index of most recently used slot
Definition at line 155 of file quantization_tables.c.
Referenced by get_qtable(), init_qtable_head_cache(), and reset_qtables().
int qtable_cache_mre [static] |
index of the next (not used longer than this) slot
Definition at line 149 of file quantization_tables.c.
Referenced by get_qtable(), and init_qtable_head_cache().
int qtable_cache_next[QTABLE_HEAD_CACHE] [static] |
quality values for the tables in cache
Definition at line 148 of file quantization_tables.c.
Referenced by get_qtable(), and init_qtable_head_cache().
int qtable_cache_values[QTABLE_HEAD_CACHE] [static] |
quantization tables cache
Definition at line 147 of file quantization_tables.c.
Referenced by get_qtable(), and init_qtable_head_cache().
int qtable_fpga_initialized [static] |
Definition at line 156 of file quantization_tables.c.
Referenced by init_qtable_fpga(), reset_qtables(), and set_qtable_fpga().
int qtable_fpga_mre [static] |
index of the next (not used longer than this) slot in FPGA quantization tables
Definition at line 153 of file quantization_tables.c.
Referenced by init_qtable_fpga(), and set_qtable_fpga().
int qtable_fpga_next[FPGA_NQTAB] [static] |
quality values for the tables in FPGA
Definition at line 152 of file quantization_tables.c.
Referenced by init_qtable_fpga(), and set_qtable_fpga().
int qtable_fpga_values[FPGA_NQTAB] [static] |
index of most recently used slot
Definition at line 151 of file quantization_tables.c.
Referenced by init_qtable_fpga(), and set_qtable_fpga().
unsigned int std_quant_tbls[2 *QTABLE_SIZE] [static] |
Initial value:
{ 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62, 18, 22, 37, 56, 68, 109, 103, 77, 24, 35, 55, 64, 81, 104, 113, 92, 49, 64, 78, 87, 103, 121, 120, 101, 72, 92, 95, 98, 112, 100, 103, 99, 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 }
Definition at line 123 of file quantization_tables.c.
Referenced by get_qtable(), and set_qtable_fpga().