diff options
author | fvogel <fvogelnew1@free.fr> | 2020-11-08 13:46:37 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2020-11-08 13:46:37 (GMT) |
commit | 14635cf721890ec922b5b34f333ac5ac93346c9c (patch) | |
tree | bba45650776ea6e5c3ba381bce5ecfebb20288f5 /win/tkWinIco.c | |
parent | b0a82cca7d1314476ae7fe568baa8e06358554a5 (diff) | |
download | tk-14635cf721890ec922b5b34f333ac5ac93346c9c.zip tk-14635cf721890ec922b5b34f333ac5ac93346c9c.tar.gz tk-14635cf721890ec922b5b34f333ac5ac93346c9c.tar.bz2 |
Remove duplicate code.
Diffstat (limited to 'win/tkWinIco.c')
-rw-r--r-- | win/tkWinIco.c | 64 |
1 files changed, 58 insertions, 6 deletions
diff --git a/win/tkWinIco.c b/win/tkWinIco.c index f23d619..039a680 100644 --- a/win/tkWinIco.c +++ b/win/tkWinIco.c @@ -13,7 +13,6 @@ #include "tkWinIco.h" - /* *---------------------------------------------------------------------- * @@ -54,7 +53,7 @@ DIBNumColors( return 0; } } - + /* *---------------------------------------------------------------------- * @@ -74,7 +73,7 @@ PaletteSize( { return (WORD) (DIBNumColors(lpbi) * sizeof(RGBQUAD)); } - + /* *---------------------------------------------------------------------- * @@ -98,7 +97,7 @@ FindDIBBits( { return lpbi + *((LPDWORD) lpbi) + PaletteSize(lpbi); } - + /* *---------------------------------------------------------------------- * @@ -120,8 +119,7 @@ BytesPerLine( { return WIDTHBYTES(lpBMIH->biWidth * lpBMIH->biPlanes * lpBMIH->biBitCount); } - - + /* *---------------------------------------------------------------------- * @@ -189,7 +187,61 @@ AdjustIconImagePointers( lpImage->Height*BytesPerLine((LPBITMAPINFOHEADER) lpImage->lpbi); return TRUE; } + +/* + *---------------------------------------------------------------------- + * + * ReadICOHeader -- + * + * Reads the header from an ICO file, as specfied by channel. + * + * Results: + * UINT - Number of images in file, -1 for failure. If this succeeds, + * there is a decent chance this is a valid icon file. + * + *---------------------------------------------------------------------- + */ + +static int +ReadICOHeader( + Tcl_Channel channel) +{ + union { + WORD word; + char bytes[sizeof(WORD)]; + } input; + /* + * Read the 'reserved' WORD, which should be a zero word. + */ + + if (Tcl_Read(channel, input.bytes, sizeof(WORD)) != sizeof(WORD)) { + return -1; + } + if (input.word != 0) { + return -1; + } + + /* + * Read the type WORD, which should be of type 1. + */ + + if (Tcl_Read(channel, input.bytes, sizeof(WORD)) != sizeof(WORD)) { + return -1; + } + if (input.word != 1) { + return -1; + } + + /* + * Get and return the count of images. + */ + + if (Tcl_Read(channel, input.bytes, sizeof(WORD)) != sizeof(WORD)) { + return -1; + } + return (int) input.word; +} /* * Local Variables: |