device-epd/lib/jpec/enc.h
Thomas Ballmann 22e8b6df19 #19
- switch to canvas for print screen functionality
- implement jpg encoder for print screen
2020-10-01 21:31:17 +02:00

82 lines
3.0 KiB
C

/**
* Copyright (c) 2012-2016 Moodstocks SAS
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef JPEC_STREAM_H
#define JPEC_STREAM_H
#include <stdint.h>
#include "buf.h"
// header-----
typedef struct jpec_enc_t_ jpec_enc_t;
jpec_enc_t *jpec_enc_new(const uint8_t *img, uint16_t w, uint16_t h);
jpec_enc_t *jpec_enc_new2(const uint8_t *img, uint16_t w, uint16_t h, int q, jpec_enc_callback_t callback);
void jpec_enc_del(jpec_enc_t *e);
const uint8_t *jpec_enc_run(jpec_enc_t *e, int *len);
// header-----
/** Structure used to hold and process an image 8x8 block */
typedef struct jpec_block_t_ {
float dct[64]; /* DCT coefficients */
int quant[64]; /* Quantization coefficients */
int zz[64]; /* Zig-Zag coefficients */
int len; /* Length of Zig-Zag coefficients */
} jpec_block_t;
/** Skeleton for an Huffman entropy coder */
typedef struct jpec_huff_skel_t_ {
void *opq;
void (*del)(void *opq);
void (*encode_block)(void *opq, jpec_block_t *block, jpec_buffer_t *buf);
} jpec_huff_skel_t;
/** JPEG encoder */
struct jpec_enc_t_ {
/** Input image data */
const uint8_t *img; /* image buffer */
uint16_t w; /* image width */
uint16_t h; /* image height */
uint16_t w8; /* w rounded to upper multiple of 8 */
/** JPEG extensible byte buffer */
jpec_buffer_t *buf;
/** Compression parameters */
int qual; /* JPEG quality factor */
int dqt[64]; /* scaled quantization matrix */
/** Current 8x8 block */
int bmax; /* maximum number of blocks (N) */
int bnum; /* block number in 0..N-1 */
uint16_t bx; /* block start X */
uint16_t by; /* block start Y */
jpec_block_t block; /* block data */
/** Huffman entropy coder */
jpec_huff_skel_t *hskel;
};
#endif