| 1 | /* |
| 2 | * Mitsubishi Photo Printer Comon Code |
| 3 | * |
| 4 | * (c) 2013-2024 Solomon Peachy <[email protected]> |
| 5 | * |
| 6 | * The latest version of this program can be found at: |
| 7 | * |
| 8 | * https://git.shaftnet.org/gitea/slp/selphy_print.git |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the Free |
| 12 | * Software Foundation; either version 2 of the License, or (at your option) |
| 13 | * any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 17 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 18 | * for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, see <https://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | * SPDX-License-Identifier: GPL-2.0+ |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include "backend_common.h" |
| 28 | |
| 29 | //#include "lib70x/libMitsuD70ImageReProcess.h" |
| 30 | |
| 31 | /* If we don't have the libMitsu header */ |
| 32 | #ifndef LUT_LEN |
| 33 | #define COLORCONV_RGB 0 |
| 34 | #define COLORCONV_BGR 1 |
| 35 | |
| 36 | #define LUT_LEN 14739 |
| 37 | |
| 38 | struct BandImage { |
| 39 | void *imgbuf; // @ 0 |
| 40 | int32_t bytes_per_row;// @ 4 (respect 8bpp and 16bpp!) |
| 41 | uint16_t origin_cols; // @ 8 (left) |
| 42 | uint16_t origin_rows; // @12 (top) |
| 43 | uint16_t cols; // @16 (right) |
| 44 | uint16_t rows; // @20 (bottom) |
| 45 | // @24 |
| 46 | }; |
| 47 | |
| 48 | /* Forward declarations */ |
| 49 | struct mitsu98xx_data; |
| 50 | struct M1CPCData; |
| 51 | struct mitsu_cpd30_data; |
| 52 | #endif |
| 53 | |
| 54 | typedef void (*dump_announceFN)(FILE *fp); |
| 55 | typedef int (*lib70x_getapiversionFN)(void); |
| 56 | typedef int (*Get3DColorTableFN)(uint8_t *buf, const char *filename); |
| 57 | typedef struct CColorConv3D *(*Load3DColorTableFN)(const uint8_t *ptr); |
| 58 | typedef void (*Destroy3DColorTableFN)(struct CColorConv3D *this); |
| 59 | typedef void (*DoColorConvFN)(struct CColorConv3D *this, uint8_t *data, uint16_t cols, uint16_t rows, uint32_t bytes_per_row, int rgb_bgr); |
| 60 | typedef void (*DoColorConvPlaneFN)(struct CColorConv3D *this, uint8_t *data_r, uint8_t *data_g, uint8_t *data_b, uint32_t planelen); |
| 61 | typedef struct CPCData *(*get_CPCDataFN)(const char *filename); |
| 62 | typedef void (*destroy_CPCDataFN)(struct CPCData *data); |
| 63 | typedef int (*do_image_effectFN)(struct CPCData *cpc, struct CPCData *ecpc, struct BandImage *input, struct BandImage *output, int sharpen, int reverse, uint8_t rew[3]); |
| 64 | typedef int (*send_image_dataFN)(struct BandImage *out, void *context, |
| 65 | int (*callback_fn)(void *context, void *buffer, uint32_t len)); |
| 66 | |
| 67 | typedef int (*CP98xx_DoConvertFN)(const struct mitsu98xx_data *table, |
| 68 | const struct BandImage *input, |
| 69 | struct BandImage *output, |
| 70 | uint8_t type, int sharpness, int reversed); |
| 71 | typedef struct mitsu98xx_data *(*CP98xx_GetDataFN)(const char *filename); |
| 72 | typedef void (*CP98xx_DestroyDataFN)(const struct mitsu98xx_data *data); |
| 73 | |
| 74 | typedef struct M1CPCData *(*M1_GetCPCDataFN)(const char *corrtable_path, |
| 75 | const char *filename, |
| 76 | const char *gammafilename); |
| 77 | typedef void (*M1_DestroyCPCDataFN)(struct M1CPCData *dat); |
| 78 | typedef void (*M1_Gamma8to14FN)(const struct M1CPCData *cpc, |
| 79 | const struct BandImage *in, struct BandImage *out); |
| 80 | typedef int (*M1_CLocalEnhancerFN)(const struct M1CPCData *cpc, |
| 81 | int sharp, struct BandImage *img); |
| 82 | typedef int (*M1_CalcRGBRateFN)(uint16_t rows, uint16_t cols, uint8_t *data); |
| 83 | typedef uint8_t (*M1_CalcOpRateMatteFN)(uint16_t rows, uint16_t cols, const uint8_t *data); |
| 84 | typedef uint8_t (*M1_CalcOpRateGlossFN)(uint16_t rows, uint16_t cols); |
| 85 | |
| 86 | typedef struct mitsu_cpd30_data *(*CPD30_GetDataFN)(const char *filename); |
| 87 | typedef void (*CPD30_DestroyDataFN)(const struct mitsu_cpd30_data *data); |
| 88 | typedef int (*CPD30_DoConvertFN)(const struct mitsu_cpd30_data *table, |
| 89 | const struct BandImage *input, |
| 90 | struct BandImage *output, |
| 91 | uint8_t type, int sharpness); |
| 92 | |
| 93 | #ifndef WITH_DYNAMIC |
| 94 | #warning "No dynamic loading support!" |
| 95 | #endif |
| 96 | |
| 97 | #define REQUIRED_LIB_APIVERSION 10 |
| 98 | |
| 99 | #define LIBMITSU_VER "0.13" |
| 100 | |
| 101 | /* Image processing library function prototypes */ |
| 102 | #define LIB_NAME_RE "libMitsuD70ImageReProcess" DLL_SUFFIX |
| 103 | |
| 104 | struct mitsu_lib { |
| 105 | void *dl_handle; |
| 106 | lib70x_getapiversionFN GetAPIVersion; |
| 107 | dump_announceFN DumpAnnounce; |
| 108 | Get3DColorTableFN Get3DColorTable; |
| 109 | Load3DColorTableFN Load3DColorTable; |
| 110 | Destroy3DColorTableFN Destroy3DColorTable; |
| 111 | DoColorConvFN DoColorConv; |
| 112 | DoColorConvPlaneFN DoColorConvPlane; |
| 113 | get_CPCDataFN GetCPCData; |
| 114 | destroy_CPCDataFN DestroyCPCData; |
| 115 | do_image_effectFN DoImageEffect60; |
| 116 | do_image_effectFN DoImageEffect70; |
| 117 | do_image_effectFN DoImageEffect80; |
| 118 | do_image_effectFN DoImageEffect; |
| 119 | send_image_dataFN SendImageData; |
| 120 | CP98xx_DoConvertFN CP98xx_DoConvert; |
| 121 | CP98xx_GetDataFN CP98xx_GetData; |
| 122 | CP98xx_DestroyDataFN CP98xx_DestroyData; |
| 123 | M1_GetCPCDataFN M1_GetCPCData; |
| 124 | M1_DestroyCPCDataFN M1_DestroyCPCData; |
| 125 | M1_CLocalEnhancerFN M1_CLocalEnhancer; |
| 126 | M1_Gamma8to14FN M1_Gamma8to14; |
| 127 | M1_CalcRGBRateFN M1_CalcRGBRate; |
| 128 | M1_CalcOpRateGlossFN M1_CalcOpRateGloss; |
| 129 | M1_CalcOpRateMatteFN M1_CalcOpRateMatte; |
| 130 | CPD30_GetDataFN CPD30_GetData; |
| 131 | CPD30_DestroyDataFN CPD30_DestroyData; |
| 132 | CPD30_DoConvertFN CPD30_DoConvert; |
| 133 | struct CColorConv3D *lut; |
| 134 | struct CPCData *cpcdata; |
| 135 | struct CPCData *ecpcdata; |
| 136 | }; |
| 137 | |
| 138 | int mitsu_loadlib(struct mitsu_lib *lib, int type); |
| 139 | int mitsu_destroylib(struct mitsu_lib *lib); |
| 140 | int mitsu_apply3dlut_packed(struct mitsu_lib *lib, const char *lutfname, uint8_t *databuf, |
| 141 | uint16_t cols, uint16_t rows, uint16_t stride, |
| 142 | int rgb_bgr); |
| 143 | int mitsu_apply3dlut_plane(struct mitsu_lib *lib, const char *lutfname, |
| 144 | uint8_t *data_r, uint8_t *data_g, uint8_t *data_b, |
| 145 | uint16_t cols, uint16_t rows); |
| 146 | int mitsu_readlamdata(const char *fname, uint16_t lamstride, |
| 147 | uint8_t *databuf, uint32_t *datalen, |
| 148 | uint16_t rows, uint16_t cols, uint8_t bpp); |
| 149 | |
| 150 | #define TEMPERATURE_NORMAL 0x00 |
| 151 | #define TEMPERATURE_PREHEAT 0x40 |
| 152 | #define TEMPERATURE_COOLING 0x80 |
| 153 | |
| 154 | const char *mitsu_temperatures(uint8_t temp); |
| 155 | const char *mitsu_media_types(int printer, uint8_t brand, uint8_t type); |