/*$
mlk in apdtool
Copyright (c) 2020 Azel

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 MLK_IMAGECONV_H
#define MLK_IMAGECONV_H

typedef struct _mImageConv mImageConv;

typedef void (*mFuncImageConv)(mImageConv *);

struct _mImageConv
{
	void *dstbuf;
	const void *srcbuf;
	const uint8_t *palbuf;
	
	int srcbits,
		dstbits,
		convtype,
		chno;
	uint32_t width,
		flags;
};


enum MIMAGECONV_CONVTYPE
{
	MIMAGECONV_CONVTYPE_NONE = 0,
	MIMAGECONV_CONVTYPE_RGB,
	MIMAGECONV_CONVTYPE_RGBA
};

enum MIMAGECONV_FLAGS
{
	MIMAGECONV_FLAGS_REVERSE = 1<<0,
	MIMAGECONV_FLAGS_SRC_BGRA = 1<<1,
	MIMAGECONV_FLAGS_SRC_ALPHA = 1<<2,
	MIMAGECONV_FLAGS_INVALID_ALPHA = 1<<3
};


#ifdef __cplusplus
extern "C" {
#endif

void mImageConv_swap_rb_8(uint8_t *buf,uint32_t width,int bytes);

void mImageConv_rgb8_to_rgba8_extend(uint8_t *buf,uint32_t width);

void mImageConv_rgbx8_to_rgb8(uint8_t *dst,const uint8_t *src,uint32_t width);
void mImageConv_rgbx8_to_gray8(uint8_t *dst,const uint8_t *src,uint32_t width);
void mImageConv_rgbx8_to_gray1(uint8_t *dst,const uint8_t *src,uint32_t width);

void mImageConv_gray_1_2_4_8(mImageConv *p);
void mImageConv_gray16(mImageConv *p);
void mImageConv_palette_1_2_4_8(mImageConv *p);
void mImageConv_rgb555(mImageConv *p);
void mImageConv_rgb8(mImageConv *p);
void mImageConv_rgba8(mImageConv *p);
void mImageConv_rgb_rgba_16(mImageConv *p);
void mImageConv_cmyk16(mImageConv *p);

void mImageConv_sepch_gray_a_8(mImageConv *p);
void mImageConv_sepch_gray_a_16(mImageConv *p);
void mImageConv_sepch_rgb_rgba_8(mImageConv *p);
void mImageConv_sepch_rgb_rgba_16(mImageConv *p);
void mImageConv_sepch_cmyk8(mImageConv *p);
void mImageConv_sepch_cmyk16(mImageConv *p);

#ifdef __cplusplus
}
#endif

#endif
