Thread: [KoCo-CVS] [Commit] cjkcodecs/src _shift_jisx0213.c
Brought to you by:
perky
From: Hye-Shik C. <pe...@us...> - 2003-07-08 09:23:22
|
perky 03/07/08 02:23:20 Added: src _shift_jisx0213.c Log: Add Shift-JISX0213 codec. Revision Changes Path 1.1 cjkcodecs/src/_shift_jisx0213.c Index: _shift_jisx0213.c =================================================================== /* * _shift_jisx0213.c: the SHIFT-JISX0213 codec * * Copyright (C) 2003 Hye-Shik Chang <pe...@Fr...>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * $Id: _shift_jisx0213.c,v 1.1 2003/07/08 09:23:20 perky Exp $ */ #define USING_BINARY_PAIR_SEARCH #include "codeccommon.h" #include "maps/alg_jisx0201.h" #include "maps/map_jisx0213_pairs.h" ENCMAP(jisxcommon) DECMAP(jisx0208) ENCMAP(jisx0213_bmp) DECMAP(jisx0213_1_bmp) DECMAP(jisx0213_2_bmp) ENCMAP(jisx0213_emp) DECMAP(jisx0213_1_emp) DECMAP(jisx0213_2_emp) #define EMPBASE 0x20000 ENCODER(shift_jisx0213) { while (inleft > 0) { ucs4_t c = **inbuf; DBCHAR code = NOCHAR; int c1, c2; size_t insize = 1; JISX0201_ENCODE(c, code) #if Py_UNICODE_SIZE == 2 else if (c >> 10 == 0xd800 >> 10) { /* high surrogate */ RESERVE_INBUF(2) if ((*inbuf)[1] >> 10 == 0xdc00 >> 10) { /* low surrogate */ c = 0x10000 + ((c - 0xd800) << 10) + ((ucs4_t)((*inbuf)[1]) - 0xdc00); insize = 2; } } #endif if (code < 0x80 || (code >= 0xa1 && code <= 0xdf)) { WRITE1(code) NEXT(1, 1) continue; } RESERVE_OUTBUF(2) if (code == NOCHAR) { if (c <= 0xffff) { TRYMAP_ENC(jisx0213_bmp, code, c) { if (code == MULTIC) { if (inleft < 2) { if (flags & MBENC_FLUSH) { code = find_pairencmap(c, 0, jisx0213_pairencmap, JISX0213_ENCPAIRS); if (code == DBCINV) return 1; } else return MBERR_TOOFEW; } else { code = find_pairencmap(c, IN2, jisx0213_pairencmap, JISX0213_ENCPAIRS); if (code == DBCINV) { code = find_pairencmap(c, 0, jisx0213_pairencmap, JISX0213_ENCPAIRS); if (code == DBCINV) return 1; } else insize = 2; } } } else TRYMAP_ENC(jisxcommon, code, c) { if (code & 0x8000) return 1; /* abandon JIS X 0212 codes */ } else return 1; } else if (c >> 16 == EMPBASE >> 16) { TRYMAP_ENC(jisx0213_emp, code, c & 0xffff); else return insize; } else return insize; } c1 = code >> 8; c2 = code & 0xff - 0x21; if (c1 & 0x80) { /* Plane 2 */ if (c1 >= 0xee) c1 -= 0x87; else if (c1 >= 0xac || c1 == 0xa8) c1 -= 0x49; else c1 -= 0x43; } else /* Plane 1 */ c1 -= 0x21; if (c1 & 1) c2 += 0x5e; c1 >>= 1; OUT1(c1 + (c1 < 0x1f ? 0x81 : 0xc1)) OUT2(c2 + (c2 < 0x3f ? 0x40 : 0x41)) NEXT(insize, 2) } return 0; } DECODER(shift_jisx0213) { while (inleft > 0) { unsigned char c = **inbuf; RESERVE_OUTBUF(1) JISX0201_DECODE(c, **outbuf) else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)) { unsigned char c1, c2; RESERVE_INBUF(2) c2 = (*inbuf)[1]; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) return 2; c1 = (c < 0xe0 ? c - 0x81 : c - 0xc1); c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); c1 = (2 * c1 + (c2 < 0x5e ? 0 : 1) + 0x21); c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21; TRYMAP_DEC(jisx0208, **outbuf, c1, c2) { NEXT(2, 1) continue; } else return 2; } else if (c >= 0xf0 && c <= 0xf9) { unsigned char c2; RESERVE_INBUF(2) c2 = (*inbuf)[1]; if ((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0x80 && c2 <= 0xfc)) { **outbuf = 0xe000 + 188 * (c - 0xf0) + (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); NEXT(2, 1) continue; } else return 2; } else return 2; NEXT(1, 1) /* JIS X 0201 */ } return 0; } #include "codecentry.h" BEGIN_CODEC_REGISTRY(shift_jisx0213) MAPOPEN(ja_JP) IMPORTMAP_DEC(jisx0208) IMPORTMAP_ENC(jisxcommon) IMPORTMAP_ENC(jisx0213_bmp) IMPORTMAP_DEC(jisx0213_1_bmp) IMPORTMAP_DEC(jisx0213_2_bmp) IMPORTMAP_ENC(jisx0213_emp) IMPORTMAP_DEC(jisx0213_1_emp) IMPORTMAP_DEC(jisx0213_2_emp) MAPCLOSE() END_CODEC_REGISTRY(shift_jisx0213) /* * ex: ts=8 sts=4 et */ |
From: Hye-Shik C. <pe...@us...> - 2003-07-08 17:14:27
|
perky 03/07/08 10:14:25 Modified: src _shift_jisx0213.c Log: Fix Shift-JISX0213 decoder to the real one. (was Shift-JIS's :) Revision Changes Path 1.2 +35 -24 cjkcodecs/src/_shift_jisx0213.c Index: _shift_jisx0213.c =================================================================== RCS file: /cvsroot/koco/cjkcodecs/src/_shift_jisx0213.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- _shift_jisx0213.c 8 Jul 2003 09:23:20 -0000 1.1 +++ _shift_jisx0213.c 8 Jul 2003 17:14:25 -0000 1.2 @@ -26,7 +26,7 @@ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - * $Id: _shift_jisx0213.c,v 1.1 2003/07/08 09:23:20 perky Exp $ + * $Id: _shift_jisx0213.c,v 1.2 2003/07/08 17:14:25 perky Exp $ */ #define USING_BINARY_PAIR_SEARCH @@ -109,7 +109,7 @@ } c1 = code >> 8; - c2 = code & 0xff - 0x21; + c2 = (code & 0xff) - 0x21; if (c1 & 0x80) { /* Plane 2 */ if (c1 >= 0xee) c1 -= 0x87; @@ -132,40 +132,51 @@ DECODER(shift_jisx0213) { while (inleft > 0) { - unsigned char c = **inbuf; + unsigned char c = IN1; RESERVE_OUTBUF(1) JISX0201_DECODE(c, **outbuf) - else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea)) { - unsigned char c1, c2; + else if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfc)) { + unsigned char c1, c2 = IN2; + ucs4_t code; RESERVE_INBUF(2) - c2 = (*inbuf)[1]; if (c2 < 0x40 || (c2 > 0x7e && c2 < 0x80) || c2 > 0xfc) return 2; c1 = (c < 0xe0 ? c - 0x81 : c - 0xc1); c2 = (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); - c1 = (2 * c1 + (c2 < 0x5e ? 0 : 1) + 0x21); + c1 = (2 * c1 + (c2 < 0x5e ? 0 : 1)); c2 = (c2 < 0x5e ? c2 : c2 - 0x5e) + 0x21; - TRYMAP_DEC(jisx0208, **outbuf, c1, c2) { - NEXT(2, 1) - continue; - } else - return 2; - } else if (c >= 0xf0 && c <= 0xf9) { - unsigned char c2; - - RESERVE_INBUF(2) - c2 = (*inbuf)[1]; - if ((c2 >= 0x40 && c2 <= 0x7e) || (c2 >= 0x80 && c2 <= 0xfc)) { - **outbuf = 0xe000 + 188 * (c - 0xf0) + - (c2 < 0x80 ? c2 - 0x40 : c2 - 0x41); - NEXT(2, 1) - continue; - } else - return 2; + if (c1 < 0x5e) { /* Plane 1 */ + c1 += 0x21; + TRYMAP_DEC(jisx0208, **outbuf, c1, c2) { + NEXT_OUT(1) + } else TRYMAP_DEC(jisx0213_1_bmp, **outbuf, c1, c2) { + NEXT_OUT(1) + } else TRYMAP_DEC(jisx0213_1_emp, code, c1, c2) { + PUTUCS4(EMPBASE | code) + } else TRYMAP_DEC(jisx0213_pair, code, c1, c2) { + WRITE2(code >> 16, code & 0xffff) + NEXT_OUT(2) + } else + return 2; + NEXT_IN(2) + } else { /* Plane 2 */ + if (c1 >= 0x67) c1 += 0x07; + else if (c1 >= 0x63 || c1 == 0x5f) c1 -= 0x37; + else c1 -= 0x3d; + + TRYMAP_DEC(jisx0213_2_bmp, **outbuf, c1, c2) { + NEXT_OUT(1) + } else TRYMAP_DEC(jisx0213_2_emp, code, c1, c2) { + PUTUCS4(EMPBASE | code) + } else + return 2; + NEXT_IN(2) + } + continue; } else return 2; |