├── .gitignore ├── Readme.md ├── include ├── data.h ├── dlist.h ├── error.h ├── font.h ├── graph.h ├── input.h ├── kuro.h ├── media.h ├── oimg_jpeg.h ├── rotozoom.h ├── scene.h ├── script.h ├── sprite.h ├── tar_reader.h ├── timer.h └── utils.h ├── screenshot ├── krs_S3.jpg └── kurologo.png ├── src ├── Makefile ├── data.c ├── dlist.c ├── error.c ├── font.c ├── graph.c ├── input.c ├── kuro.c ├── libjpeg │ ├── Makefile │ ├── jcomapi.c │ ├── jconfig.h │ ├── jdapimin.c │ ├── jdapistd.c │ ├── jdatasrc.c │ ├── jdcoefct.c │ ├── jdcolor.c │ ├── jdct.h │ ├── jddctmgr.c │ ├── jdhuff.c │ ├── jdhuff.h │ ├── jdinput.c │ ├── jdmainct.c │ ├── jdmarker.c │ ├── jdmaster.c │ ├── jdmerge.c │ ├── jdphuff.c │ ├── jdpostct.c │ ├── jdsample.c │ ├── jerror.c │ ├── jerror.h │ ├── jidctflt.c │ ├── jidctfst.c │ ├── jidctint.c │ ├── jidctred.c │ ├── jinclude.h │ ├── jmemansi.c │ ├── jmemmgr.c │ ├── jmemname.c │ ├── jmemnobs.c │ ├── jmemsys.h │ ├── jmorecfg.h │ ├── jpegint.h │ ├── jpeglib.h │ ├── jquant1.c │ ├── jquant2.c │ ├── jutils.c │ └── jversion.h ├── media.c ├── oimg_jpeg.c ├── rotozoom.c ├── scene_data.c ├── scene_select.c ├── scene_talk.c ├── scene_title.c ├── script.c ├── sprite.c ├── tar_reader.c ├── timer.c └── utils.c └── win32 ├── KuroScripter.dsp ├── KuroScripter.dsw ├── KuroScripter.ncb ├── KuroScripter.opt ├── KuroScripter.plg ├── res ├── krs_icon.png ├── krs_icon_win32.ico ├── resource.h └── resource.rc └── resource.aps /.gitignore: -------------------------------------------------------------------------------- 1 | tns/ 2 | win32/Debug/ 3 | win32/krs/ 4 | *.o 5 | *.tns 6 | *.doc 7 | *.a 8 | *.dll -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ![KuroScripter](./screenshot/kurologo.png) 2 | 3 | Nspire上的类ONS游戏引擎[KuroScripter](http://anderainlovelace.github.io/KuroScripterHome/) 4 | by Anderain Ryu (Hikari no Uiharu) 5 | - - - 6 | ###关于### 7 | KuroScripter是为Nspire系列计算器制作的文字类游戏引擎。 8 | 底层使用SDL实现,在ndless上使用了SDL的实现nSDL。 9 | 因为没有SDL Image的实现。在ndless SDK引用了libjpeg和SDL Image中的jpeg部分来读取jpeg。 10 | 11 | 因为素材大小的缘故,移植时基本需要处理全部素材,加之需要删减不需要的命令以减少图形效果,所以设计时就打算没有兼容ONS的脚本。 12 | 13 | 此为[项目介绍主页](http://anderainlovelace.github.io/KuroScripterHome/),含有移植游戏所需的脚本介绍。 14 | - - - 15 | ###效果图### 16 | *此为黑白机上Nspire Clickpad运行KRS的效果图* 17 | ![KuroScripter](./screenshot/krs_S3.jpg) 18 | - - - 19 | ###开源### 20 | 依照BSD liscence开源 -------------------------------------------------------------------------------- /include/data.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/include/data.h -------------------------------------------------------------------------------- /include/dlist.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/include/dlist.h -------------------------------------------------------------------------------- /include/error.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERROR_H_ 2 | #define _ERROR_H_ 3 | 4 | void Error_Exit(const char * format,...); 5 | 6 | #endif -------------------------------------------------------------------------------- /include/font.h: -------------------------------------------------------------------------------- 1 | #ifndef _FONT_H_ 2 | #define _FONT_H_ 3 | 4 | #define isChs(c) ((c) & 0x80) 5 | 6 | #define FONT_WIDTH 12 7 | #define FONT_HEIGHT 12 8 | 9 | void Font_DrawString (SDL_Surface * surface,int x,int y,const char * str,Uint32 color); 10 | void Font_DrawChar (SDL_Surface * surface,int x,int y,unsigned char c1,unsigned char c2,Uint32 color); 11 | void Font_Init (); 12 | void Font_Close (void); 13 | int Font_GetDrawWidth (const char *); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /include/graph.h: -------------------------------------------------------------------------------- 1 | #ifndef _GRAPH_H_ 2 | #define _GRAPH_H_ 3 | 4 | extern SDL_Surface * screen; 5 | 6 | #define DEF_TRANS 60 7 | 8 | #define SCR_WIDTH 320 9 | #define SCR_HEIGHT 240 10 | 11 | extern Uint32 COLOR_MASK,COLOR_BLACK,COLOR_WHITE; 12 | 13 | #define CRGB(r,g,b) (SDL_MapRGB(screen->format,r,g,b)) 14 | 15 | #ifdef ___NDLESS___ 16 | #define SCR_BPP (has_colors ? 16 : 8) 17 | #else 18 | #define SCR_BPP (16) 19 | #endif 20 | 21 | void Graph_Init (); 22 | void Graph_Quit (void); 23 | void Graph_Clear (); 24 | void Graph_Flip (); 25 | void Graph_ApplySurfaceTo (int x, int y, SDL_Surface * src,SDL_Surface * dest); 26 | void Graph_SetPixel (SDL_Surface *surface, int x, int y, Uint32 pixel); 27 | void Graph_WriteGraph (SDL_Surface * surface,int x,int y,int w,int h,unsigned char * pimage,Uint32 color); 28 | 29 | void Graph_Freeze (); 30 | void Graph_Shock (int frames); 31 | void Graph_Transition (int frames,void (*redraw)(void)); 32 | 33 | void Graph_ScreenSave (); 34 | void Graph_ScreenRestore (); 35 | 36 | #endif -------------------------------------------------------------------------------- /include/input.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/include/input.h -------------------------------------------------------------------------------- /include/kuro.h: -------------------------------------------------------------------------------- 1 | #ifndef _KURO_H_ 2 | #define _KURO_H_ 3 | 4 | #ifndef WIN32 5 | #define ___NDLESS___ 6 | #endif 7 | 8 | 9 | #ifdef ___NDLESS___ 10 | #include "os.h" 11 | #endif 12 | 13 | #include "SDL/SDL_config.h" 14 | #include "SDL/SDL.h" 15 | #include "stdio.h" 16 | #include "stdlib.h" 17 | #include "string.h" 18 | #include "ctype.h" 19 | #include "setjmp.h" 20 | 21 | #define TRUE 1 22 | #define FALSE 0 23 | #define BOOL int 24 | #define real double 25 | 26 | #define strEq(s1,s2) (strcmp(s1,s2)==0) 27 | 28 | #ifndef ___NDLESS___ 29 | 30 | #define FONT_FILE "krs/hzk12.hzk" 31 | #define MEDIA_FILE "krs/game.krp" 32 | #define CONFIG_FILE "krs/config.krs" 33 | #define SAVE_FILE_PATH "krs/save/" 34 | #define SAVE_FILE_EXT ".krd" 35 | #define MEDIA_PATH "krs/media/" 36 | #define ESCAPE_IMAGE "krs/escape.jpg" 37 | 38 | #else 39 | 40 | #define MEDIA_FILE "/documents/krs/game.krp.tns" 41 | #define FONT_FILE "/documents/krs/hzk12.hzk.tns" 42 | #define CONFIG_FILE "/documents/krs/config.krs.tns" 43 | #define SAVE_FILE_PATH "/documents/krs/save/" 44 | #define ESCAPE_IMAGE "/documents/krs/escape.jpg.tns" 45 | #define MEDIA_PATH "/documents/krs/media/" 46 | 47 | #define SAVE_FILE_EXT ".krd.tns" 48 | #endif 49 | 50 | #define GAME_CONFIG_FILE "config.krs" 51 | 52 | #endif -------------------------------------------------------------------------------- /include/media.h: -------------------------------------------------------------------------------- 1 | #ifndef _MEDIA_H_ 2 | #define _MEDIA_H_ 3 | 4 | #include "kuro.h" 5 | #include "graph.h" 6 | #include "media.h" 7 | #include "tar_reader.h" 8 | #include "error.h" 9 | 10 | 11 | void Media_Init (const char * fileName); 12 | SDL_Surface * Media_LoadImage (const char * fileName); 13 | char * Media_LoadText (const char * fileName); 14 | void Media_Close (void); 15 | SDL_Surface * Media_LoadImageAbs (const char * filePath); 16 | 17 | #endif -------------------------------------------------------------------------------- /include/oimg_jpeg.h: -------------------------------------------------------------------------------- 1 | #ifndef _OIMG_JPEG_ 2 | #define _OIMG_JPEG_ 3 | 4 | int OIMG_InitJPG(); 5 | void OIMG_QuitJPG(); 6 | 7 | #include "kuro.h" 8 | 9 | #ifdef ___NDLESS___ 10 | 11 | #include "SDL/SDL.h" 12 | #include "SDL/SDL_version.h" 13 | #include "SDL/begin_code.h" 14 | 15 | extern DECLSPEC int SDLCALL OIMG_isJPG(SDL_RWops *src); 16 | extern DECLSPEC SDL_Surface * SDLCALL OIMG_LoadJPG_RW(SDL_RWops *src); 17 | 18 | #define OIMG_SetError SDL_SetError 19 | #define OIMG_GetError SDL_GetError 20 | 21 | #include "SDL/close_code.h" 22 | 23 | #else 24 | 25 | 26 | #include "SDL_image.h" 27 | #define OIMG_LoadJPG_RW IMG_LoadJPG_RW 28 | #define OIMG_isJPG IMG_isJPG 29 | 30 | #endif /* __NDLESS__ */ 31 | 32 | #endif /* _OIMG_JPEG_ */ 33 | -------------------------------------------------------------------------------- /include/rotozoom.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | SDL_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces 4 | 5 | Copyright (C) 2001-2012 Andreas Schiffler 6 | 7 | This software is provided 'as-is', without any express or implied 8 | warranty. In no event will the authors be held liable for any damages 9 | arising from the use of this software. 10 | 11 | Permission is granted to anyone to use this software for any purpose, 12 | including commercial applications, and to alter it and redistribute it 13 | freely, subject to the following restrictions: 14 | 15 | 1. The origin of this software must not be misrepresented; you must not 16 | claim that you wrote the original software. If you use this software 17 | in a product, an acknowledgment in the product documentation would be 18 | appreciated but is not required. 19 | 20 | 2. Altered source versions must be plainly marked as such, and must not be 21 | misrepresented as being the original software. 22 | 23 | 3. This notice may not be removed or altered from any source 24 | distribution. 25 | 26 | Andreas Schiffler -- aschiffler at ferzkopp dot net 27 | 28 | */ 29 | 30 | #ifndef _SDL_rotozoom_h 31 | #define _SDL_rotozoom_h 32 | 33 | #include 34 | 35 | /* Set up for C function definitions, even when using C++ */ 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #ifndef M_PI 41 | #define M_PI 3.141592654 42 | #endif 43 | 44 | #include "SDL/SDL.h" 45 | 46 | /* ---- Defines */ 47 | 48 | /*! 49 | \brief Disable anti-aliasing (no smoothing). 50 | */ 51 | #define SMOOTHING_OFF 0 52 | 53 | /*! 54 | \brief Enable anti-aliasing (smoothing). 55 | */ 56 | #define SMOOTHING_ON 1 57 | 58 | /* ---- Function Prototypes */ 59 | 60 | #ifdef _MSC_VER 61 | # if defined(DLL_EXPORT) && !defined(LIBSDL_GFX_DLL_IMPORT) 62 | # define SDL_ROTOZOOM_SCOPE __declspec(dllexport) 63 | # else 64 | # ifdef LIBSDL_GFX_DLL_IMPORT 65 | # define SDL_ROTOZOOM_SCOPE __declspec(dllimport) 66 | # endif 67 | # endif 68 | #endif 69 | #ifndef SDL_ROTOZOOM_SCOPE 70 | # define SDL_ROTOZOOM_SCOPE extern 71 | #endif 72 | 73 | /* 74 | 75 | Rotozoom functions 76 | 77 | */ 78 | 79 | SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth); 80 | 81 | SDL_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY 82 | (SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth); 83 | 84 | 85 | SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, 86 | int *dstheight); 87 | 88 | SDL_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY 89 | (int width, int height, double angle, double zoomx, double zoomy, 90 | int *dstwidth, int *dstheight); 91 | 92 | /* 93 | 94 | Zooming functions 95 | 96 | */ 97 | 98 | SDL_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth); 99 | 100 | SDL_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight); 101 | 102 | /* 103 | 104 | Shrinking functions 105 | 106 | */ 107 | 108 | SDL_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory); 109 | 110 | /* 111 | 112 | Specialized rotation functions 113 | 114 | */ 115 | 116 | SDL_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns); 117 | 118 | /* Ends C function definitions when using C++ */ 119 | #ifdef __cplusplus 120 | } 121 | #endif 122 | 123 | #endif /* _SDL_rotozoom_h */ 124 | -------------------------------------------------------------------------------- /include/scene.h: -------------------------------------------------------------------------------- 1 | #ifndef _SCENE_H_ 2 | #define _SCENE_H_ 3 | 4 | void Scene_Select (BOOL); 5 | int Scene_Title (int); 6 | void Scene_Talk (); 7 | const char * Scene_Data (int type); 8 | 9 | #define SCENE_SAVE 0 10 | #define SCENE_LOAD 1 11 | 12 | #endif -------------------------------------------------------------------------------- /include/script.h: -------------------------------------------------------------------------------- 1 | #ifndef _SCRIPT_H_ 2 | #define _SCRIPT_H_ 3 | 4 | #include "dlist.h" 5 | 6 | #define LABEL_MAX 32 7 | 8 | typedef struct { 9 | char name[LABEL_MAX]; 10 | unsigned long offset; 11 | } 12 | Label; 13 | 14 | extern DList * listLabel; 15 | 16 | #define TOKEN_MAX 512 17 | 18 | void Script_Set (const char * source); 19 | void Script_GetToken (); 20 | void Script_LoadGlobalConfig (); 21 | void Script_LoadGameConfig (); 22 | void Script_FreeConfig (); 23 | void Script_AddLabel (const char * name,unsigned long offset); 24 | void Script_GotoLabel (const char * name); 25 | 26 | unsigned long Script_GetScriptOffset(); 27 | void Script_SetScriptOffset (unsigned long offset); 28 | 29 | #define FILE_END_FLAG '!' 30 | #define NIL_FLAG "~" 31 | #define SCRIPT_END() (token[0] == FILE_END_FLAG) 32 | #define TOKEN_EMPTY() (token[0] == '\0') 33 | #define TOKEN_IS(s) (strEq(token,s)) 34 | 35 | extern char token[]; 36 | 37 | typedef struct { 38 | BOOL debug; 39 | int textX; 40 | int textY; 41 | int nameX; 42 | int lineMax; 43 | int fps; 44 | int titleTextX; 45 | int titleTextY; 46 | int titleTextSpW; 47 | int titleTextSpH; 48 | } 49 | Configure; 50 | 51 | extern Configure config; 52 | 53 | #endif -------------------------------------------------------------------------------- /include/sprite.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPRITE_H_ 2 | #define _SPRITE_H_ 3 | 4 | typedef struct { 5 | int x; 6 | int y; 7 | real zoomX; 8 | real zoomY; 9 | int angle; 10 | BOOL visible; 11 | SDL_Surface* surface; 12 | } 13 | Sprite; 14 | 15 | Sprite * Sprite_Create (); 16 | Sprite * Sprite_LoadImage (const char * fileName); 17 | Sprite * Sprite_CreateBySurface (SDL_Surface * surface); 18 | void Sprite_Free (Sprite * sprite,BOOL disposeSurface); 19 | void Sprite_Apply (const Sprite * sprite); 20 | 21 | #endif -------------------------------------------------------------------------------- /include/tar_reader.h: -------------------------------------------------------------------------------- 1 | #ifndef _TAR_READER_H_ 2 | #define _TAR_READER_H_ 3 | 4 | #include "stdio.h" 5 | 6 | #define TAR_SUCCESS 0 7 | #define TAR_CANNOTOPENTAR 1 8 | #define TAR_FILENOTFOUND 2 9 | 10 | #define TAR_FILE FILE 11 | #define Tar_Open(fileName) (fopen(fileName,"rb")) 12 | #define Tar_Close fclose 13 | 14 | void * Tar_GetInTarFile (TAR_FILE * file,const char * fileName,size_t * pSize,int * result); 15 | 16 | #endif -------------------------------------------------------------------------------- /include/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIMER_H_ 2 | #define _TIMER_H_ 3 | 4 | void RFPS_Start(); 5 | void RFPS_End(); 6 | 7 | #endif -------------------------------------------------------------------------------- /include/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_H_ 2 | #define _UTILS_H_ 3 | 4 | double myatof(const char* sptr); 5 | char * mystrdup(const char * src); 6 | 7 | #ifdef ___NDLESS___ 8 | 9 | void ContrastInc (); 10 | void ContrastDec (); 11 | 12 | #endif 13 | 14 | #endif -------------------------------------------------------------------------------- /screenshot/krs_S3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/screenshot/krs_S3.jpg -------------------------------------------------------------------------------- /screenshot/kurologo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/screenshot/kurologo.png -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------- 2 | # KuroScripter Makefile 3 | #--------------------------------- 4 | # by Hikari no Uiharu 5 | # for Ndless SDK 6 | #--------------------------------- 7 | DEBUG = FALSE 8 | GCC = gcc 9 | AS = as 10 | GXX = g++ 11 | LD = ld-bflt 12 | GCCFLAGS = -Wall -W -marm -I../include 13 | 14 | LIB = libjpeg/jdmarker.o libjpeg/jidctred.o libjpeg/jdmaster.o libjpeg/jmemmgr.o libjpeg/jdmerge.o libjpeg/jmemnobs.o libjpeg/jdphuff.o libjpeg/jquant1.o libjpeg/jdapimin.o libjpeg/jdpostct.o libjpeg/jquant2.o libjpeg/jdapistd.o libjpeg/jdsample.o libjpeg/jutils.o libjpeg/jdatasrc.o libjpeg/jerror.o libjpeg/jdcoefct.o libjpeg/jdcolor.o libjpeg/jddctmgr.o libjpeg/jdhuff.o libjpeg/jidctflt.o libjpeg/jcomapi.o libjpeg/jdinput.o libjpeg/jidctfst.o libjpeg/jdmainct.o libjpeg/jidctint.o \ 15 | -lndls 16 | 17 | LDFLAGS = $(LIB) -s 18 | 19 | ifeq ($(DEBUG),FALSE) 20 | GCCFLAGS += -Os 21 | else 22 | GCCFLAGS += -O0 -g 23 | LDFLAGS += --debug 24 | endif 25 | 26 | OBJS = error.o kuro.o scene_title.o timer.o \ 27 | font.o scene_data.o script.o scene_select.o \ 28 | data.o graph.o media.o sprite.o \ 29 | dlist.o input.o oimg_jpeg.o scene_talk.o \ 30 | tar_reader.o utils.o 31 | 32 | ifneq ($(strip $(CPPOBJS)),) 33 | LDFLAGS += --cpp 34 | endif 35 | 36 | EXE = KuroScripter.tns 37 | DISTDIR = . 38 | 39 | vpath %.tns $(DISTDIR) 40 | 41 | all: $(EXE) 42 | 43 | %.o: %.c 44 | $(GCC) $(GCCFLAGS) -c $< 45 | 46 | %.o: %.cpp 47 | $(GXX) $(GCCFLAGS) -c $< 48 | 49 | %.o: %.S 50 | $(AS) -c $< 51 | 52 | $(EXE): $(OBJS) 53 | mkdir -p $(DISTDIR) 54 | $(LD) $^ -o $(DISTDIR)/$@ $(LDFLAGS) 55 | 56 | ifeq ($(DEBUG),FALSE) 57 | @rm -f $(DISTDIR)/*.gdb 58 | endif 59 | 60 | clean: 61 | rm -f *.o *.elf $(DISTDIR)/*.gdb $(DISTDIR)/$(EXE) 62 | -------------------------------------------------------------------------------- /src/data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/data.c -------------------------------------------------------------------------------- /src/dlist.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/dlist.c -------------------------------------------------------------------------------- /src/error.c: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file error.c 3 | * 4 | * @brief 错误处理 5 | * @author hikari 6 | * @date 2014-5-11 7 | */ 8 | #ifdef WIN32 9 | #include "windows.h" 10 | #endif 11 | 12 | #include "kuro.h" 13 | #include "stdarg.h" 14 | #include "error.h" 15 | 16 | void Error_Exit(const char * format,...) 17 | { 18 | char buf[512]; 19 | va_list arg_list; 20 | 21 | va_start (arg_list,format); 22 | vsprintf ((char*)buf,(char*)format,arg_list); 23 | va_end (arg_list); 24 | 25 | #ifdef ___NDLESS___ 26 | puts(buf); 27 | #else 28 | #ifdef WIN32 29 | MessageBox(NULL,buf,"ERROR!",MB_OK); 30 | #else 31 | puts("ERROR:"); 32 | puts(buf); 33 | #endif 34 | #endif 35 | exit(0); 36 | } 37 | -------------------------------------------------------------------------------- /src/font.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/font.c -------------------------------------------------------------------------------- /src/graph.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/graph.c -------------------------------------------------------------------------------- /src/input.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/input.c -------------------------------------------------------------------------------- /src/kuro.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/kuro.c -------------------------------------------------------------------------------- /src/libjpeg/jcomapi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jcomapi.c 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains application interface routines that are used for both 9 | * compression and decompression. 10 | */ 11 | 12 | #define JPEG_INTERNALS 13 | #include "jinclude.h" 14 | #include "jpeglib.h" 15 | 16 | 17 | /* 18 | * Abort processing of a JPEG compression or decompression operation, 19 | * but don't destroy the object itself. 20 | * 21 | * For this, we merely clean up all the nonpermanent memory pools. 22 | * Note that temp files (virtual arrays) are not allowed to belong to 23 | * the permanent pool, so we will be able to close all temp files here. 24 | * Closing a data source or destination, if necessary, is the application's 25 | * responsibility. 26 | */ 27 | 28 | GLOBAL(void) 29 | jpeg_abort (j_common_ptr cinfo) 30 | { 31 | int pool; 32 | 33 | /* Do nothing if called on a not-initialized or destroyed JPEG object. */ 34 | if (cinfo->mem == NULL) 35 | return; 36 | 37 | /* Releasing pools in reverse order might help avoid fragmentation 38 | * with some (brain-damaged) malloc libraries. 39 | */ 40 | for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) { 41 | (*cinfo->mem->free_pool) (cinfo, pool); 42 | } 43 | 44 | /* Reset overall state for possible reuse of object */ 45 | if (cinfo->is_decompressor) { 46 | cinfo->global_state = DSTATE_START; 47 | /* Try to keep application from accessing now-deleted marker list. 48 | * A bit kludgy to do it here, but this is the most central place. 49 | */ 50 | ((j_decompress_ptr) cinfo)->marker_list = NULL; 51 | } else { 52 | cinfo->global_state = CSTATE_START; 53 | } 54 | } 55 | 56 | 57 | /* 58 | * Destruction of a JPEG object. 59 | * 60 | * Everything gets deallocated except the master jpeg_compress_struct itself 61 | * and the error manager struct. Both of these are supplied by the application 62 | * and must be freed, if necessary, by the application. (Often they are on 63 | * the stack and so don't need to be freed anyway.) 64 | * Closing a data source or destination, if necessary, is the application's 65 | * responsibility. 66 | */ 67 | 68 | GLOBAL(void) 69 | jpeg_destroy (j_common_ptr cinfo) 70 | { 71 | /* We need only tell the memory manager to release everything. */ 72 | /* NB: mem pointer is NULL if memory mgr failed to initialize. */ 73 | if (cinfo->mem != NULL) 74 | (*cinfo->mem->self_destruct) (cinfo); 75 | cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */ 76 | cinfo->global_state = 0; /* mark it destroyed */ 77 | } 78 | 79 | 80 | /* 81 | * Convenience routines for allocating quantization and Huffman tables. 82 | * (Would jutils.c be a more reasonable place to put these?) 83 | */ 84 | 85 | GLOBAL(JQUANT_TBL *) 86 | jpeg_alloc_quant_table (j_common_ptr cinfo) 87 | { 88 | JQUANT_TBL *tbl; 89 | 90 | tbl = (JQUANT_TBL *) 91 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL)); 92 | tbl->sent_table = FALSE; /* make sure this is false in any new table */ 93 | return tbl; 94 | } 95 | 96 | 97 | GLOBAL(JHUFF_TBL *) 98 | jpeg_alloc_huff_table (j_common_ptr cinfo) 99 | { 100 | JHUFF_TBL *tbl; 101 | 102 | tbl = (JHUFF_TBL *) 103 | (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL)); 104 | tbl->sent_table = FALSE; /* make sure this is false in any new table */ 105 | return tbl; 106 | } 107 | -------------------------------------------------------------------------------- /src/libjpeg/jconfig.h: -------------------------------------------------------------------------------- 1 | /* jconfig.h. Generated automatically by configure. */ 2 | /* jconfig.cfg --- source file edited by configure script */ 3 | /* see jconfig.doc for explanations */ 4 | 5 | #define HAVE_PROTOTYPES 6 | #define HAVE_UNSIGNED_CHAR 7 | #define HAVE_UNSIGNED_SHORT 8 | #undef void 9 | #undef const 10 | #undef CHAR_IS_UNSIGNED 11 | #define HAVE_STDDEF_H 12 | #define HAVE_STDLIB_H 13 | #undef NEED_BSD_STRINGS 14 | #undef NEED_SYS_TYPES_H 15 | #undef NEED_FAR_POINTERS 16 | #define NEED_SHORT_EXTERNAL_NAMES 17 | /* Define this if you get warnings about undefined structures. */ 18 | #undef INCOMPLETE_TYPES_BROKEN 19 | 20 | #ifdef JPEG_INTERNALS 21 | 22 | #undef RIGHT_SHIFT_IS_UNSIGNED 23 | #define INLINE __inline__ 24 | /* These are for configuring the JPEG memory manager. */ 25 | #undef DEFAULT_MAX_MEM 26 | #undef NO_MKTEMP 27 | 28 | #endif /* JPEG_INTERNALS */ 29 | 30 | #ifdef JPEG_CJPEG_DJPEG 31 | 32 | #define BMP_SUPPORTED /* BMP image file format */ 33 | #define GIF_SUPPORTED /* GIF image file format */ 34 | #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */ 35 | #undef RLE_SUPPORTED /* Utah RLE image file format */ 36 | #define TARGA_SUPPORTED /* Targa image file format */ 37 | 38 | #undef TWO_FILE_COMMANDLINE 39 | #undef NEED_SIGNAL_CATCHER 40 | #undef DONT_USE_B_MODE 41 | 42 | /* Define this if you want percent-done progress reports from cjpeg/djpeg. */ 43 | #undef PROGRESS_REPORT 44 | 45 | #endif /* JPEG_CJPEG_DJPEG */ 46 | -------------------------------------------------------------------------------- /src/libjpeg/jdapimin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jdapimin.c 3 | * 4 | * Copyright (C) 1994-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains application interface code for the decompression half 9 | * of the JPEG library. These are the "minimum" API routines that may be 10 | * needed in either the normal full-decompression case or the 11 | * transcoding-only case. 12 | * 13 | * Most of the routines intended to be called directly by an application 14 | * are in this file or in jdapistd.c. But also see jcomapi.c for routines 15 | * shared by compression and decompression, and jdtrans.c for the transcoding 16 | * case. 17 | */ 18 | 19 | #define JPEG_INTERNALS 20 | #include "jinclude.h" 21 | #include "jpeglib.h" 22 | 23 | 24 | /* 25 | * Initialization of a JPEG decompression object. 26 | * The error manager must already be set up (in case memory manager fails). 27 | */ 28 | 29 | GLOBAL(void) 30 | jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize) 31 | { 32 | int i; 33 | 34 | /* Guard against version mismatches between library and caller. */ 35 | cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ 36 | if (version != JPEG_LIB_VERSION) 37 | ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); 38 | if (structsize != SIZEOF(struct jpeg_decompress_struct)) 39 | ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 40 | (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize); 41 | 42 | /* For debugging purposes, we zero the whole master structure. 43 | * But the application has already set the err pointer, and may have set 44 | * client_data, so we have to save and restore those fields. 45 | * Note: if application hasn't set client_data, tools like Purify may 46 | * complain here. 47 | */ 48 | { 49 | struct jpeg_error_mgr * err = cinfo->err; 50 | void * client_data = cinfo->client_data; /* ignore Purify complaint here */ 51 | MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct)); 52 | cinfo->err = err; 53 | cinfo->client_data = client_data; 54 | } 55 | cinfo->is_decompressor = TRUE; 56 | 57 | 58 | /* Initialize a memory manager instance for this object */ 59 | jinit_memory_mgr((j_common_ptr) cinfo); 60 | 61 | 62 | /* Zero out pointers to permanent structures. */ 63 | cinfo->progress = NULL; 64 | cinfo->src = NULL; 65 | 66 | for (i = 0; i < NUM_QUANT_TBLS; i++) 67 | cinfo->quant_tbl_ptrs[i] = NULL; 68 | 69 | for (i = 0; i < NUM_HUFF_TBLS; i++) { 70 | cinfo->dc_huff_tbl_ptrs[i] = NULL; 71 | cinfo->ac_huff_tbl_ptrs[i] = NULL; 72 | } 73 | 74 | /* Initialize marker processor so application can override methods 75 | * for COM, APPn markers before calling jpeg_read_header. 76 | */ 77 | cinfo->marker_list = NULL; 78 | jinit_marker_reader(cinfo); 79 | 80 | /* And initialize the overall input controller. */ 81 | jinit_input_controller(cinfo); 82 | 83 | /* OK, I'm ready */ 84 | cinfo->global_state = DSTATE_START; 85 | } 86 | 87 | 88 | /* 89 | * Destruction of a JPEG decompression object 90 | */ 91 | 92 | GLOBAL(void) 93 | jpeg_destroy_decompress (j_decompress_ptr cinfo) 94 | { 95 | jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ 96 | } 97 | 98 | 99 | /* 100 | * Abort processing of a JPEG decompression operation, 101 | * but don't destroy the object itself. 102 | */ 103 | 104 | GLOBAL(void) 105 | jpeg_abort_decompress (j_decompress_ptr cinfo) 106 | { 107 | jpeg_abort((j_common_ptr) cinfo); /* use common routine */ 108 | } 109 | 110 | 111 | /* 112 | * Set default decompression parameters. 113 | */ 114 | 115 | LOCAL(void) 116 | default_decompress_parms (j_decompress_ptr cinfo) 117 | { 118 | /* Guess the input colorspace, and set output colorspace accordingly. */ 119 | /* (Wish JPEG committee had provided a real way to specify this...) */ 120 | /* Note application may override our guesses. */ 121 | switch (cinfo->num_components) { 122 | case 1: 123 | cinfo->jpeg_color_space = JCS_GRAYSCALE; 124 | cinfo->out_color_space = JCS_GRAYSCALE; 125 | break; 126 | 127 | case 3: 128 | if (cinfo->saw_JFIF_marker) { 129 | cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */ 130 | } else if (cinfo->saw_Adobe_marker) { 131 | switch (cinfo->Adobe_transform) { 132 | case 0: 133 | cinfo->jpeg_color_space = JCS_RGB; 134 | break; 135 | case 1: 136 | cinfo->jpeg_color_space = JCS_YCbCr; 137 | break; 138 | default: 139 | WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); 140 | cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ 141 | break; 142 | } 143 | } else { 144 | /* Saw no special markers, try to guess from the component IDs */ 145 | int cid0 = cinfo->comp_info[0].component_id; 146 | int cid1 = cinfo->comp_info[1].component_id; 147 | int cid2 = cinfo->comp_info[2].component_id; 148 | 149 | if (cid0 == 1 && cid1 == 2 && cid2 == 3) 150 | cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */ 151 | else if (cid0 == 82 && cid1 == 71 && cid2 == 66) 152 | cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */ 153 | else { 154 | TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2); 155 | cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */ 156 | } 157 | } 158 | /* Always guess RGB is proper output colorspace. */ 159 | cinfo->out_color_space = JCS_RGB; 160 | break; 161 | 162 | case 4: 163 | if (cinfo->saw_Adobe_marker) { 164 | switch (cinfo->Adobe_transform) { 165 | case 0: 166 | cinfo->jpeg_color_space = JCS_CMYK; 167 | break; 168 | case 2: 169 | cinfo->jpeg_color_space = JCS_YCCK; 170 | break; 171 | default: 172 | WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform); 173 | cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */ 174 | break; 175 | } 176 | } else { 177 | /* No special markers, assume straight CMYK. */ 178 | cinfo->jpeg_color_space = JCS_CMYK; 179 | } 180 | cinfo->out_color_space = JCS_CMYK; 181 | break; 182 | 183 | default: 184 | cinfo->jpeg_color_space = JCS_UNKNOWN; 185 | cinfo->out_color_space = JCS_UNKNOWN; 186 | break; 187 | } 188 | 189 | /* Set defaults for other decompression parameters. */ 190 | cinfo->scale_num = 1; /* 1:1 scaling */ 191 | cinfo->scale_denom = 1; 192 | cinfo->output_gamma = 1.0; 193 | cinfo->buffered_image = FALSE; 194 | cinfo->raw_data_out = FALSE; 195 | cinfo->dct_method = JDCT_DEFAULT; 196 | cinfo->do_fancy_upsampling = TRUE; 197 | cinfo->do_block_smoothing = TRUE; 198 | cinfo->quantize_colors = FALSE; 199 | /* We set these in case application only sets quantize_colors. */ 200 | cinfo->dither_mode = JDITHER_FS; 201 | #ifdef QUANT_2PASS_SUPPORTED 202 | cinfo->two_pass_quantize = TRUE; 203 | #else 204 | cinfo->two_pass_quantize = FALSE; 205 | #endif 206 | cinfo->desired_number_of_colors = 256; 207 | cinfo->colormap = NULL; 208 | /* Initialize for no mode change in buffered-image mode. */ 209 | cinfo->enable_1pass_quant = FALSE; 210 | cinfo->enable_external_quant = FALSE; 211 | cinfo->enable_2pass_quant = FALSE; 212 | } 213 | 214 | 215 | /* 216 | * Decompression startup: read start of JPEG datastream to see what's there. 217 | * Need only initialize JPEG object and supply a data source before calling. 218 | * 219 | * This routine will read as far as the first SOS marker (ie, actual start of 220 | * compressed data), and will save all tables and parameters in the JPEG 221 | * object. It will also initialize the decompression parameters to default 222 | * values, and finally return JPEG_HEADER_OK. On return, the application may 223 | * adjust the decompression parameters and then call jpeg_start_decompress. 224 | * (Or, if the application only wanted to determine the image parameters, 225 | * the data need not be decompressed. In that case, call jpeg_abort or 226 | * jpeg_destroy to release any temporary space.) 227 | * If an abbreviated (tables only) datastream is presented, the routine will 228 | * return JPEG_HEADER_TABLES_ONLY upon reaching EOI. The application may then 229 | * re-use the JPEG object to read the abbreviated image datastream(s). 230 | * It is unnecessary (but OK) to call jpeg_abort in this case. 231 | * The JPEG_SUSPENDED return code only occurs if the data source module 232 | * requests suspension of the decompressor. In this case the application 233 | * should load more source data and then re-call jpeg_read_header to resume 234 | * processing. 235 | * If a non-suspending data source is used and require_image is TRUE, then the 236 | * return code need not be inspected since only JPEG_HEADER_OK is possible. 237 | * 238 | * This routine is now just a front end to jpeg_consume_input, with some 239 | * extra error checking. 240 | */ 241 | 242 | GLOBAL(int) 243 | jpeg_read_header (j_decompress_ptr cinfo, boolean require_image) 244 | { 245 | int retcode; 246 | 247 | if (cinfo->global_state != DSTATE_START && 248 | cinfo->global_state != DSTATE_INHEADER) 249 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 250 | 251 | retcode = jpeg_consume_input(cinfo); 252 | 253 | switch (retcode) { 254 | case JPEG_REACHED_SOS: 255 | retcode = JPEG_HEADER_OK; 256 | break; 257 | case JPEG_REACHED_EOI: 258 | if (require_image) /* Complain if application wanted an image */ 259 | ERREXIT(cinfo, JERR_NO_IMAGE); 260 | /* Reset to start state; it would be safer to require the application to 261 | * call jpeg_abort, but we can't change it now for compatibility reasons. 262 | * A side effect is to free any temporary memory (there shouldn't be any). 263 | */ 264 | jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */ 265 | retcode = JPEG_HEADER_TABLES_ONLY; 266 | break; 267 | case JPEG_SUSPENDED: 268 | /* no work */ 269 | break; 270 | } 271 | 272 | return retcode; 273 | } 274 | 275 | 276 | /* 277 | * Consume data in advance of what the decompressor requires. 278 | * This can be called at any time once the decompressor object has 279 | * been created and a data source has been set up. 280 | * 281 | * This routine is essentially a state machine that handles a couple 282 | * of critical state-transition actions, namely initial setup and 283 | * transition from header scanning to ready-for-start_decompress. 284 | * All the actual input is done via the input controller's consume_input 285 | * method. 286 | */ 287 | 288 | GLOBAL(int) 289 | jpeg_consume_input (j_decompress_ptr cinfo) 290 | { 291 | int retcode = JPEG_SUSPENDED; 292 | 293 | /* NB: every possible DSTATE value should be listed in this switch */ 294 | switch (cinfo->global_state) { 295 | case DSTATE_START: 296 | /* Start-of-datastream actions: reset appropriate modules */ 297 | (*cinfo->inputctl->reset_input_controller) (cinfo); 298 | /* Initialize application's data source module */ 299 | (*cinfo->src->init_source) (cinfo); 300 | cinfo->global_state = DSTATE_INHEADER; 301 | /*FALLTHROUGH*/ 302 | case DSTATE_INHEADER: 303 | retcode = (*cinfo->inputctl->consume_input) (cinfo); 304 | if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */ 305 | /* Set up default parameters based on header data */ 306 | default_decompress_parms(cinfo); 307 | /* Set global state: ready for start_decompress */ 308 | cinfo->global_state = DSTATE_READY; 309 | } 310 | break; 311 | case DSTATE_READY: 312 | /* Can't advance past first SOS until start_decompress is called */ 313 | retcode = JPEG_REACHED_SOS; 314 | break; 315 | case DSTATE_PRELOAD: 316 | case DSTATE_PRESCAN: 317 | case DSTATE_SCANNING: 318 | case DSTATE_RAW_OK: 319 | case DSTATE_BUFIMAGE: 320 | case DSTATE_BUFPOST: 321 | case DSTATE_STOPPING: 322 | retcode = (*cinfo->inputctl->consume_input) (cinfo); 323 | break; 324 | default: 325 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 326 | } 327 | return retcode; 328 | } 329 | 330 | 331 | /* 332 | * Have we finished reading the input file? 333 | */ 334 | 335 | GLOBAL(boolean) 336 | jpeg_input_complete (j_decompress_ptr cinfo) 337 | { 338 | /* Check for valid jpeg object */ 339 | if (cinfo->global_state < DSTATE_START || 340 | cinfo->global_state > DSTATE_STOPPING) 341 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 342 | return cinfo->inputctl->eoi_reached; 343 | } 344 | 345 | 346 | /* 347 | * Is there more than one scan? 348 | */ 349 | 350 | GLOBAL(boolean) 351 | jpeg_has_multiple_scans (j_decompress_ptr cinfo) 352 | { 353 | /* Only valid after jpeg_read_header completes */ 354 | if (cinfo->global_state < DSTATE_READY || 355 | cinfo->global_state > DSTATE_STOPPING) 356 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 357 | return cinfo->inputctl->has_multiple_scans; 358 | } 359 | 360 | 361 | /* 362 | * Finish JPEG decompression. 363 | * 364 | * This will normally just verify the file trailer and release temp storage. 365 | * 366 | * Returns FALSE if suspended. The return value need be inspected only if 367 | * a suspending data source is used. 368 | */ 369 | 370 | GLOBAL(boolean) 371 | jpeg_finish_decompress (j_decompress_ptr cinfo) 372 | { 373 | if ((cinfo->global_state == DSTATE_SCANNING || 374 | cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) { 375 | /* Terminate final pass of non-buffered mode */ 376 | if (cinfo->output_scanline < cinfo->output_height) 377 | ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); 378 | (*cinfo->master->finish_output_pass) (cinfo); 379 | cinfo->global_state = DSTATE_STOPPING; 380 | } else if (cinfo->global_state == DSTATE_BUFIMAGE) { 381 | /* Finishing after a buffered-image operation */ 382 | cinfo->global_state = DSTATE_STOPPING; 383 | } else if (cinfo->global_state != DSTATE_STOPPING) { 384 | /* STOPPING = repeat call after a suspension, anything else is error */ 385 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 386 | } 387 | /* Read until EOI */ 388 | while (! cinfo->inputctl->eoi_reached) { 389 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) 390 | return FALSE; /* Suspend, come back later */ 391 | } 392 | /* Do final cleanup */ 393 | (*cinfo->src->term_source) (cinfo); 394 | /* We can use jpeg_abort to release memory and reset global_state */ 395 | jpeg_abort((j_common_ptr) cinfo); 396 | return TRUE; 397 | } 398 | -------------------------------------------------------------------------------- /src/libjpeg/jdapistd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jdapistd.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains application interface code for the decompression half 9 | * of the JPEG library. These are the "standard" API routines that are 10 | * used in the normal full-decompression case. They are not used by a 11 | * transcoding-only application. Note that if an application links in 12 | * jpeg_start_decompress, it will end up linking in the entire decompressor. 13 | * We thus must separate this file from jdapimin.c to avoid linking the 14 | * whole decompression library into a transcoder. 15 | */ 16 | 17 | #define JPEG_INTERNALS 18 | #include "jinclude.h" 19 | #include "jpeglib.h" 20 | 21 | 22 | /* Forward declarations */ 23 | LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo)); 24 | 25 | 26 | /* 27 | * Decompression initialization. 28 | * jpeg_read_header must be completed before calling this. 29 | * 30 | * If a multipass operating mode was selected, this will do all but the 31 | * last pass, and thus may take a great deal of time. 32 | * 33 | * Returns FALSE if suspended. The return value need be inspected only if 34 | * a suspending data source is used. 35 | */ 36 | 37 | GLOBAL(boolean) 38 | jpeg_start_decompress (j_decompress_ptr cinfo) 39 | { 40 | if (cinfo->global_state == DSTATE_READY) { 41 | /* First call: initialize master control, select active modules */ 42 | jinit_master_decompress(cinfo); 43 | if (cinfo->buffered_image) { 44 | /* No more work here; expecting jpeg_start_output next */ 45 | cinfo->global_state = DSTATE_BUFIMAGE; 46 | return TRUE; 47 | } 48 | cinfo->global_state = DSTATE_PRELOAD; 49 | } 50 | if (cinfo->global_state == DSTATE_PRELOAD) { 51 | /* If file has multiple scans, absorb them all into the coef buffer */ 52 | if (cinfo->inputctl->has_multiple_scans) { 53 | #ifdef D_MULTISCAN_FILES_SUPPORTED 54 | for (;;) { 55 | int retcode; 56 | /* Call progress monitor hook if present */ 57 | if (cinfo->progress != NULL) 58 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 59 | /* Absorb some more input */ 60 | retcode = (*cinfo->inputctl->consume_input) (cinfo); 61 | if (retcode == JPEG_SUSPENDED) 62 | return FALSE; 63 | if (retcode == JPEG_REACHED_EOI) 64 | break; 65 | /* Advance progress counter if appropriate */ 66 | if (cinfo->progress != NULL && 67 | (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { 68 | if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { 69 | /* jdmaster underestimated number of scans; ratchet up one scan */ 70 | cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows; 71 | } 72 | } 73 | } 74 | #else 75 | ERREXIT(cinfo, JERR_NOT_COMPILED); 76 | #endif /* D_MULTISCAN_FILES_SUPPORTED */ 77 | } 78 | cinfo->output_scan_number = cinfo->input_scan_number; 79 | } else if (cinfo->global_state != DSTATE_PRESCAN) 80 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 81 | /* Perform any dummy output passes, and set up for the final pass */ 82 | return output_pass_setup(cinfo); 83 | } 84 | 85 | 86 | /* 87 | * Set up for an output pass, and perform any dummy pass(es) needed. 88 | * Common subroutine for jpeg_start_decompress and jpeg_start_output. 89 | * Entry: global_state = DSTATE_PRESCAN only if previously suspended. 90 | * Exit: If done, returns TRUE and sets global_state for proper output mode. 91 | * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN. 92 | */ 93 | 94 | LOCAL(boolean) 95 | output_pass_setup (j_decompress_ptr cinfo) 96 | { 97 | if (cinfo->global_state != DSTATE_PRESCAN) { 98 | /* First call: do pass setup */ 99 | (*cinfo->master->prepare_for_output_pass) (cinfo); 100 | cinfo->output_scanline = 0; 101 | cinfo->global_state = DSTATE_PRESCAN; 102 | } 103 | /* Loop over any required dummy passes */ 104 | while (cinfo->master->is_dummy_pass) { 105 | #ifdef QUANT_2PASS_SUPPORTED 106 | /* Crank through the dummy pass */ 107 | while (cinfo->output_scanline < cinfo->output_height) { 108 | JDIMENSION last_scanline; 109 | /* Call progress monitor hook if present */ 110 | if (cinfo->progress != NULL) { 111 | cinfo->progress->pass_counter = (long) cinfo->output_scanline; 112 | cinfo->progress->pass_limit = (long) cinfo->output_height; 113 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 114 | } 115 | /* Process some data */ 116 | last_scanline = cinfo->output_scanline; 117 | (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL, 118 | &cinfo->output_scanline, (JDIMENSION) 0); 119 | if (cinfo->output_scanline == last_scanline) 120 | return FALSE; /* No progress made, must suspend */ 121 | } 122 | /* Finish up dummy pass, and set up for another one */ 123 | (*cinfo->master->finish_output_pass) (cinfo); 124 | (*cinfo->master->prepare_for_output_pass) (cinfo); 125 | cinfo->output_scanline = 0; 126 | #else 127 | ERREXIT(cinfo, JERR_NOT_COMPILED); 128 | #endif /* QUANT_2PASS_SUPPORTED */ 129 | } 130 | /* Ready for application to drive output pass through 131 | * jpeg_read_scanlines or jpeg_read_raw_data. 132 | */ 133 | cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING; 134 | return TRUE; 135 | } 136 | 137 | 138 | /* 139 | * Read some scanlines of data from the JPEG decompressor. 140 | * 141 | * The return value will be the number of lines actually read. 142 | * This may be less than the number requested in several cases, 143 | * including bottom of image, data source suspension, and operating 144 | * modes that emit multiple scanlines at a time. 145 | * 146 | * Note: we warn about excess calls to jpeg_read_scanlines() since 147 | * this likely signals an application programmer error. However, 148 | * an oversize buffer (max_lines > scanlines remaining) is not an error. 149 | */ 150 | 151 | GLOBAL(JDIMENSION) 152 | jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines, 153 | JDIMENSION max_lines) 154 | { 155 | JDIMENSION row_ctr; 156 | if (cinfo->global_state != DSTATE_SCANNING) 157 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 158 | if (cinfo->output_scanline >= cinfo->output_height) { 159 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 160 | return 0; 161 | } 162 | /* Call progress monitor hook if present */ 163 | if (cinfo->progress != NULL) { 164 | cinfo->progress->pass_counter = (long) cinfo->output_scanline; 165 | cinfo->progress->pass_limit = (long) cinfo->output_height; 166 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 167 | } 168 | /* Process some data */ 169 | row_ctr = 0; 170 | (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines); 171 | cinfo->output_scanline += row_ctr; 172 | return row_ctr; 173 | } 174 | 175 | 176 | /* 177 | * Alternate entry point to read raw data. 178 | * Processes exactly one iMCU row per call, unless suspended. 179 | */ 180 | 181 | GLOBAL(JDIMENSION) 182 | jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data, 183 | JDIMENSION max_lines) 184 | { 185 | JDIMENSION lines_per_iMCU_row; 186 | 187 | if (cinfo->global_state != DSTATE_RAW_OK) 188 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 189 | if (cinfo->output_scanline >= cinfo->output_height) { 190 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); 191 | return 0; 192 | } 193 | 194 | /* Call progress monitor hook if present */ 195 | if (cinfo->progress != NULL) { 196 | cinfo->progress->pass_counter = (long) cinfo->output_scanline; 197 | cinfo->progress->pass_limit = (long) cinfo->output_height; 198 | (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 199 | } 200 | 201 | /* Verify that at least one iMCU row can be returned. */ 202 | lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size; 203 | if (max_lines < lines_per_iMCU_row) 204 | ERREXIT(cinfo, JERR_BUFFER_SIZE); 205 | 206 | /* Decompress directly into user's buffer. */ 207 | if (! (*cinfo->coef->decompress_data) (cinfo, data)) 208 | return 0; /* suspension forced, can do nothing more */ 209 | 210 | /* OK, we processed one iMCU row. */ 211 | cinfo->output_scanline += lines_per_iMCU_row; 212 | return lines_per_iMCU_row; 213 | } 214 | 215 | 216 | /* Additional entry points for buffered-image mode. */ 217 | 218 | #ifdef D_MULTISCAN_FILES_SUPPORTED 219 | 220 | /* 221 | * Initialize for an output pass in buffered-image mode. 222 | */ 223 | 224 | GLOBAL(boolean) 225 | jpeg_start_output (j_decompress_ptr cinfo, int scan_number) 226 | { 227 | if (cinfo->global_state != DSTATE_BUFIMAGE && 228 | cinfo->global_state != DSTATE_PRESCAN) 229 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 230 | /* Limit scan number to valid range */ 231 | if (scan_number <= 0) 232 | scan_number = 1; 233 | if (cinfo->inputctl->eoi_reached && 234 | scan_number > cinfo->input_scan_number) 235 | scan_number = cinfo->input_scan_number; 236 | cinfo->output_scan_number = scan_number; 237 | /* Perform any dummy output passes, and set up for the real pass */ 238 | return output_pass_setup(cinfo); 239 | } 240 | 241 | 242 | /* 243 | * Finish up after an output pass in buffered-image mode. 244 | * 245 | * Returns FALSE if suspended. The return value need be inspected only if 246 | * a suspending data source is used. 247 | */ 248 | 249 | GLOBAL(boolean) 250 | jpeg_finish_output (j_decompress_ptr cinfo) 251 | { 252 | if ((cinfo->global_state == DSTATE_SCANNING || 253 | cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) { 254 | /* Terminate this pass. */ 255 | /* We do not require the whole pass to have been completed. */ 256 | (*cinfo->master->finish_output_pass) (cinfo); 257 | cinfo->global_state = DSTATE_BUFPOST; 258 | } else if (cinfo->global_state != DSTATE_BUFPOST) { 259 | /* BUFPOST = repeat call after a suspension, anything else is error */ 260 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 261 | } 262 | /* Read markers looking for SOS or EOI */ 263 | while (cinfo->input_scan_number <= cinfo->output_scan_number && 264 | ! cinfo->inputctl->eoi_reached) { 265 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) 266 | return FALSE; /* Suspend, come back later */ 267 | } 268 | cinfo->global_state = DSTATE_BUFIMAGE; 269 | return TRUE; 270 | } 271 | 272 | #endif /* D_MULTISCAN_FILES_SUPPORTED */ 273 | -------------------------------------------------------------------------------- /src/libjpeg/jdatasrc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jdatasrc.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains decompression data source routines for the case of 9 | * reading JPEG data from a file (or any stdio stream). While these routines 10 | * are sufficient for most applications, some will want to use a different 11 | * source manager. 12 | * IMPORTANT: we assume that fread() will correctly transcribe an array of 13 | * JOCTETs from 8-bit-wide elements on external storage. If char is wider 14 | * than 8 bits on your machine, you may need to do some tweaking. 15 | */ 16 | 17 | /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ 18 | #include "jinclude.h" 19 | #include "jpeglib.h" 20 | #include "jerror.h" 21 | 22 | 23 | /* Expanded data source object for stdio input */ 24 | 25 | typedef struct { 26 | struct jpeg_source_mgr pub; /* public fields */ 27 | 28 | FILE * infile; /* source stream */ 29 | JOCTET * buffer; /* start of buffer */ 30 | boolean start_of_file; /* have we gotten any data yet? */ 31 | } my_source_mgr; 32 | 33 | typedef my_source_mgr * my_src_ptr; 34 | 35 | #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */ 36 | 37 | 38 | /* 39 | * Initialize source --- called by jpeg_read_header 40 | * before any data is actually read. 41 | */ 42 | 43 | METHODDEF(void) 44 | init_source (j_decompress_ptr cinfo) 45 | { 46 | my_src_ptr src = (my_src_ptr) cinfo->src; 47 | 48 | /* We reset the empty-input-file flag for each image, 49 | * but we don't clear the input buffer. 50 | * This is correct behavior for reading a series of images from one source. 51 | */ 52 | src->start_of_file = TRUE; 53 | } 54 | 55 | 56 | /* 57 | * Fill the input buffer --- called whenever buffer is emptied. 58 | * 59 | * In typical applications, this should read fresh data into the buffer 60 | * (ignoring the current state of next_input_byte & bytes_in_buffer), 61 | * reset the pointer & count to the start of the buffer, and return TRUE 62 | * indicating that the buffer has been reloaded. It is not necessary to 63 | * fill the buffer entirely, only to obtain at least one more byte. 64 | * 65 | * There is no such thing as an EOF return. If the end of the file has been 66 | * reached, the routine has a choice of ERREXIT() or inserting fake data into 67 | * the buffer. In most cases, generating a warning message and inserting a 68 | * fake EOI marker is the best course of action --- this will allow the 69 | * decompressor to output however much of the image is there. However, 70 | * the resulting error message is misleading if the real problem is an empty 71 | * input file, so we handle that case specially. 72 | * 73 | * In applications that need to be able to suspend compression due to input 74 | * not being available yet, a FALSE return indicates that no more data can be 75 | * obtained right now, but more may be forthcoming later. In this situation, 76 | * the decompressor will return to its caller (with an indication of the 77 | * number of scanlines it has read, if any). The application should resume 78 | * decompression after it has loaded more data into the input buffer. Note 79 | * that there are substantial restrictions on the use of suspension --- see 80 | * the documentation. 81 | * 82 | * When suspending, the decompressor will back up to a convenient restart point 83 | * (typically the start of the current MCU). next_input_byte & bytes_in_buffer 84 | * indicate where the restart point will be if the current call returns FALSE. 85 | * Data beyond this point must be rescanned after resumption, so move it to 86 | * the front of the buffer rather than discarding it. 87 | */ 88 | 89 | METHODDEF(boolean) 90 | fill_input_buffer (j_decompress_ptr cinfo) 91 | { 92 | my_src_ptr src = (my_src_ptr) cinfo->src; 93 | size_t nbytes; 94 | 95 | nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE); 96 | 97 | if (nbytes <= 0) { 98 | if (src->start_of_file) /* Treat empty input file as fatal error */ 99 | ERREXIT(cinfo, JERR_INPUT_EMPTY); 100 | WARNMS(cinfo, JWRN_JPEG_EOF); 101 | /* Insert a fake EOI marker */ 102 | src->buffer[0] = (JOCTET) 0xFF; 103 | src->buffer[1] = (JOCTET) JPEG_EOI; 104 | nbytes = 2; 105 | } 106 | 107 | src->pub.next_input_byte = src->buffer; 108 | src->pub.bytes_in_buffer = nbytes; 109 | src->start_of_file = FALSE; 110 | 111 | return TRUE; 112 | } 113 | 114 | 115 | /* 116 | * Skip data --- used to skip over a potentially large amount of 117 | * uninteresting data (such as an APPn marker). 118 | * 119 | * Writers of suspendable-input applications must note that skip_input_data 120 | * is not granted the right to give a suspension return. If the skip extends 121 | * beyond the data currently in the buffer, the buffer can be marked empty so 122 | * that the next read will cause a fill_input_buffer call that can suspend. 123 | * Arranging for additional bytes to be discarded before reloading the input 124 | * buffer is the application writer's problem. 125 | */ 126 | 127 | METHODDEF(void) 128 | skip_input_data (j_decompress_ptr cinfo, long num_bytes) 129 | { 130 | my_src_ptr src = (my_src_ptr) cinfo->src; 131 | 132 | /* Just a dumb implementation for now. Could use fseek() except 133 | * it doesn't work on pipes. Not clear that being smart is worth 134 | * any trouble anyway --- large skips are infrequent. 135 | */ 136 | if (num_bytes > 0) { 137 | while (num_bytes > (long) src->pub.bytes_in_buffer) { 138 | num_bytes -= (long) src->pub.bytes_in_buffer; 139 | (void) fill_input_buffer(cinfo); 140 | /* note we assume that fill_input_buffer will never return FALSE, 141 | * so suspension need not be handled. 142 | */ 143 | } 144 | src->pub.next_input_byte += (size_t) num_bytes; 145 | src->pub.bytes_in_buffer -= (size_t) num_bytes; 146 | } 147 | } 148 | 149 | 150 | /* 151 | * An additional method that can be provided by data source modules is the 152 | * resync_to_restart method for error recovery in the presence of RST markers. 153 | * For the moment, this source module just uses the default resync method 154 | * provided by the JPEG library. That method assumes that no backtracking 155 | * is possible. 156 | */ 157 | 158 | 159 | /* 160 | * Terminate source --- called by jpeg_finish_decompress 161 | * after all data has been read. Often a no-op. 162 | * 163 | * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding 164 | * application must deal with any cleanup that should happen even 165 | * for error exit. 166 | */ 167 | 168 | METHODDEF(void) 169 | term_source (j_decompress_ptr cinfo) 170 | { 171 | /* no work necessary here */ 172 | } 173 | 174 | 175 | /* 176 | * Prepare for input from a stdio stream. 177 | * The caller must have already opened the stream, and is responsible 178 | * for closing it after finishing decompression. 179 | */ 180 | 181 | GLOBAL(void) 182 | jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile) 183 | { 184 | my_src_ptr src; 185 | 186 | /* The source object and input buffer are made permanent so that a series 187 | * of JPEG images can be read from the same file by calling jpeg_stdio_src 188 | * only before the first one. (If we discarded the buffer at the end of 189 | * one image, we'd likely lose the start of the next one.) 190 | * This makes it unsafe to use this manager and a different source 191 | * manager serially with the same JPEG object. Caveat programmer. 192 | */ 193 | if (cinfo->src == NULL) { /* first time for this JPEG object? */ 194 | cinfo->src = (struct jpeg_source_mgr *) 195 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 196 | SIZEOF(my_source_mgr)); 197 | src = (my_src_ptr) cinfo->src; 198 | src->buffer = (JOCTET *) 199 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, 200 | INPUT_BUF_SIZE * SIZEOF(JOCTET)); 201 | } 202 | 203 | src = (my_src_ptr) cinfo->src; 204 | src->pub.init_source = init_source; 205 | src->pub.fill_input_buffer = fill_input_buffer; 206 | src->pub.skip_input_data = skip_input_data; 207 | src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */ 208 | src->pub.term_source = term_source; 209 | src->infile = infile; 210 | src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */ 211 | src->pub.next_input_byte = NULL; /* until buffer loaded */ 212 | } 213 | -------------------------------------------------------------------------------- /src/libjpeg/jdcolor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jdcolor.c 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains output colorspace conversion routines. 9 | */ 10 | 11 | #define JPEG_INTERNALS 12 | #include "jinclude.h" 13 | #include "jpeglib.h" 14 | 15 | 16 | /* Private subobject */ 17 | 18 | typedef struct { 19 | struct jpeg_color_deconverter pub; /* public fields */ 20 | 21 | /* Private state for YCC->RGB conversion */ 22 | int * Cr_r_tab; /* => table for Cr to R conversion */ 23 | int * Cb_b_tab; /* => table for Cb to B conversion */ 24 | INT32 * Cr_g_tab; /* => table for Cr to G conversion */ 25 | INT32 * Cb_g_tab; /* => table for Cb to G conversion */ 26 | } my_color_deconverter; 27 | 28 | typedef my_color_deconverter * my_cconvert_ptr; 29 | 30 | 31 | /**************** YCbCr -> RGB conversion: most common case **************/ 32 | 33 | /* 34 | * YCbCr is defined per CCIR 601-1, except that Cb and Cr are 35 | * normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5. 36 | * The conversion equations to be implemented are therefore 37 | * R = Y + 1.40200 * Cr 38 | * G = Y - 0.34414 * Cb - 0.71414 * Cr 39 | * B = Y + 1.77200 * Cb 40 | * where Cb and Cr represent the incoming values less CENTERJSAMPLE. 41 | * (These numbers are derived from TIFF 6.0 section 21, dated 3-June-92.) 42 | * 43 | * To avoid floating-point arithmetic, we represent the fractional constants 44 | * as integers scaled up by 2^16 (about 4 digits precision); we have to divide 45 | * the products by 2^16, with appropriate rounding, to get the correct answer. 46 | * Notice that Y, being an integral input, does not contribute any fraction 47 | * so it need not participate in the rounding. 48 | * 49 | * For even more speed, we avoid doing any multiplications in the inner loop 50 | * by precalculating the constants times Cb and Cr for all possible values. 51 | * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table); 52 | * for 12-bit samples it is still acceptable. It's not very reasonable for 53 | * 16-bit samples, but if you want lossless storage you shouldn't be changing 54 | * colorspace anyway. 55 | * The Cr=>R and Cb=>B values can be rounded to integers in advance; the 56 | * values for the G calculation are left scaled up, since we must add them 57 | * together before rounding. 58 | */ 59 | 60 | #define SCALEBITS 16 /* speediest right-shift on some machines */ 61 | #define ONE_HALF ((INT32) 1 << (SCALEBITS-1)) 62 | #define FIX(x) ((INT32) ((x) * (1L<RGB colorspace conversion. 67 | */ 68 | 69 | LOCAL(void) 70 | build_ycc_rgb_table (j_decompress_ptr cinfo) 71 | { 72 | my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 73 | int i; 74 | INT32 x; 75 | SHIFT_TEMPS 76 | 77 | cconvert->Cr_r_tab = (int *) 78 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 79 | (MAXJSAMPLE+1) * SIZEOF(int)); 80 | cconvert->Cb_b_tab = (int *) 81 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 82 | (MAXJSAMPLE+1) * SIZEOF(int)); 83 | cconvert->Cr_g_tab = (INT32 *) 84 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 85 | (MAXJSAMPLE+1) * SIZEOF(INT32)); 86 | cconvert->Cb_g_tab = (INT32 *) 87 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 88 | (MAXJSAMPLE+1) * SIZEOF(INT32)); 89 | 90 | for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) { 91 | /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */ 92 | /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */ 93 | /* Cr=>R value is nearest int to 1.40200 * x */ 94 | cconvert->Cr_r_tab[i] = (int) 95 | RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS); 96 | /* Cb=>B value is nearest int to 1.77200 * x */ 97 | cconvert->Cb_b_tab[i] = (int) 98 | RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS); 99 | /* Cr=>G value is scaled-up -0.71414 * x */ 100 | cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x; 101 | /* Cb=>G value is scaled-up -0.34414 * x */ 102 | /* We also add in ONE_HALF so that need not do it in inner loop */ 103 | cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF; 104 | } 105 | } 106 | 107 | 108 | /* 109 | * Convert some rows of samples to the output colorspace. 110 | * 111 | * Note that we change from noninterleaved, one-plane-per-component format 112 | * to interleaved-pixel format. The output buffer is therefore three times 113 | * as wide as the input buffer. 114 | * A starting row offset is provided only for the input buffer. The caller 115 | * can easily adjust the passed output_buf value to accommodate any row 116 | * offset required on that side. 117 | */ 118 | 119 | METHODDEF(void) 120 | ycc_rgb_convert (j_decompress_ptr cinfo, 121 | JSAMPIMAGE input_buf, JDIMENSION input_row, 122 | JSAMPARRAY output_buf, int num_rows) 123 | { 124 | my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 125 | register int y, cb, cr; 126 | register JSAMPROW outptr; 127 | register JSAMPROW inptr0, inptr1, inptr2; 128 | register JDIMENSION col; 129 | JDIMENSION num_cols = cinfo->output_width; 130 | /* copy these pointers into registers if possible */ 131 | register JSAMPLE * range_limit = cinfo->sample_range_limit; 132 | register int * Crrtab = cconvert->Cr_r_tab; 133 | register int * Cbbtab = cconvert->Cb_b_tab; 134 | register INT32 * Crgtab = cconvert->Cr_g_tab; 135 | register INT32 * Cbgtab = cconvert->Cb_g_tab; 136 | SHIFT_TEMPS 137 | 138 | while (--num_rows >= 0) { 139 | inptr0 = input_buf[0][input_row]; 140 | inptr1 = input_buf[1][input_row]; 141 | inptr2 = input_buf[2][input_row]; 142 | input_row++; 143 | outptr = *output_buf++; 144 | for (col = 0; col < num_cols; col++) { 145 | y = GETJSAMPLE(inptr0[col]); 146 | cb = GETJSAMPLE(inptr1[col]); 147 | cr = GETJSAMPLE(inptr2[col]); 148 | /* Range-limiting is essential due to noise introduced by DCT losses. */ 149 | outptr[RGB_RED] = range_limit[y + Crrtab[cr]]; 150 | outptr[RGB_GREEN] = range_limit[y + 151 | ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], 152 | SCALEBITS))]; 153 | outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]]; 154 | outptr += RGB_PIXELSIZE; 155 | } 156 | } 157 | } 158 | 159 | 160 | /**************** Cases other than YCbCr -> RGB **************/ 161 | 162 | 163 | /* 164 | * Color conversion for no colorspace change: just copy the data, 165 | * converting from separate-planes to interleaved representation. 166 | */ 167 | 168 | METHODDEF(void) 169 | null_convert (j_decompress_ptr cinfo, 170 | JSAMPIMAGE input_buf, JDIMENSION input_row, 171 | JSAMPARRAY output_buf, int num_rows) 172 | { 173 | register JSAMPROW inptr, outptr; 174 | register JDIMENSION count; 175 | register int num_components = cinfo->num_components; 176 | JDIMENSION num_cols = cinfo->output_width; 177 | int ci; 178 | 179 | while (--num_rows >= 0) { 180 | for (ci = 0; ci < num_components; ci++) { 181 | inptr = input_buf[ci][input_row]; 182 | outptr = output_buf[0] + ci; 183 | for (count = num_cols; count > 0; count--) { 184 | *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */ 185 | outptr += num_components; 186 | } 187 | } 188 | input_row++; 189 | output_buf++; 190 | } 191 | } 192 | 193 | 194 | /* 195 | * Color conversion for grayscale: just copy the data. 196 | * This also works for YCbCr -> grayscale conversion, in which 197 | * we just copy the Y (luminance) component and ignore chrominance. 198 | */ 199 | 200 | METHODDEF(void) 201 | grayscale_convert (j_decompress_ptr cinfo, 202 | JSAMPIMAGE input_buf, JDIMENSION input_row, 203 | JSAMPARRAY output_buf, int num_rows) 204 | { 205 | jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0, 206 | num_rows, cinfo->output_width); 207 | } 208 | 209 | 210 | /* 211 | * Convert grayscale to RGB: just duplicate the graylevel three times. 212 | * This is provided to support applications that don't want to cope 213 | * with grayscale as a separate case. 214 | */ 215 | 216 | METHODDEF(void) 217 | gray_rgb_convert (j_decompress_ptr cinfo, 218 | JSAMPIMAGE input_buf, JDIMENSION input_row, 219 | JSAMPARRAY output_buf, int num_rows) 220 | { 221 | register JSAMPROW inptr, outptr; 222 | register JDIMENSION col; 223 | JDIMENSION num_cols = cinfo->output_width; 224 | 225 | while (--num_rows >= 0) { 226 | inptr = input_buf[0][input_row++]; 227 | outptr = *output_buf++; 228 | for (col = 0; col < num_cols; col++) { 229 | /* We can dispense with GETJSAMPLE() here */ 230 | outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col]; 231 | outptr += RGB_PIXELSIZE; 232 | } 233 | } 234 | } 235 | 236 | 237 | /* 238 | * Adobe-style YCCK->CMYK conversion. 239 | * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same 240 | * conversion as above, while passing K (black) unchanged. 241 | * We assume build_ycc_rgb_table has been called. 242 | */ 243 | 244 | METHODDEF(void) 245 | ycck_cmyk_convert (j_decompress_ptr cinfo, 246 | JSAMPIMAGE input_buf, JDIMENSION input_row, 247 | JSAMPARRAY output_buf, int num_rows) 248 | { 249 | my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert; 250 | register int y, cb, cr; 251 | register JSAMPROW outptr; 252 | register JSAMPROW inptr0, inptr1, inptr2, inptr3; 253 | register JDIMENSION col; 254 | JDIMENSION num_cols = cinfo->output_width; 255 | /* copy these pointers into registers if possible */ 256 | register JSAMPLE * range_limit = cinfo->sample_range_limit; 257 | register int * Crrtab = cconvert->Cr_r_tab; 258 | register int * Cbbtab = cconvert->Cb_b_tab; 259 | register INT32 * Crgtab = cconvert->Cr_g_tab; 260 | register INT32 * Cbgtab = cconvert->Cb_g_tab; 261 | SHIFT_TEMPS 262 | 263 | while (--num_rows >= 0) { 264 | inptr0 = input_buf[0][input_row]; 265 | inptr1 = input_buf[1][input_row]; 266 | inptr2 = input_buf[2][input_row]; 267 | inptr3 = input_buf[3][input_row]; 268 | input_row++; 269 | outptr = *output_buf++; 270 | for (col = 0; col < num_cols; col++) { 271 | y = GETJSAMPLE(inptr0[col]); 272 | cb = GETJSAMPLE(inptr1[col]); 273 | cr = GETJSAMPLE(inptr2[col]); 274 | /* Range-limiting is essential due to noise introduced by DCT losses. */ 275 | outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */ 276 | outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */ 277 | ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], 278 | SCALEBITS)))]; 279 | outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */ 280 | /* K passes through unchanged */ 281 | outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */ 282 | outptr += 4; 283 | } 284 | } 285 | } 286 | 287 | 288 | /* 289 | * Empty method for start_pass. 290 | */ 291 | 292 | METHODDEF(void) 293 | start_pass_dcolor (j_decompress_ptr cinfo) 294 | { 295 | /* no work needed */ 296 | } 297 | 298 | 299 | /* 300 | * Module initialization routine for output colorspace conversion. 301 | */ 302 | 303 | GLOBAL(void) 304 | jinit_color_deconverter (j_decompress_ptr cinfo) 305 | { 306 | my_cconvert_ptr cconvert; 307 | int ci; 308 | 309 | cconvert = (my_cconvert_ptr) 310 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 311 | SIZEOF(my_color_deconverter)); 312 | cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert; 313 | cconvert->pub.start_pass = start_pass_dcolor; 314 | 315 | /* Make sure num_components agrees with jpeg_color_space */ 316 | switch (cinfo->jpeg_color_space) { 317 | case JCS_GRAYSCALE: 318 | if (cinfo->num_components != 1) 319 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 320 | break; 321 | 322 | case JCS_RGB: 323 | case JCS_YCbCr: 324 | if (cinfo->num_components != 3) 325 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 326 | break; 327 | 328 | case JCS_CMYK: 329 | case JCS_YCCK: 330 | if (cinfo->num_components != 4) 331 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 332 | break; 333 | 334 | default: /* JCS_UNKNOWN can be anything */ 335 | if (cinfo->num_components < 1) 336 | ERREXIT(cinfo, JERR_BAD_J_COLORSPACE); 337 | break; 338 | } 339 | 340 | /* Set out_color_components and conversion method based on requested space. 341 | * Also clear the component_needed flags for any unused components, 342 | * so that earlier pipeline stages can avoid useless computation. 343 | */ 344 | 345 | switch (cinfo->out_color_space) { 346 | case JCS_GRAYSCALE: 347 | cinfo->out_color_components = 1; 348 | if (cinfo->jpeg_color_space == JCS_GRAYSCALE || 349 | cinfo->jpeg_color_space == JCS_YCbCr) { 350 | cconvert->pub.color_convert = grayscale_convert; 351 | /* For color->grayscale conversion, only the Y (0) component is needed */ 352 | for (ci = 1; ci < cinfo->num_components; ci++) 353 | cinfo->comp_info[ci].component_needed = FALSE; 354 | } else 355 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 356 | break; 357 | 358 | case JCS_RGB: 359 | cinfo->out_color_components = RGB_PIXELSIZE; 360 | if (cinfo->jpeg_color_space == JCS_YCbCr) { 361 | cconvert->pub.color_convert = ycc_rgb_convert; 362 | build_ycc_rgb_table(cinfo); 363 | } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) { 364 | cconvert->pub.color_convert = gray_rgb_convert; 365 | } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) { 366 | cconvert->pub.color_convert = null_convert; 367 | } else 368 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 369 | break; 370 | 371 | case JCS_CMYK: 372 | cinfo->out_color_components = 4; 373 | if (cinfo->jpeg_color_space == JCS_YCCK) { 374 | cconvert->pub.color_convert = ycck_cmyk_convert; 375 | build_ycc_rgb_table(cinfo); 376 | } else if (cinfo->jpeg_color_space == JCS_CMYK) { 377 | cconvert->pub.color_convert = null_convert; 378 | } else 379 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 380 | break; 381 | 382 | default: 383 | /* Permit null conversion to same output space */ 384 | if (cinfo->out_color_space == cinfo->jpeg_color_space) { 385 | cinfo->out_color_components = cinfo->num_components; 386 | cconvert->pub.color_convert = null_convert; 387 | } else /* unsupported non-null conversion */ 388 | ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL); 389 | break; 390 | } 391 | 392 | if (cinfo->quantize_colors) 393 | cinfo->output_components = 1; /* single colormapped output component */ 394 | else 395 | cinfo->output_components = cinfo->out_color_components; 396 | } 397 | -------------------------------------------------------------------------------- /src/libjpeg/jdct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jdct.h 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This include file contains common declarations for the forward and 9 | * inverse DCT modules. These declarations are private to the DCT managers 10 | * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms. 11 | * The individual DCT algorithms are kept in separate files to ease 12 | * machine-dependent tuning (e.g., assembly coding). 13 | */ 14 | 15 | 16 | /* 17 | * A forward DCT routine is given a pointer to a work area of type DCTELEM[]; 18 | * the DCT is to be performed in-place in that buffer. Type DCTELEM is int 19 | * for 8-bit samples, INT32 for 12-bit samples. (NOTE: Floating-point DCT 20 | * implementations use an array of type FAST_FLOAT, instead.) 21 | * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE). 22 | * The DCT outputs are returned scaled up by a factor of 8; they therefore 23 | * have a range of +-8K for 8-bit data, +-128K for 12-bit data. This 24 | * convention improves accuracy in integer implementations and saves some 25 | * work in floating-point ones. 26 | * Quantization of the output coefficients is done by jcdctmgr.c. 27 | */ 28 | 29 | #if BITS_IN_JSAMPLE == 8 30 | typedef int DCTELEM; /* 16 or 32 bits is fine */ 31 | #else 32 | typedef INT32 DCTELEM; /* must have 32 bits */ 33 | #endif 34 | 35 | typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data)); 36 | typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data)); 37 | 38 | 39 | /* 40 | * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer 41 | * to an output sample array. The routine must dequantize the input data as 42 | * well as perform the IDCT; for dequantization, it uses the multiplier table 43 | * pointed to by compptr->dct_table. The output data is to be placed into the 44 | * sample array starting at a specified column. (Any row offset needed will 45 | * be applied to the array pointer before it is passed to the IDCT code.) 46 | * Note that the number of samples emitted by the IDCT routine is 47 | * DCT_scaled_size * DCT_scaled_size. 48 | */ 49 | 50 | /* typedef inverse_DCT_method_ptr is declared in jpegint.h */ 51 | 52 | /* 53 | * Each IDCT routine has its own ideas about the best dct_table element type. 54 | */ 55 | 56 | typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */ 57 | #if BITS_IN_JSAMPLE == 8 58 | typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */ 59 | #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */ 60 | #else 61 | typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */ 62 | #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */ 63 | #endif 64 | typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */ 65 | 66 | 67 | /* 68 | * Each IDCT routine is responsible for range-limiting its results and 69 | * converting them to unsigned form (0..MAXJSAMPLE). The raw outputs could 70 | * be quite far out of range if the input data is corrupt, so a bulletproof 71 | * range-limiting step is required. We use a mask-and-table-lookup method 72 | * to do the combined operations quickly. See the comments with 73 | * prepare_range_limit_table (in jdmaster.c) for more info. 74 | */ 75 | 76 | #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE) 77 | 78 | #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */ 79 | 80 | 81 | /* Short forms of external names for systems with brain-damaged linkers. */ 82 | 83 | #ifdef NEED_SHORT_EXTERNAL_NAMES 84 | #define jpeg_fdct_islow jFDislow 85 | #define jpeg_fdct_ifast jFDifast 86 | #define jpeg_fdct_float jFDfloat 87 | #define jpeg_idct_islow jRDislow 88 | #define jpeg_idct_ifast jRDifast 89 | #define jpeg_idct_float jRDfloat 90 | #define jpeg_idct_4x4 jRD4x4 91 | #define jpeg_idct_2x2 jRD2x2 92 | #define jpeg_idct_1x1 jRD1x1 93 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 94 | 95 | /* Extern declarations for the forward and inverse DCT routines. */ 96 | 97 | EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data)); 98 | EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data)); 99 | EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data)); 100 | 101 | EXTERN(void) jpeg_idct_islow 102 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 103 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 104 | EXTERN(void) jpeg_idct_ifast 105 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 106 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 107 | EXTERN(void) jpeg_idct_float 108 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 109 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 110 | EXTERN(void) jpeg_idct_4x4 111 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 112 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 113 | EXTERN(void) jpeg_idct_2x2 114 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 115 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 116 | EXTERN(void) jpeg_idct_1x1 117 | JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr, 118 | JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)); 119 | 120 | 121 | /* 122 | * Macros for handling fixed-point arithmetic; these are used by many 123 | * but not all of the DCT/IDCT modules. 124 | * 125 | * All values are expected to be of type INT32. 126 | * Fractional constants are scaled left by CONST_BITS bits. 127 | * CONST_BITS is defined within each module using these macros, 128 | * and may differ from one module to the next. 129 | */ 130 | 131 | #define ONE ((INT32) 1) 132 | #define CONST_SCALE (ONE << CONST_BITS) 133 | 134 | /* Convert a positive real constant to an integer scaled by CONST_SCALE. 135 | * Caution: some C compilers fail to reduce "FIX(constant)" at compile time, 136 | * thus causing a lot of useless floating-point operations at run time. 137 | */ 138 | 139 | #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5)) 140 | 141 | /* Descale and correctly round an INT32 value that's scaled by N bits. 142 | * We assume RIGHT_SHIFT rounds towards minus infinity, so adding 143 | * the fudge factor is correct for either sign of X. 144 | */ 145 | 146 | #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n) 147 | 148 | /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. 149 | * This macro is used only when the two inputs will actually be no more than 150 | * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a 151 | * full 32x32 multiply. This provides a useful speedup on many machines. 152 | * Unfortunately there is no way to specify a 16x16->32 multiply portably 153 | * in C, but some C compilers will do the right thing if you provide the 154 | * correct combination of casts. 155 | */ 156 | 157 | #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ 158 | #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const))) 159 | #endif 160 | #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */ 161 | #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const))) 162 | #endif 163 | 164 | #ifndef MULTIPLY16C16 /* default definition */ 165 | #define MULTIPLY16C16(var,const) ((var) * (const)) 166 | #endif 167 | 168 | /* Same except both inputs are variables. */ 169 | 170 | #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */ 171 | #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2))) 172 | #endif 173 | 174 | #ifndef MULTIPLY16V16 /* default definition */ 175 | #define MULTIPLY16V16(var1,var2) ((var1) * (var2)) 176 | #endif 177 | -------------------------------------------------------------------------------- /src/libjpeg/jddctmgr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jddctmgr.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains the inverse-DCT management logic. 9 | * This code selects a particular IDCT implementation to be used, 10 | * and it performs related housekeeping chores. No code in this file 11 | * is executed per IDCT step, only during output pass setup. 12 | * 13 | * Note that the IDCT routines are responsible for performing coefficient 14 | * dequantization as well as the IDCT proper. This module sets up the 15 | * dequantization multiplier table needed by the IDCT routine. 16 | */ 17 | 18 | #define JPEG_INTERNALS 19 | #include "jinclude.h" 20 | #include "jpeglib.h" 21 | #include "jdct.h" /* Private declarations for DCT subsystem */ 22 | 23 | 24 | /* 25 | * The decompressor input side (jdinput.c) saves away the appropriate 26 | * quantization table for each component at the start of the first scan 27 | * involving that component. (This is necessary in order to correctly 28 | * decode files that reuse Q-table slots.) 29 | * When we are ready to make an output pass, the saved Q-table is converted 30 | * to a multiplier table that will actually be used by the IDCT routine. 31 | * The multiplier table contents are IDCT-method-dependent. To support 32 | * application changes in IDCT method between scans, we can remake the 33 | * multiplier tables if necessary. 34 | * In buffered-image mode, the first output pass may occur before any data 35 | * has been seen for some components, and thus before their Q-tables have 36 | * been saved away. To handle this case, multiplier tables are preset 37 | * to zeroes; the result of the IDCT will be a neutral gray level. 38 | */ 39 | 40 | 41 | /* Private subobject for this module */ 42 | 43 | typedef struct { 44 | struct jpeg_inverse_dct pub; /* public fields */ 45 | 46 | /* This array contains the IDCT method code that each multiplier table 47 | * is currently set up for, or -1 if it's not yet set up. 48 | * The actual multiplier tables are pointed to by dct_table in the 49 | * per-component comp_info structures. 50 | */ 51 | int cur_method[MAX_COMPONENTS]; 52 | } my_idct_controller; 53 | 54 | typedef my_idct_controller * my_idct_ptr; 55 | 56 | 57 | /* Allocated multiplier tables: big enough for any supported variant */ 58 | 59 | typedef union { 60 | ISLOW_MULT_TYPE islow_array[DCTSIZE2]; 61 | #ifdef DCT_IFAST_SUPPORTED 62 | IFAST_MULT_TYPE ifast_array[DCTSIZE2]; 63 | #endif 64 | #ifdef DCT_FLOAT_SUPPORTED 65 | FLOAT_MULT_TYPE float_array[DCTSIZE2]; 66 | #endif 67 | } multiplier_table; 68 | 69 | 70 | /* The current scaled-IDCT routines require ISLOW-style multiplier tables, 71 | * so be sure to compile that code if either ISLOW or SCALING is requested. 72 | */ 73 | #ifdef DCT_ISLOW_SUPPORTED 74 | #define PROVIDE_ISLOW_TABLES 75 | #else 76 | #ifdef IDCT_SCALING_SUPPORTED 77 | #define PROVIDE_ISLOW_TABLES 78 | #endif 79 | #endif 80 | 81 | 82 | /* 83 | * Prepare for an output pass. 84 | * Here we select the proper IDCT routine for each component and build 85 | * a matching multiplier table. 86 | */ 87 | 88 | METHODDEF(void) 89 | start_pass (j_decompress_ptr cinfo) 90 | { 91 | my_idct_ptr idct = (my_idct_ptr) cinfo->idct; 92 | int ci, i; 93 | jpeg_component_info *compptr; 94 | int method = 0; 95 | inverse_DCT_method_ptr method_ptr = NULL; 96 | JQUANT_TBL * qtbl; 97 | 98 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 99 | ci++, compptr++) { 100 | /* Select the proper IDCT routine for this component's scaling */ 101 | switch (compptr->DCT_scaled_size) { 102 | #ifdef IDCT_SCALING_SUPPORTED 103 | case 1: 104 | method_ptr = jpeg_idct_1x1; 105 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ 106 | break; 107 | case 2: 108 | method_ptr = jpeg_idct_2x2; 109 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ 110 | break; 111 | case 4: 112 | method_ptr = jpeg_idct_4x4; 113 | method = JDCT_ISLOW; /* jidctred uses islow-style table */ 114 | break; 115 | #endif 116 | case DCTSIZE: 117 | switch (cinfo->dct_method) { 118 | #ifdef DCT_ISLOW_SUPPORTED 119 | case JDCT_ISLOW: 120 | method_ptr = jpeg_idct_islow; 121 | method = JDCT_ISLOW; 122 | break; 123 | #endif 124 | #ifdef DCT_IFAST_SUPPORTED 125 | case JDCT_IFAST: 126 | method_ptr = jpeg_idct_ifast; 127 | method = JDCT_IFAST; 128 | break; 129 | #endif 130 | #ifdef DCT_FLOAT_SUPPORTED 131 | case JDCT_FLOAT: 132 | method_ptr = jpeg_idct_float; 133 | method = JDCT_FLOAT; 134 | break; 135 | #endif 136 | default: 137 | ERREXIT(cinfo, JERR_NOT_COMPILED); 138 | break; 139 | } 140 | break; 141 | default: 142 | ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size); 143 | break; 144 | } 145 | idct->pub.inverse_DCT[ci] = method_ptr; 146 | /* Create multiplier table from quant table. 147 | * However, we can skip this if the component is uninteresting 148 | * or if we already built the table. Also, if no quant table 149 | * has yet been saved for the component, we leave the 150 | * multiplier table all-zero; we'll be reading zeroes from the 151 | * coefficient controller's buffer anyway. 152 | */ 153 | if (! compptr->component_needed || idct->cur_method[ci] == method) 154 | continue; 155 | qtbl = compptr->quant_table; 156 | if (qtbl == NULL) /* happens if no data yet for component */ 157 | continue; 158 | idct->cur_method[ci] = method; 159 | switch (method) { 160 | #ifdef PROVIDE_ISLOW_TABLES 161 | case JDCT_ISLOW: 162 | { 163 | /* For LL&M IDCT method, multipliers are equal to raw quantization 164 | * coefficients, but are stored as ints to ensure access efficiency. 165 | */ 166 | ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table; 167 | for (i = 0; i < DCTSIZE2; i++) { 168 | ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i]; 169 | } 170 | } 171 | break; 172 | #endif 173 | #ifdef DCT_IFAST_SUPPORTED 174 | case JDCT_IFAST: 175 | { 176 | /* For AA&N IDCT method, multipliers are equal to quantization 177 | * coefficients scaled by scalefactor[row]*scalefactor[col], where 178 | * scalefactor[0] = 1 179 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 180 | * For integer operation, the multiplier table is to be scaled by 181 | * IFAST_SCALE_BITS. 182 | */ 183 | IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table; 184 | #define CONST_BITS 14 185 | static const INT16 aanscales[DCTSIZE2] = { 186 | /* precomputed values scaled up by 14 bits */ 187 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 188 | 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, 189 | 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, 190 | 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, 191 | 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, 192 | 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, 193 | 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, 194 | 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 195 | }; 196 | SHIFT_TEMPS 197 | 198 | for (i = 0; i < DCTSIZE2; i++) { 199 | ifmtbl[i] = (IFAST_MULT_TYPE) 200 | DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i], 201 | (INT32) aanscales[i]), 202 | CONST_BITS-IFAST_SCALE_BITS); 203 | } 204 | } 205 | break; 206 | #endif 207 | #ifdef DCT_FLOAT_SUPPORTED 208 | case JDCT_FLOAT: 209 | { 210 | /* For float AA&N IDCT method, multipliers are equal to quantization 211 | * coefficients scaled by scalefactor[row]*scalefactor[col], where 212 | * scalefactor[0] = 1 213 | * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7 214 | */ 215 | FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table; 216 | int row, col; 217 | static const double aanscalefactor[DCTSIZE] = { 218 | 1.0, 1.387039845, 1.306562965, 1.175875602, 219 | 1.0, 0.785694958, 0.541196100, 0.275899379 220 | }; 221 | 222 | i = 0; 223 | for (row = 0; row < DCTSIZE; row++) { 224 | for (col = 0; col < DCTSIZE; col++) { 225 | fmtbl[i] = (FLOAT_MULT_TYPE) 226 | ((double) qtbl->quantval[i] * 227 | aanscalefactor[row] * aanscalefactor[col]); 228 | i++; 229 | } 230 | } 231 | } 232 | break; 233 | #endif 234 | default: 235 | ERREXIT(cinfo, JERR_NOT_COMPILED); 236 | break; 237 | } 238 | } 239 | } 240 | 241 | 242 | /* 243 | * Initialize IDCT manager. 244 | */ 245 | 246 | GLOBAL(void) 247 | jinit_inverse_dct (j_decompress_ptr cinfo) 248 | { 249 | my_idct_ptr idct; 250 | int ci; 251 | jpeg_component_info *compptr; 252 | 253 | idct = (my_idct_ptr) 254 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 255 | SIZEOF(my_idct_controller)); 256 | cinfo->idct = (struct jpeg_inverse_dct *) idct; 257 | idct->pub.start_pass = start_pass; 258 | 259 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 260 | ci++, compptr++) { 261 | /* Allocate and pre-zero a multiplier table for each component */ 262 | compptr->dct_table = 263 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 264 | SIZEOF(multiplier_table)); 265 | MEMZERO(compptr->dct_table, SIZEOF(multiplier_table)); 266 | /* Mark multiplier table not yet set up for any method */ 267 | idct->cur_method[ci] = -1; 268 | } 269 | } 270 | -------------------------------------------------------------------------------- /src/libjpeg/jdhuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jdhuff.h 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains declarations for Huffman entropy decoding routines 9 | * that are shared between the sequential decoder (jdhuff.c) and the 10 | * progressive decoder (jdphuff.c). No other modules need to see these. 11 | */ 12 | 13 | /* Short forms of external names for systems with brain-damaged linkers. */ 14 | 15 | #ifdef NEED_SHORT_EXTERNAL_NAMES 16 | #define jpeg_make_d_derived_tbl jMkDDerived 17 | #define jpeg_fill_bit_buffer jFilBitBuf 18 | #define jpeg_huff_decode jHufDecode 19 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 20 | 21 | 22 | /* Derived data constructed for each Huffman table */ 23 | 24 | #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */ 25 | 26 | typedef struct { 27 | /* Basic tables: (element [0] of each array is unused) */ 28 | INT32 maxcode[18]; /* largest code of length k (-1 if none) */ 29 | /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */ 30 | INT32 valoffset[17]; /* huffval[] offset for codes of length k */ 31 | /* valoffset[k] = huffval[] index of 1st symbol of code length k, less 32 | * the smallest code of length k; so given a code of length k, the 33 | * corresponding symbol is huffval[code + valoffset[k]] 34 | */ 35 | 36 | /* Link to public Huffman table (needed only in jpeg_huff_decode) */ 37 | JHUFF_TBL *pub; 38 | 39 | /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of 40 | * the input data stream. If the next Huffman code is no more 41 | * than HUFF_LOOKAHEAD bits long, we can obtain its length and 42 | * the corresponding symbol directly from these tables. 43 | */ 44 | int look_nbits[1< 32 bits on your machine, and shifting/masking longs is 76 | * reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE 77 | * appropriately should be a win. Unfortunately we can't define the size 78 | * with something like #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8) 79 | * because not all machines measure sizeof in 8-bit bytes. 80 | */ 81 | 82 | typedef struct { /* Bitreading state saved across MCUs */ 83 | bit_buf_type get_buffer; /* current bit-extraction buffer */ 84 | int bits_left; /* # of unused bits in it */ 85 | } bitread_perm_state; 86 | 87 | typedef struct { /* Bitreading working state within an MCU */ 88 | /* Current data source location */ 89 | /* We need a copy, rather than munging the original, in case of suspension */ 90 | const JOCTET * next_input_byte; /* => next byte to read from source */ 91 | size_t bytes_in_buffer; /* # of bytes remaining in source buffer */ 92 | /* Bit input buffer --- note these values are kept in register variables, 93 | * not in this struct, inside the inner loops. 94 | */ 95 | bit_buf_type get_buffer; /* current bit-extraction buffer */ 96 | int bits_left; /* # of unused bits in it */ 97 | /* Pointer needed by jpeg_fill_bit_buffer. */ 98 | j_decompress_ptr cinfo; /* back link to decompress master record */ 99 | } bitread_working_state; 100 | 101 | /* Macros to declare and load/save bitread local variables. */ 102 | #define BITREAD_STATE_VARS \ 103 | register bit_buf_type get_buffer; \ 104 | register int bits_left; \ 105 | bitread_working_state br_state 106 | 107 | #define BITREAD_LOAD_STATE(cinfop,permstate) \ 108 | br_state.cinfo = cinfop; \ 109 | br_state.next_input_byte = cinfop->src->next_input_byte; \ 110 | br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \ 111 | get_buffer = permstate.get_buffer; \ 112 | bits_left = permstate.bits_left; 113 | 114 | #define BITREAD_SAVE_STATE(cinfop,permstate) \ 115 | cinfop->src->next_input_byte = br_state.next_input_byte; \ 116 | cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \ 117 | permstate.get_buffer = get_buffer; \ 118 | permstate.bits_left = bits_left 119 | 120 | /* 121 | * These macros provide the in-line portion of bit fetching. 122 | * Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer 123 | * before using GET_BITS, PEEK_BITS, or DROP_BITS. 124 | * The variables get_buffer and bits_left are assumed to be locals, 125 | * but the state struct might not be (jpeg_huff_decode needs this). 126 | * CHECK_BIT_BUFFER(state,n,action); 127 | * Ensure there are N bits in get_buffer; if suspend, take action. 128 | * val = GET_BITS(n); 129 | * Fetch next N bits. 130 | * val = PEEK_BITS(n); 131 | * Fetch next N bits without removing them from the buffer. 132 | * DROP_BITS(n); 133 | * Discard next N bits. 134 | * The value N should be a simple variable, not an expression, because it 135 | * is evaluated multiple times. 136 | */ 137 | 138 | #define CHECK_BIT_BUFFER(state,nbits,action) \ 139 | { if (bits_left < (nbits)) { \ 140 | if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \ 141 | { action; } \ 142 | get_buffer = (state).get_buffer; bits_left = (state).bits_left; } } 143 | 144 | #define GET_BITS(nbits) \ 145 | (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1)) 146 | 147 | #define PEEK_BITS(nbits) \ 148 | (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1)) 149 | 150 | #define DROP_BITS(nbits) \ 151 | (bits_left -= (nbits)) 152 | 153 | /* Load up the bit buffer to a depth of at least nbits */ 154 | EXTERN(boolean) jpeg_fill_bit_buffer 155 | JPP((bitread_working_state * state, register bit_buf_type get_buffer, 156 | register int bits_left, int nbits)); 157 | 158 | 159 | /* 160 | * Code for extracting next Huffman-coded symbol from input bit stream. 161 | * Again, this is time-critical and we make the main paths be macros. 162 | * 163 | * We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits 164 | * without looping. Usually, more than 95% of the Huffman codes will be 8 165 | * or fewer bits long. The few overlength codes are handled with a loop, 166 | * which need not be inline code. 167 | * 168 | * Notes about the HUFF_DECODE macro: 169 | * 1. Near the end of the data segment, we may fail to get enough bits 170 | * for a lookahead. In that case, we do it the hard way. 171 | * 2. If the lookahead table contains no entry, the next code must be 172 | * more than HUFF_LOOKAHEAD bits long. 173 | * 3. jpeg_huff_decode returns -1 if forced to suspend. 174 | */ 175 | 176 | #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \ 177 | { register int nb, look; \ 178 | if (bits_left < HUFF_LOOKAHEAD) { \ 179 | if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \ 180 | get_buffer = state.get_buffer; bits_left = state.bits_left; \ 181 | if (bits_left < HUFF_LOOKAHEAD) { \ 182 | nb = 1; goto slowlabel; \ 183 | } \ 184 | } \ 185 | look = PEEK_BITS(HUFF_LOOKAHEAD); \ 186 | if ((nb = htbl->look_nbits[look]) != 0) { \ 187 | DROP_BITS(nb); \ 188 | result = htbl->look_sym[look]; \ 189 | } else { \ 190 | nb = HUFF_LOOKAHEAD+1; \ 191 | slowlabel: \ 192 | if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \ 193 | { failaction; } \ 194 | get_buffer = state.get_buffer; bits_left = state.bits_left; \ 195 | } \ 196 | } 197 | 198 | /* Out-of-line case for Huffman code fetching */ 199 | EXTERN(int) jpeg_huff_decode 200 | JPP((bitread_working_state * state, register bit_buf_type get_buffer, 201 | register int bits_left, d_derived_tbl * htbl, int min_bits)); 202 | -------------------------------------------------------------------------------- /src/libjpeg/jdpostct.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jdpostct.c 3 | * 4 | * Copyright (C) 1994-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains the decompression postprocessing controller. 9 | * This controller manages the upsampling, color conversion, and color 10 | * quantization/reduction steps; specifically, it controls the buffering 11 | * between upsample/color conversion and color quantization/reduction. 12 | * 13 | * If no color quantization/reduction is required, then this module has no 14 | * work to do, and it just hands off to the upsample/color conversion code. 15 | * An integrated upsample/convert/quantize process would replace this module 16 | * entirely. 17 | */ 18 | 19 | #define JPEG_INTERNALS 20 | #include "jinclude.h" 21 | #include "jpeglib.h" 22 | 23 | 24 | /* Private buffer controller object */ 25 | 26 | typedef struct { 27 | struct jpeg_d_post_controller pub; /* public fields */ 28 | 29 | /* Color quantization source buffer: this holds output data from 30 | * the upsample/color conversion step to be passed to the quantizer. 31 | * For two-pass color quantization, we need a full-image buffer; 32 | * for one-pass operation, a strip buffer is sufficient. 33 | */ 34 | jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */ 35 | JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */ 36 | JDIMENSION strip_height; /* buffer size in rows */ 37 | /* for two-pass mode only: */ 38 | JDIMENSION starting_row; /* row # of first row in current strip */ 39 | JDIMENSION next_row; /* index of next row to fill/empty in strip */ 40 | } my_post_controller; 41 | 42 | typedef my_post_controller * my_post_ptr; 43 | 44 | 45 | /* Forward declarations */ 46 | METHODDEF(void) post_process_1pass 47 | JPP((j_decompress_ptr cinfo, 48 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 49 | JDIMENSION in_row_groups_avail, 50 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 51 | JDIMENSION out_rows_avail)); 52 | #ifdef QUANT_2PASS_SUPPORTED 53 | METHODDEF(void) post_process_prepass 54 | JPP((j_decompress_ptr cinfo, 55 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 56 | JDIMENSION in_row_groups_avail, 57 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 58 | JDIMENSION out_rows_avail)); 59 | METHODDEF(void) post_process_2pass 60 | JPP((j_decompress_ptr cinfo, 61 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 62 | JDIMENSION in_row_groups_avail, 63 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 64 | JDIMENSION out_rows_avail)); 65 | #endif 66 | 67 | 68 | /* 69 | * Initialize for a processing pass. 70 | */ 71 | 72 | METHODDEF(void) 73 | start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode) 74 | { 75 | my_post_ptr post = (my_post_ptr) cinfo->post; 76 | 77 | switch (pass_mode) { 78 | case JBUF_PASS_THRU: 79 | if (cinfo->quantize_colors) { 80 | /* Single-pass processing with color quantization. */ 81 | post->pub.post_process_data = post_process_1pass; 82 | /* We could be doing buffered-image output before starting a 2-pass 83 | * color quantization; in that case, jinit_d_post_controller did not 84 | * allocate a strip buffer. Use the virtual-array buffer as workspace. 85 | */ 86 | if (post->buffer == NULL) { 87 | post->buffer = (*cinfo->mem->access_virt_sarray) 88 | ((j_common_ptr) cinfo, post->whole_image, 89 | (JDIMENSION) 0, post->strip_height, TRUE); 90 | } 91 | } else { 92 | /* For single-pass processing without color quantization, 93 | * I have no work to do; just call the upsampler directly. 94 | */ 95 | post->pub.post_process_data = cinfo->upsample->upsample; 96 | } 97 | break; 98 | #ifdef QUANT_2PASS_SUPPORTED 99 | case JBUF_SAVE_AND_PASS: 100 | /* First pass of 2-pass quantization */ 101 | if (post->whole_image == NULL) 102 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 103 | post->pub.post_process_data = post_process_prepass; 104 | break; 105 | case JBUF_CRANK_DEST: 106 | /* Second pass of 2-pass quantization */ 107 | if (post->whole_image == NULL) 108 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 109 | post->pub.post_process_data = post_process_2pass; 110 | break; 111 | #endif /* QUANT_2PASS_SUPPORTED */ 112 | default: 113 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 114 | break; 115 | } 116 | post->starting_row = post->next_row = 0; 117 | } 118 | 119 | 120 | /* 121 | * Process some data in the one-pass (strip buffer) case. 122 | * This is used for color precision reduction as well as one-pass quantization. 123 | */ 124 | 125 | METHODDEF(void) 126 | post_process_1pass (j_decompress_ptr cinfo, 127 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 128 | JDIMENSION in_row_groups_avail, 129 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 130 | JDIMENSION out_rows_avail) 131 | { 132 | my_post_ptr post = (my_post_ptr) cinfo->post; 133 | JDIMENSION num_rows, max_rows; 134 | 135 | /* Fill the buffer, but not more than what we can dump out in one go. */ 136 | /* Note we rely on the upsampler to detect bottom of image. */ 137 | max_rows = out_rows_avail - *out_row_ctr; 138 | if (max_rows > post->strip_height) 139 | max_rows = post->strip_height; 140 | num_rows = 0; 141 | (*cinfo->upsample->upsample) (cinfo, 142 | input_buf, in_row_group_ctr, in_row_groups_avail, 143 | post->buffer, &num_rows, max_rows); 144 | /* Quantize and emit data. */ 145 | (*cinfo->cquantize->color_quantize) (cinfo, 146 | post->buffer, output_buf + *out_row_ctr, (int) num_rows); 147 | *out_row_ctr += num_rows; 148 | } 149 | 150 | 151 | #ifdef QUANT_2PASS_SUPPORTED 152 | 153 | /* 154 | * Process some data in the first pass of 2-pass quantization. 155 | */ 156 | 157 | METHODDEF(void) 158 | post_process_prepass (j_decompress_ptr cinfo, 159 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 160 | JDIMENSION in_row_groups_avail, 161 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 162 | JDIMENSION out_rows_avail) 163 | { 164 | my_post_ptr post = (my_post_ptr) cinfo->post; 165 | JDIMENSION old_next_row, num_rows; 166 | 167 | /* Reposition virtual buffer if at start of strip. */ 168 | if (post->next_row == 0) { 169 | post->buffer = (*cinfo->mem->access_virt_sarray) 170 | ((j_common_ptr) cinfo, post->whole_image, 171 | post->starting_row, post->strip_height, TRUE); 172 | } 173 | 174 | /* Upsample some data (up to a strip height's worth). */ 175 | old_next_row = post->next_row; 176 | (*cinfo->upsample->upsample) (cinfo, 177 | input_buf, in_row_group_ctr, in_row_groups_avail, 178 | post->buffer, &post->next_row, post->strip_height); 179 | 180 | /* Allow quantizer to scan new data. No data is emitted, */ 181 | /* but we advance out_row_ctr so outer loop can tell when we're done. */ 182 | if (post->next_row > old_next_row) { 183 | num_rows = post->next_row - old_next_row; 184 | (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row, 185 | (JSAMPARRAY) NULL, (int) num_rows); 186 | *out_row_ctr += num_rows; 187 | } 188 | 189 | /* Advance if we filled the strip. */ 190 | if (post->next_row >= post->strip_height) { 191 | post->starting_row += post->strip_height; 192 | post->next_row = 0; 193 | } 194 | } 195 | 196 | 197 | /* 198 | * Process some data in the second pass of 2-pass quantization. 199 | */ 200 | 201 | METHODDEF(void) 202 | post_process_2pass (j_decompress_ptr cinfo, 203 | JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, 204 | JDIMENSION in_row_groups_avail, 205 | JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, 206 | JDIMENSION out_rows_avail) 207 | { 208 | my_post_ptr post = (my_post_ptr) cinfo->post; 209 | JDIMENSION num_rows, max_rows; 210 | 211 | /* Reposition virtual buffer if at start of strip. */ 212 | if (post->next_row == 0) { 213 | post->buffer = (*cinfo->mem->access_virt_sarray) 214 | ((j_common_ptr) cinfo, post->whole_image, 215 | post->starting_row, post->strip_height, FALSE); 216 | } 217 | 218 | /* Determine number of rows to emit. */ 219 | num_rows = post->strip_height - post->next_row; /* available in strip */ 220 | max_rows = out_rows_avail - *out_row_ctr; /* available in output area */ 221 | if (num_rows > max_rows) 222 | num_rows = max_rows; 223 | /* We have to check bottom of image here, can't depend on upsampler. */ 224 | max_rows = cinfo->output_height - post->starting_row; 225 | if (num_rows > max_rows) 226 | num_rows = max_rows; 227 | 228 | /* Quantize and emit data. */ 229 | (*cinfo->cquantize->color_quantize) (cinfo, 230 | post->buffer + post->next_row, output_buf + *out_row_ctr, 231 | (int) num_rows); 232 | *out_row_ctr += num_rows; 233 | 234 | /* Advance if we filled the strip. */ 235 | post->next_row += num_rows; 236 | if (post->next_row >= post->strip_height) { 237 | post->starting_row += post->strip_height; 238 | post->next_row = 0; 239 | } 240 | } 241 | 242 | #endif /* QUANT_2PASS_SUPPORTED */ 243 | 244 | 245 | /* 246 | * Initialize postprocessing controller. 247 | */ 248 | 249 | GLOBAL(void) 250 | jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer) 251 | { 252 | my_post_ptr post; 253 | 254 | post = (my_post_ptr) 255 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 256 | SIZEOF(my_post_controller)); 257 | cinfo->post = (struct jpeg_d_post_controller *) post; 258 | post->pub.start_pass = start_pass_dpost; 259 | post->whole_image = NULL; /* flag for no virtual arrays */ 260 | post->buffer = NULL; /* flag for no strip buffer */ 261 | 262 | /* Create the quantization buffer, if needed */ 263 | if (cinfo->quantize_colors) { 264 | /* The buffer strip height is max_v_samp_factor, which is typically 265 | * an efficient number of rows for upsampling to return. 266 | * (In the presence of output rescaling, we might want to be smarter?) 267 | */ 268 | post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor; 269 | if (need_full_buffer) { 270 | /* Two-pass color quantization: need full-image storage. */ 271 | /* We round up the number of rows to a multiple of the strip height. */ 272 | #ifdef QUANT_2PASS_SUPPORTED 273 | post->whole_image = (*cinfo->mem->request_virt_sarray) 274 | ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, 275 | cinfo->output_width * cinfo->out_color_components, 276 | (JDIMENSION) jround_up((long) cinfo->output_height, 277 | (long) post->strip_height), 278 | post->strip_height); 279 | #else 280 | ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 281 | #endif /* QUANT_2PASS_SUPPORTED */ 282 | } else { 283 | /* One-pass color quantization: just make a strip buffer. */ 284 | post->buffer = (*cinfo->mem->alloc_sarray) 285 | ((j_common_ptr) cinfo, JPOOL_IMAGE, 286 | cinfo->output_width * cinfo->out_color_components, 287 | post->strip_height); 288 | } 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /src/libjpeg/jerror.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jerror.c 3 | * 4 | * Copyright (C) 1991-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains simple error-reporting and trace-message routines. 9 | * These are suitable for Unix-like systems and others where writing to 10 | * stderr is the right thing to do. Many applications will want to replace 11 | * some or all of these routines. 12 | * 13 | * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile, 14 | * you get a Windows-specific hack to display error messages in a dialog box. 15 | * It ain't much, but it beats dropping error messages into the bit bucket, 16 | * which is what happens to output to stderr under most Windows C compilers. 17 | * 18 | * These routines are used by both the compression and decompression code. 19 | */ 20 | 21 | /* this is not a core library module, so it doesn't define JPEG_INTERNALS */ 22 | #include "jinclude.h" 23 | #include "jpeglib.h" 24 | #include "jversion.h" 25 | #include "jerror.h" 26 | 27 | #ifdef USE_WINDOWS_MESSAGEBOX 28 | #include 29 | #endif 30 | 31 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ 32 | #define EXIT_FAILURE 1 33 | #endif 34 | 35 | 36 | /* 37 | * Create the message string table. 38 | * We do this from the master message list in jerror.h by re-reading 39 | * jerror.h with a suitable definition for macro JMESSAGE. 40 | * The message table is made an external symbol just in case any applications 41 | * want to refer to it directly. 42 | */ 43 | 44 | #ifdef NEED_SHORT_EXTERNAL_NAMES 45 | #define jpeg_std_message_table jMsgTable 46 | #endif 47 | 48 | #define JMESSAGE(code,string) string , 49 | 50 | const char * const jpeg_std_message_table[] = { 51 | #include "jerror.h" 52 | NULL 53 | }; 54 | 55 | 56 | /* 57 | * Error exit handler: must not return to caller. 58 | * 59 | * Applications may override this if they want to get control back after 60 | * an error. Typically one would longjmp somewhere instead of exiting. 61 | * The setjmp buffer can be made a private field within an expanded error 62 | * handler object. Note that the info needed to generate an error message 63 | * is stored in the error object, so you can generate the message now or 64 | * later, at your convenience. 65 | * You should make sure that the JPEG object is cleaned up (with jpeg_abort 66 | * or jpeg_destroy) at some point. 67 | */ 68 | 69 | METHODDEF(void) 70 | error_exit (j_common_ptr cinfo) 71 | { 72 | /* Always display the message */ 73 | (*cinfo->err->output_message) (cinfo); 74 | 75 | /* Let the memory manager delete any temp files before we die */ 76 | jpeg_destroy(cinfo); 77 | 78 | exit(EXIT_FAILURE); 79 | } 80 | 81 | 82 | /* 83 | * Actual output of an error or trace message. 84 | * Applications may override this method to send JPEG messages somewhere 85 | * other than stderr. 86 | * 87 | * On Windows, printing to stderr is generally completely useless, 88 | * so we provide optional code to produce an error-dialog popup. 89 | * Most Windows applications will still prefer to override this routine, 90 | * but if they don't, it'll do something at least marginally useful. 91 | * 92 | * NOTE: to use the library in an environment that doesn't support the 93 | * C stdio library, you may have to delete the call to fprintf() entirely, 94 | * not just not use this routine. 95 | */ 96 | 97 | METHODDEF(void) 98 | output_message (j_common_ptr cinfo) 99 | { 100 | char buffer[JMSG_LENGTH_MAX]; 101 | 102 | /* Create the message */ 103 | (*cinfo->err->format_message) (cinfo, buffer); 104 | 105 | #ifdef USE_WINDOWS_MESSAGEBOX 106 | /* Display it in a message dialog box */ 107 | MessageBox(GetActiveWindow(), buffer, "JPEG Library Error", 108 | MB_OK | MB_ICONERROR); 109 | #else 110 | /* Send it to stderr, adding a newline */ 111 | fprintf(stderr, "%s\n", buffer); 112 | #endif 113 | } 114 | 115 | 116 | /* 117 | * Decide whether to emit a trace or warning message. 118 | * msg_level is one of: 119 | * -1: recoverable corrupt-data warning, may want to abort. 120 | * 0: important advisory messages (always display to user). 121 | * 1: first level of tracing detail. 122 | * 2,3,...: successively more detailed tracing messages. 123 | * An application might override this method if it wanted to abort on warnings 124 | * or change the policy about which messages to display. 125 | */ 126 | 127 | METHODDEF(void) 128 | emit_message (j_common_ptr cinfo, int msg_level) 129 | { 130 | struct jpeg_error_mgr * err = cinfo->err; 131 | 132 | if (msg_level < 0) { 133 | /* It's a warning message. Since corrupt files may generate many warnings, 134 | * the policy implemented here is to show only the first warning, 135 | * unless trace_level >= 3. 136 | */ 137 | if (err->num_warnings == 0 || err->trace_level >= 3) 138 | (*err->output_message) (cinfo); 139 | /* Always count warnings in num_warnings. */ 140 | err->num_warnings++; 141 | } else { 142 | /* It's a trace message. Show it if trace_level >= msg_level. */ 143 | if (err->trace_level >= msg_level) 144 | (*err->output_message) (cinfo); 145 | } 146 | } 147 | 148 | 149 | /* 150 | * Format a message string for the most recent JPEG error or message. 151 | * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX 152 | * characters. Note that no '\n' character is added to the string. 153 | * Few applications should need to override this method. 154 | */ 155 | 156 | METHODDEF(void) 157 | format_message (j_common_ptr cinfo, char * buffer) 158 | { 159 | struct jpeg_error_mgr * err = cinfo->err; 160 | int msg_code = err->msg_code; 161 | const char * msgtext = NULL; 162 | const char * msgptr; 163 | char ch; 164 | boolean isstring; 165 | 166 | /* Look up message string in proper table */ 167 | if (msg_code > 0 && msg_code <= err->last_jpeg_message) { 168 | msgtext = err->jpeg_message_table[msg_code]; 169 | } else if (err->addon_message_table != NULL && 170 | msg_code >= err->first_addon_message && 171 | msg_code <= err->last_addon_message) { 172 | msgtext = err->addon_message_table[msg_code - err->first_addon_message]; 173 | } 174 | 175 | /* Defend against bogus message number */ 176 | if (msgtext == NULL) { 177 | err->msg_parm.i[0] = msg_code; 178 | msgtext = err->jpeg_message_table[0]; 179 | } 180 | 181 | /* Check for string parameter, as indicated by %s in the message text */ 182 | isstring = FALSE; 183 | msgptr = msgtext; 184 | while ((ch = *msgptr++) != '\0') { 185 | if (ch == '%') { 186 | if (*msgptr == 's') isstring = TRUE; 187 | break; 188 | } 189 | } 190 | 191 | /* Format the message into the passed buffer */ 192 | if (isstring) 193 | sprintf(buffer, msgtext, err->msg_parm.s); 194 | else 195 | sprintf(buffer, msgtext, 196 | err->msg_parm.i[0], err->msg_parm.i[1], 197 | err->msg_parm.i[2], err->msg_parm.i[3], 198 | err->msg_parm.i[4], err->msg_parm.i[5], 199 | err->msg_parm.i[6], err->msg_parm.i[7]); 200 | } 201 | 202 | 203 | /* 204 | * Reset error state variables at start of a new image. 205 | * This is called during compression startup to reset trace/error 206 | * processing to default state, without losing any application-specific 207 | * method pointers. An application might possibly want to override 208 | * this method if it has additional error processing state. 209 | */ 210 | 211 | METHODDEF(void) 212 | reset_error_mgr (j_common_ptr cinfo) 213 | { 214 | cinfo->err->num_warnings = 0; 215 | /* trace_level is not reset since it is an application-supplied parameter */ 216 | cinfo->err->msg_code = 0; /* may be useful as a flag for "no error" */ 217 | } 218 | 219 | 220 | /* 221 | * Fill in the standard error-handling methods in a jpeg_error_mgr object. 222 | * Typical call is: 223 | * struct jpeg_compress_struct cinfo; 224 | * struct jpeg_error_mgr err; 225 | * 226 | * cinfo.err = jpeg_std_error(&err); 227 | * after which the application may override some of the methods. 228 | */ 229 | 230 | GLOBAL(struct jpeg_error_mgr *) 231 | jpeg_std_error (struct jpeg_error_mgr * err) 232 | { 233 | err->error_exit = error_exit; 234 | err->emit_message = emit_message; 235 | err->output_message = output_message; 236 | err->format_message = format_message; 237 | err->reset_error_mgr = reset_error_mgr; 238 | 239 | err->trace_level = 0; /* default = no tracing */ 240 | err->num_warnings = 0; /* no warnings emitted yet */ 241 | err->msg_code = 0; /* may be useful as a flag for "no error" */ 242 | 243 | /* Initialize message table pointers */ 244 | err->jpeg_message_table = jpeg_std_message_table; 245 | err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1; 246 | 247 | err->addon_message_table = NULL; 248 | err->first_addon_message = 0; /* for safety */ 249 | err->last_addon_message = 0; 250 | 251 | return err; 252 | } 253 | -------------------------------------------------------------------------------- /src/libjpeg/jerror.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jerror.h 3 | * 4 | * Copyright (C) 1994-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file defines the error and message codes for the JPEG library. 9 | * Edit this file to add new codes, or to translate the message strings to 10 | * some other language. 11 | * A set of error-reporting macros are defined too. Some applications using 12 | * the JPEG library may wish to include this file to get the error codes 13 | * and/or the macros. 14 | */ 15 | 16 | /* 17 | * To define the enum list of message codes, include this file without 18 | * defining macro JMESSAGE. To create a message string table, include it 19 | * again with a suitable JMESSAGE definition (see jerror.c for an example). 20 | */ 21 | #ifndef JMESSAGE 22 | #ifndef JERROR_H 23 | /* First time through, define the enum list */ 24 | #define JMAKE_ENUM_LIST 25 | #else 26 | /* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */ 27 | #define JMESSAGE(code,string) 28 | #endif /* JERROR_H */ 29 | #endif /* JMESSAGE */ 30 | 31 | #ifdef JMAKE_ENUM_LIST 32 | 33 | typedef enum { 34 | 35 | #define JMESSAGE(code,string) code , 36 | 37 | #endif /* JMAKE_ENUM_LIST */ 38 | 39 | JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */ 40 | 41 | /* For maintenance convenience, list is alphabetical by message code name */ 42 | JMESSAGE(JERR_ARITH_NOTIMPL, 43 | "Sorry, there are legal restrictions on arithmetic coding") 44 | JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix") 45 | JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix") 46 | JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode") 47 | JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS") 48 | JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range") 49 | JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported") 50 | JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition") 51 | JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace") 52 | JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace") 53 | JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length") 54 | JMESSAGE(JERR_BAD_LIB_VERSION, 55 | "Wrong JPEG library version: library is %d, caller expects %d") 56 | JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan") 57 | JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d") 58 | JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d") 59 | JMESSAGE(JERR_BAD_PROGRESSION, 60 | "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d") 61 | JMESSAGE(JERR_BAD_PROG_SCRIPT, 62 | "Invalid progressive parameters at scan script entry %d") 63 | JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors") 64 | JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d") 65 | JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d") 66 | JMESSAGE(JERR_BAD_STRUCT_SIZE, 67 | "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u") 68 | JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access") 69 | JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small") 70 | JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here") 71 | JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet") 72 | JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d") 73 | JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request") 74 | JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d") 75 | JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x") 76 | JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d") 77 | JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d") 78 | JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)") 79 | JMESSAGE(JERR_EMS_READ, "Read from EMS failed") 80 | JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed") 81 | JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan") 82 | JMESSAGE(JERR_FILE_READ, "Input file read error") 83 | JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?") 84 | JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet") 85 | JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow") 86 | JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry") 87 | JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels") 88 | JMESSAGE(JERR_INPUT_EMPTY, "Empty input file") 89 | JMESSAGE(JERR_INPUT_EOF, "Premature end of input file") 90 | JMESSAGE(JERR_MISMATCHED_QUANT_TABLE, 91 | "Cannot transcode due to multiple use of quantization table %d") 92 | JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data") 93 | JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change") 94 | JMESSAGE(JERR_NOTIMPL, "Not implemented yet") 95 | JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time") 96 | JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported") 97 | JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined") 98 | JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image") 99 | JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined") 100 | JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x") 101 | JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)") 102 | JMESSAGE(JERR_QUANT_COMPONENTS, 103 | "Cannot quantize more than %d color components") 104 | JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors") 105 | JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors") 106 | JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers") 107 | JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker") 108 | JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x") 109 | JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers") 110 | JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF") 111 | JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s") 112 | JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file") 113 | JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file") 114 | JMESSAGE(JERR_TFILE_WRITE, 115 | "Write failed on temporary file --- out of disk space?") 116 | JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines") 117 | JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x") 118 | JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up") 119 | JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation") 120 | JMESSAGE(JERR_XMS_READ, "Read from XMS failed") 121 | JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed") 122 | JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT) 123 | JMESSAGE(JMSG_VERSION, JVERSION) 124 | JMESSAGE(JTRC_16BIT_TABLES, 125 | "Caution: quantization tables are too coarse for baseline JPEG") 126 | JMESSAGE(JTRC_ADOBE, 127 | "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d") 128 | JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u") 129 | JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u") 130 | JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x") 131 | JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x") 132 | JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d") 133 | JMESSAGE(JTRC_DRI, "Define Restart Interval %u") 134 | JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u") 135 | JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u") 136 | JMESSAGE(JTRC_EOI, "End Of Image") 137 | JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d") 138 | JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d") 139 | JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE, 140 | "Warning: thumbnail image size does not match data length %u") 141 | JMESSAGE(JTRC_JFIF_EXTENSION, 142 | "JFIF extension marker: type 0x%02x, length %u") 143 | JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image") 144 | JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u") 145 | JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x") 146 | JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u") 147 | JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors") 148 | JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors") 149 | JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization") 150 | JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d") 151 | JMESSAGE(JTRC_RST, "RST%d") 152 | JMESSAGE(JTRC_SMOOTH_NOTIMPL, 153 | "Smoothing not supported with nonstandard sampling ratios") 154 | JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d") 155 | JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d") 156 | JMESSAGE(JTRC_SOI, "Start of Image") 157 | JMESSAGE(JTRC_SOS, "Start Of Scan: %d components") 158 | JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d") 159 | JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d") 160 | JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s") 161 | JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s") 162 | JMESSAGE(JTRC_THUMB_JPEG, 163 | "JFIF extension marker: JPEG-compressed thumbnail image, length %u") 164 | JMESSAGE(JTRC_THUMB_PALETTE, 165 | "JFIF extension marker: palette thumbnail image, length %u") 166 | JMESSAGE(JTRC_THUMB_RGB, 167 | "JFIF extension marker: RGB thumbnail image, length %u") 168 | JMESSAGE(JTRC_UNKNOWN_IDS, 169 | "Unrecognized component IDs %d %d %d, assuming YCbCr") 170 | JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u") 171 | JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u") 172 | JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d") 173 | JMESSAGE(JWRN_BOGUS_PROGRESSION, 174 | "Inconsistent progression sequence for component %d coefficient %d") 175 | JMESSAGE(JWRN_EXTRANEOUS_DATA, 176 | "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x") 177 | JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment") 178 | JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code") 179 | JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d") 180 | JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file") 181 | JMESSAGE(JWRN_MUST_RESYNC, 182 | "Corrupt JPEG data: found marker 0x%02x instead of RST%d") 183 | JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG") 184 | JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines") 185 | 186 | #ifdef JMAKE_ENUM_LIST 187 | 188 | JMSG_LASTMSGCODE 189 | } J_MESSAGE_CODE; 190 | 191 | #undef JMAKE_ENUM_LIST 192 | #endif /* JMAKE_ENUM_LIST */ 193 | 194 | /* Zap JMESSAGE macro so that future re-inclusions do nothing by default */ 195 | #undef JMESSAGE 196 | 197 | 198 | #ifndef JERROR_H 199 | #define JERROR_H 200 | 201 | /* Macros to simplify using the error and trace message stuff */ 202 | /* The first parameter is either type of cinfo pointer */ 203 | 204 | /* Fatal errors (print message and exit) */ 205 | #define ERREXIT(cinfo,code) \ 206 | ((cinfo)->err->msg_code = (code), \ 207 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 208 | #define ERREXIT1(cinfo,code,p1) \ 209 | ((cinfo)->err->msg_code = (code), \ 210 | (cinfo)->err->msg_parm.i[0] = (p1), \ 211 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 212 | #define ERREXIT2(cinfo,code,p1,p2) \ 213 | ((cinfo)->err->msg_code = (code), \ 214 | (cinfo)->err->msg_parm.i[0] = (p1), \ 215 | (cinfo)->err->msg_parm.i[1] = (p2), \ 216 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 217 | #define ERREXIT3(cinfo,code,p1,p2,p3) \ 218 | ((cinfo)->err->msg_code = (code), \ 219 | (cinfo)->err->msg_parm.i[0] = (p1), \ 220 | (cinfo)->err->msg_parm.i[1] = (p2), \ 221 | (cinfo)->err->msg_parm.i[2] = (p3), \ 222 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 223 | #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \ 224 | ((cinfo)->err->msg_code = (code), \ 225 | (cinfo)->err->msg_parm.i[0] = (p1), \ 226 | (cinfo)->err->msg_parm.i[1] = (p2), \ 227 | (cinfo)->err->msg_parm.i[2] = (p3), \ 228 | (cinfo)->err->msg_parm.i[3] = (p4), \ 229 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 230 | #define ERREXITS(cinfo,code,str) \ 231 | ((cinfo)->err->msg_code = (code), \ 232 | strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ 233 | (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo))) 234 | 235 | #define MAKESTMT(stuff) do { stuff } while (0) 236 | 237 | /* Nonfatal errors (we can keep going, but the data is probably corrupt) */ 238 | #define WARNMS(cinfo,code) \ 239 | ((cinfo)->err->msg_code = (code), \ 240 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) 241 | #define WARNMS1(cinfo,code,p1) \ 242 | ((cinfo)->err->msg_code = (code), \ 243 | (cinfo)->err->msg_parm.i[0] = (p1), \ 244 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) 245 | #define WARNMS2(cinfo,code,p1,p2) \ 246 | ((cinfo)->err->msg_code = (code), \ 247 | (cinfo)->err->msg_parm.i[0] = (p1), \ 248 | (cinfo)->err->msg_parm.i[1] = (p2), \ 249 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1)) 250 | 251 | /* Informational/debugging messages */ 252 | #define TRACEMS(cinfo,lvl,code) \ 253 | ((cinfo)->err->msg_code = (code), \ 254 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 255 | #define TRACEMS1(cinfo,lvl,code,p1) \ 256 | ((cinfo)->err->msg_code = (code), \ 257 | (cinfo)->err->msg_parm.i[0] = (p1), \ 258 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 259 | #define TRACEMS2(cinfo,lvl,code,p1,p2) \ 260 | ((cinfo)->err->msg_code = (code), \ 261 | (cinfo)->err->msg_parm.i[0] = (p1), \ 262 | (cinfo)->err->msg_parm.i[1] = (p2), \ 263 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 264 | #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \ 265 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 266 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \ 267 | (cinfo)->err->msg_code = (code); \ 268 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 269 | #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \ 270 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 271 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ 272 | (cinfo)->err->msg_code = (code); \ 273 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 274 | #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \ 275 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 276 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ 277 | _mp[4] = (p5); \ 278 | (cinfo)->err->msg_code = (code); \ 279 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 280 | #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \ 281 | MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \ 282 | _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \ 283 | _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \ 284 | (cinfo)->err->msg_code = (code); \ 285 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); ) 286 | #define TRACEMSS(cinfo,lvl,code,str) \ 287 | ((cinfo)->err->msg_code = (code), \ 288 | strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \ 289 | (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl))) 290 | 291 | #endif /* JERROR_H */ 292 | -------------------------------------------------------------------------------- /src/libjpeg/jidctflt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jidctflt.c 3 | * 4 | * Copyright (C) 1994-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains a floating-point implementation of the 9 | * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine 10 | * must also perform dequantization of the input coefficients. 11 | * 12 | * This implementation should be more accurate than either of the integer 13 | * IDCT implementations. However, it may not give the same results on all 14 | * machines because of differences in roundoff behavior. Speed will depend 15 | * on the hardware's floating point capacity. 16 | * 17 | * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT 18 | * on each row (or vice versa, but it's more convenient to emit a row at 19 | * a time). Direct algorithms are also available, but they are much more 20 | * complex and seem not to be any faster when reduced to code. 21 | * 22 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for 23 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 24 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell 25 | * JPEG textbook (see REFERENCES section in file README). The following code 26 | * is based directly on figure 4-8 in P&M. 27 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is 28 | * possible to arrange the computation so that many of the multiplies are 29 | * simple scalings of the final outputs. These multiplies can then be 30 | * folded into the multiplications or divisions by the JPEG quantization 31 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds 32 | * to be done in the DCT itself. 33 | * The primary disadvantage of this method is that with a fixed-point 34 | * implementation, accuracy is lost due to imprecise representation of the 35 | * scaled quantization values. However, that problem does not arise if 36 | * we use floating point arithmetic. 37 | */ 38 | 39 | #define JPEG_INTERNALS 40 | #include "jinclude.h" 41 | #include "jpeglib.h" 42 | #include "jdct.h" /* Private declarations for DCT subsystem */ 43 | 44 | #ifdef DCT_FLOAT_SUPPORTED 45 | 46 | 47 | /* 48 | * This module is specialized to the case DCTSIZE = 8. 49 | */ 50 | 51 | #if DCTSIZE != 8 52 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 53 | #endif 54 | 55 | 56 | /* Dequantize a coefficient by multiplying it by the multiplier-table 57 | * entry; produce a float result. 58 | */ 59 | 60 | #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval)) 61 | 62 | 63 | /* 64 | * Perform dequantization and inverse DCT on one block of coefficients. 65 | */ 66 | 67 | GLOBAL(void) 68 | jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, 69 | JCOEFPTR coef_block, 70 | JSAMPARRAY output_buf, JDIMENSION output_col) 71 | { 72 | FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 73 | FAST_FLOAT tmp10, tmp11, tmp12, tmp13; 74 | FAST_FLOAT z5, z10, z11, z12, z13; 75 | JCOEFPTR inptr; 76 | FLOAT_MULT_TYPE * quantptr; 77 | FAST_FLOAT * wsptr; 78 | JSAMPROW outptr; 79 | JSAMPLE *range_limit = IDCT_range_limit(cinfo); 80 | int ctr; 81 | FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ 82 | SHIFT_TEMPS 83 | 84 | /* Pass 1: process columns from input, store into work array. */ 85 | 86 | inptr = coef_block; 87 | quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table; 88 | wsptr = workspace; 89 | for (ctr = DCTSIZE; ctr > 0; ctr--) { 90 | /* Due to quantization, we will usually find that many of the input 91 | * coefficients are zero, especially the AC terms. We can exploit this 92 | * by short-circuiting the IDCT calculation for any column in which all 93 | * the AC terms are zero. In that case each output is equal to the 94 | * DC coefficient (with scale factor as needed). 95 | * With typical images and quantization tables, half or more of the 96 | * column DCT calculations can be simplified this way. 97 | */ 98 | 99 | if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && 100 | inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && 101 | inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && 102 | inptr[DCTSIZE*7] == 0) { 103 | /* AC terms all zero */ 104 | FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 105 | 106 | wsptr[DCTSIZE*0] = dcval; 107 | wsptr[DCTSIZE*1] = dcval; 108 | wsptr[DCTSIZE*2] = dcval; 109 | wsptr[DCTSIZE*3] = dcval; 110 | wsptr[DCTSIZE*4] = dcval; 111 | wsptr[DCTSIZE*5] = dcval; 112 | wsptr[DCTSIZE*6] = dcval; 113 | wsptr[DCTSIZE*7] = dcval; 114 | 115 | inptr++; /* advance pointers to next column */ 116 | quantptr++; 117 | wsptr++; 118 | continue; 119 | } 120 | 121 | /* Even part */ 122 | 123 | tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 124 | tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); 125 | tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); 126 | tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); 127 | 128 | tmp10 = tmp0 + tmp2; /* phase 3 */ 129 | tmp11 = tmp0 - tmp2; 130 | 131 | tmp13 = tmp1 + tmp3; /* phases 5-3 */ 132 | tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ 133 | 134 | tmp0 = tmp10 + tmp13; /* phase 2 */ 135 | tmp3 = tmp10 - tmp13; 136 | tmp1 = tmp11 + tmp12; 137 | tmp2 = tmp11 - tmp12; 138 | 139 | /* Odd part */ 140 | 141 | tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); 142 | tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); 143 | tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); 144 | tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); 145 | 146 | z13 = tmp6 + tmp5; /* phase 6 */ 147 | z10 = tmp6 - tmp5; 148 | z11 = tmp4 + tmp7; 149 | z12 = tmp4 - tmp7; 150 | 151 | tmp7 = z11 + z13; /* phase 5 */ 152 | tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ 153 | 154 | z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 155 | tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ 156 | tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ 157 | 158 | tmp6 = tmp12 - tmp7; /* phase 2 */ 159 | tmp5 = tmp11 - tmp6; 160 | tmp4 = tmp10 + tmp5; 161 | 162 | wsptr[DCTSIZE*0] = tmp0 + tmp7; 163 | wsptr[DCTSIZE*7] = tmp0 - tmp7; 164 | wsptr[DCTSIZE*1] = tmp1 + tmp6; 165 | wsptr[DCTSIZE*6] = tmp1 - tmp6; 166 | wsptr[DCTSIZE*2] = tmp2 + tmp5; 167 | wsptr[DCTSIZE*5] = tmp2 - tmp5; 168 | wsptr[DCTSIZE*4] = tmp3 + tmp4; 169 | wsptr[DCTSIZE*3] = tmp3 - tmp4; 170 | 171 | inptr++; /* advance pointers to next column */ 172 | quantptr++; 173 | wsptr++; 174 | } 175 | 176 | /* Pass 2: process rows from work array, store into output array. */ 177 | /* Note that we must descale the results by a factor of 8 == 2**3. */ 178 | 179 | wsptr = workspace; 180 | for (ctr = 0; ctr < DCTSIZE; ctr++) { 181 | outptr = output_buf[ctr] + output_col; 182 | /* Rows of zeroes can be exploited in the same way as we did with columns. 183 | * However, the column calculation has created many nonzero AC terms, so 184 | * the simplification applies less often (typically 5% to 10% of the time). 185 | * And testing floats for zero is relatively expensive, so we don't bother. 186 | */ 187 | 188 | /* Even part */ 189 | 190 | tmp10 = wsptr[0] + wsptr[4]; 191 | tmp11 = wsptr[0] - wsptr[4]; 192 | 193 | tmp13 = wsptr[2] + wsptr[6]; 194 | tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13; 195 | 196 | tmp0 = tmp10 + tmp13; 197 | tmp3 = tmp10 - tmp13; 198 | tmp1 = tmp11 + tmp12; 199 | tmp2 = tmp11 - tmp12; 200 | 201 | /* Odd part */ 202 | 203 | z13 = wsptr[5] + wsptr[3]; 204 | z10 = wsptr[5] - wsptr[3]; 205 | z11 = wsptr[1] + wsptr[7]; 206 | z12 = wsptr[1] - wsptr[7]; 207 | 208 | tmp7 = z11 + z13; 209 | tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); 210 | 211 | z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 212 | tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ 213 | tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ 214 | 215 | tmp6 = tmp12 - tmp7; 216 | tmp5 = tmp11 - tmp6; 217 | tmp4 = tmp10 + tmp5; 218 | 219 | /* Final output stage: scale down by a factor of 8 and range-limit */ 220 | 221 | outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3) 222 | & RANGE_MASK]; 223 | outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3) 224 | & RANGE_MASK]; 225 | outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3) 226 | & RANGE_MASK]; 227 | outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3) 228 | & RANGE_MASK]; 229 | outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3) 230 | & RANGE_MASK]; 231 | outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3) 232 | & RANGE_MASK]; 233 | outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3) 234 | & RANGE_MASK]; 235 | outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3) 236 | & RANGE_MASK]; 237 | 238 | wsptr += DCTSIZE; /* advance pointer to next row */ 239 | } 240 | } 241 | 242 | #endif /* DCT_FLOAT_SUPPORTED */ 243 | -------------------------------------------------------------------------------- /src/libjpeg/jidctfst.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jidctfst.c 3 | * 4 | * Copyright (C) 1994-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains a fast, not so accurate integer implementation of the 9 | * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine 10 | * must also perform dequantization of the input coefficients. 11 | * 12 | * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT 13 | * on each row (or vice versa, but it's more convenient to emit a row at 14 | * a time). Direct algorithms are also available, but they are much more 15 | * complex and seem not to be any faster when reduced to code. 16 | * 17 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for 18 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 19 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell 20 | * JPEG textbook (see REFERENCES section in file README). The following code 21 | * is based directly on figure 4-8 in P&M. 22 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is 23 | * possible to arrange the computation so that many of the multiplies are 24 | * simple scalings of the final outputs. These multiplies can then be 25 | * folded into the multiplications or divisions by the JPEG quantization 26 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds 27 | * to be done in the DCT itself. 28 | * The primary disadvantage of this method is that with fixed-point math, 29 | * accuracy is lost due to imprecise representation of the scaled 30 | * quantization values. The smaller the quantization table entry, the less 31 | * precise the scaled value, so this implementation does worse with high- 32 | * quality-setting files than with low-quality ones. 33 | */ 34 | 35 | #define JPEG_INTERNALS 36 | #include "jinclude.h" 37 | #include "jpeglib.h" 38 | #include "jdct.h" /* Private declarations for DCT subsystem */ 39 | 40 | #ifdef DCT_IFAST_SUPPORTED 41 | 42 | 43 | /* 44 | * This module is specialized to the case DCTSIZE = 8. 45 | */ 46 | 47 | #if DCTSIZE != 8 48 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 49 | #endif 50 | 51 | 52 | /* Scaling decisions are generally the same as in the LL&M algorithm; 53 | * see jidctint.c for more details. However, we choose to descale 54 | * (right shift) multiplication products as soon as they are formed, 55 | * rather than carrying additional fractional bits into subsequent additions. 56 | * This compromises accuracy slightly, but it lets us save a few shifts. 57 | * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) 58 | * everywhere except in the multiplications proper; this saves a good deal 59 | * of work on 16-bit-int machines. 60 | * 61 | * The dequantized coefficients are not integers because the AA&N scaling 62 | * factors have been incorporated. We represent them scaled up by PASS1_BITS, 63 | * so that the first and second IDCT rounds have the same input scaling. 64 | * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to 65 | * avoid a descaling shift; this compromises accuracy rather drastically 66 | * for small quantization table entries, but it saves a lot of shifts. 67 | * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway, 68 | * so we use a much larger scaling factor to preserve accuracy. 69 | * 70 | * A final compromise is to represent the multiplicative constants to only 71 | * 8 fractional bits, rather than 13. This saves some shifting work on some 72 | * machines, and may also reduce the cost of multiplication (since there 73 | * are fewer one-bits in the constants). 74 | */ 75 | 76 | #if BITS_IN_JSAMPLE == 8 77 | #define CONST_BITS 8 78 | #define PASS1_BITS 2 79 | #else 80 | #define CONST_BITS 8 81 | #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ 82 | #endif 83 | 84 | /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus 85 | * causing a lot of useless floating-point operations at run time. 86 | * To get around this we use the following pre-calculated constants. 87 | * If you change CONST_BITS you may want to add appropriate values. 88 | * (With a reasonable C compiler, you can just rely on the FIX() macro...) 89 | */ 90 | 91 | #if CONST_BITS == 8 92 | #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ 93 | #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ 94 | #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ 95 | #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ 96 | #else 97 | #define FIX_1_082392200 FIX(1.082392200) 98 | #define FIX_1_414213562 FIX(1.414213562) 99 | #define FIX_1_847759065 FIX(1.847759065) 100 | #define FIX_2_613125930 FIX(2.613125930) 101 | #endif 102 | 103 | 104 | /* We can gain a little more speed, with a further compromise in accuracy, 105 | * by omitting the addition in a descaling shift. This yields an incorrectly 106 | * rounded result half the time... 107 | */ 108 | 109 | #ifndef USE_ACCURATE_ROUNDING 110 | #undef DESCALE 111 | #define DESCALE(x,n) RIGHT_SHIFT(x, n) 112 | #endif 113 | 114 | 115 | /* Multiply a DCTELEM variable by an INT32 constant, and immediately 116 | * descale to yield a DCTELEM result. 117 | */ 118 | 119 | #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) 120 | 121 | 122 | /* Dequantize a coefficient by multiplying it by the multiplier-table 123 | * entry; produce a DCTELEM result. For 8-bit data a 16x16->16 124 | * multiplication will do. For 12-bit data, the multiplier table is 125 | * declared INT32, so a 32-bit multiply will be used. 126 | */ 127 | 128 | #if BITS_IN_JSAMPLE == 8 129 | #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) 130 | #else 131 | #define DEQUANTIZE(coef,quantval) \ 132 | DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) 133 | #endif 134 | 135 | 136 | /* Like DESCALE, but applies to a DCTELEM and produces an int. 137 | * We assume that int right shift is unsigned if INT32 right shift is. 138 | */ 139 | 140 | #ifdef RIGHT_SHIFT_IS_UNSIGNED 141 | #define ISHIFT_TEMPS DCTELEM ishift_temp; 142 | #if BITS_IN_JSAMPLE == 8 143 | #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */ 144 | #else 145 | #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */ 146 | #endif 147 | #define IRIGHT_SHIFT(x,shft) \ 148 | ((ishift_temp = (x)) < 0 ? \ 149 | (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \ 150 | (ishift_temp >> (shft))) 151 | #else 152 | #define ISHIFT_TEMPS 153 | #define IRIGHT_SHIFT(x,shft) ((x) >> (shft)) 154 | #endif 155 | 156 | #ifdef USE_ACCURATE_ROUNDING 157 | #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n)) 158 | #else 159 | #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n)) 160 | #endif 161 | 162 | 163 | /* 164 | * Perform dequantization and inverse DCT on one block of coefficients. 165 | */ 166 | 167 | GLOBAL(void) 168 | jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, 169 | JCOEFPTR coef_block, 170 | JSAMPARRAY output_buf, JDIMENSION output_col) 171 | { 172 | DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 173 | DCTELEM tmp10, tmp11, tmp12, tmp13; 174 | DCTELEM z5, z10, z11, z12, z13; 175 | JCOEFPTR inptr; 176 | IFAST_MULT_TYPE * quantptr; 177 | int * wsptr; 178 | JSAMPROW outptr; 179 | JSAMPLE *range_limit = IDCT_range_limit(cinfo); 180 | int ctr; 181 | int workspace[DCTSIZE2]; /* buffers data between passes */ 182 | SHIFT_TEMPS /* for DESCALE */ 183 | ISHIFT_TEMPS /* for IDESCALE */ 184 | 185 | /* Pass 1: process columns from input, store into work array. */ 186 | 187 | inptr = coef_block; 188 | quantptr = (IFAST_MULT_TYPE *) compptr->dct_table; 189 | wsptr = workspace; 190 | for (ctr = DCTSIZE; ctr > 0; ctr--) { 191 | /* Due to quantization, we will usually find that many of the input 192 | * coefficients are zero, especially the AC terms. We can exploit this 193 | * by short-circuiting the IDCT calculation for any column in which all 194 | * the AC terms are zero. In that case each output is equal to the 195 | * DC coefficient (with scale factor as needed). 196 | * With typical images and quantization tables, half or more of the 197 | * column DCT calculations can be simplified this way. 198 | */ 199 | 200 | if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && 201 | inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && 202 | inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && 203 | inptr[DCTSIZE*7] == 0) { 204 | /* AC terms all zero */ 205 | int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 206 | 207 | wsptr[DCTSIZE*0] = dcval; 208 | wsptr[DCTSIZE*1] = dcval; 209 | wsptr[DCTSIZE*2] = dcval; 210 | wsptr[DCTSIZE*3] = dcval; 211 | wsptr[DCTSIZE*4] = dcval; 212 | wsptr[DCTSIZE*5] = dcval; 213 | wsptr[DCTSIZE*6] = dcval; 214 | wsptr[DCTSIZE*7] = dcval; 215 | 216 | inptr++; /* advance pointers to next column */ 217 | quantptr++; 218 | wsptr++; 219 | continue; 220 | } 221 | 222 | /* Even part */ 223 | 224 | tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 225 | tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); 226 | tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); 227 | tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); 228 | 229 | tmp10 = tmp0 + tmp2; /* phase 3 */ 230 | tmp11 = tmp0 - tmp2; 231 | 232 | tmp13 = tmp1 + tmp3; /* phases 5-3 */ 233 | tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ 234 | 235 | tmp0 = tmp10 + tmp13; /* phase 2 */ 236 | tmp3 = tmp10 - tmp13; 237 | tmp1 = tmp11 + tmp12; 238 | tmp2 = tmp11 - tmp12; 239 | 240 | /* Odd part */ 241 | 242 | tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); 243 | tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); 244 | tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); 245 | tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); 246 | 247 | z13 = tmp6 + tmp5; /* phase 6 */ 248 | z10 = tmp6 - tmp5; 249 | z11 = tmp4 + tmp7; 250 | z12 = tmp4 - tmp7; 251 | 252 | tmp7 = z11 + z13; /* phase 5 */ 253 | tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ 254 | 255 | z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ 256 | tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ 257 | tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ 258 | 259 | tmp6 = tmp12 - tmp7; /* phase 2 */ 260 | tmp5 = tmp11 - tmp6; 261 | tmp4 = tmp10 + tmp5; 262 | 263 | wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7); 264 | wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7); 265 | wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6); 266 | wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6); 267 | wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5); 268 | wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5); 269 | wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4); 270 | wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4); 271 | 272 | inptr++; /* advance pointers to next column */ 273 | quantptr++; 274 | wsptr++; 275 | } 276 | 277 | /* Pass 2: process rows from work array, store into output array. */ 278 | /* Note that we must descale the results by a factor of 8 == 2**3, */ 279 | /* and also undo the PASS1_BITS scaling. */ 280 | 281 | wsptr = workspace; 282 | for (ctr = 0; ctr < DCTSIZE; ctr++) { 283 | outptr = output_buf[ctr] + output_col; 284 | /* Rows of zeroes can be exploited in the same way as we did with columns. 285 | * However, the column calculation has created many nonzero AC terms, so 286 | * the simplification applies less often (typically 5% to 10% of the time). 287 | * On machines with very fast multiplication, it's possible that the 288 | * test takes more time than it's worth. In that case this section 289 | * may be commented out. 290 | */ 291 | 292 | #ifndef NO_ZERO_ROW_TEST 293 | if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && 294 | wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { 295 | /* AC terms all zero */ 296 | JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3) 297 | & RANGE_MASK]; 298 | 299 | outptr[0] = dcval; 300 | outptr[1] = dcval; 301 | outptr[2] = dcval; 302 | outptr[3] = dcval; 303 | outptr[4] = dcval; 304 | outptr[5] = dcval; 305 | outptr[6] = dcval; 306 | outptr[7] = dcval; 307 | 308 | wsptr += DCTSIZE; /* advance pointer to next row */ 309 | continue; 310 | } 311 | #endif 312 | 313 | /* Even part */ 314 | 315 | tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]); 316 | tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]); 317 | 318 | tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]); 319 | tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562) 320 | - tmp13; 321 | 322 | tmp0 = tmp10 + tmp13; 323 | tmp3 = tmp10 - tmp13; 324 | tmp1 = tmp11 + tmp12; 325 | tmp2 = tmp11 - tmp12; 326 | 327 | /* Odd part */ 328 | 329 | z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3]; 330 | z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3]; 331 | z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; 332 | z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; 333 | 334 | tmp7 = z11 + z13; /* phase 5 */ 335 | tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ 336 | 337 | z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ 338 | tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */ 339 | tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */ 340 | 341 | tmp6 = tmp12 - tmp7; /* phase 2 */ 342 | tmp5 = tmp11 - tmp6; 343 | tmp4 = tmp10 + tmp5; 344 | 345 | /* Final output stage: scale down by a factor of 8 and range-limit */ 346 | 347 | outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3) 348 | & RANGE_MASK]; 349 | outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3) 350 | & RANGE_MASK]; 351 | outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3) 352 | & RANGE_MASK]; 353 | outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3) 354 | & RANGE_MASK]; 355 | outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3) 356 | & RANGE_MASK]; 357 | outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3) 358 | & RANGE_MASK]; 359 | outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3) 360 | & RANGE_MASK]; 361 | outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3) 362 | & RANGE_MASK]; 363 | 364 | wsptr += DCTSIZE; /* advance pointer to next row */ 365 | } 366 | } 367 | 368 | #endif /* DCT_IFAST_SUPPORTED */ 369 | -------------------------------------------------------------------------------- /src/libjpeg/jinclude.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jinclude.h 3 | * 4 | * Copyright (C) 1991-1994, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file exists to provide a single place to fix any problems with 9 | * including the wrong system include files. (Common problems are taken 10 | * care of by the standard jconfig symbols, but on really weird systems 11 | * you may have to edit this file.) 12 | * 13 | * NOTE: this file is NOT intended to be included by applications using the 14 | * JPEG library. Most applications need only include jpeglib.h. 15 | */ 16 | 17 | 18 | /* Include auto-config file to find out which system include files we need. */ 19 | 20 | #include "jconfig.h" /* auto configuration options */ 21 | #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */ 22 | 23 | /* 24 | * We need the NULL macro and size_t typedef. 25 | * On an ANSI-conforming system it is sufficient to include . 26 | * Otherwise, we get them from or ; we may have to 27 | * pull in as well. 28 | * Note that the core JPEG library does not require ; 29 | * only the default error handler and data source/destination modules do. 30 | * But we must pull it in because of the references to FILE in jpeglib.h. 31 | * You can remove those references if you want to compile without . 32 | */ 33 | #include "os.h" 34 | 35 | #ifdef HAVE_STDDEF_H 36 | #endif 37 | 38 | #ifdef HAVE_STDLIB_H 39 | #endif 40 | 41 | #ifdef NEED_SYS_TYPES_H 42 | #endif 43 | 44 | /* 45 | * We need memory copying and zeroing functions, plus strncpy(). 46 | * ANSI and System V implementations declare these in . 47 | * BSD doesn't have the mem() functions, but it does have bcopy()/bzero(). 48 | * Some systems may declare memset and memcpy in . 49 | * 50 | * NOTE: we assume the size parameters to these functions are of type size_t. 51 | * Change the casts in these macros if not! 52 | */ 53 | 54 | #ifdef NEED_BSD_STRINGS 55 | 56 | #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size)) 57 | #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size)) 58 | 59 | #else /* not BSD, assume ANSI/SysV string lib */ 60 | 61 | #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size)) 62 | #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size)) 63 | 64 | #endif 65 | 66 | /* 67 | * In ANSI C, and indeed any rational implementation, size_t is also the 68 | * type returned by sizeof(). However, it seems there are some irrational 69 | * implementations out there, in which sizeof() returns an int even though 70 | * size_t is defined as long or unsigned long. To ensure consistent results 71 | * we always use this SIZEOF() macro in place of using sizeof() directly. 72 | */ 73 | 74 | #define SIZEOF(object) ((size_t) sizeof(object)) 75 | 76 | /* 77 | * The modules that use fread() and fwrite() always invoke them through 78 | * these macros. On some systems you may need to twiddle the argument casts. 79 | * CAUTION: argument order is different from underlying functions! 80 | */ 81 | 82 | #define JFREAD(file,buf,sizeofbuf) \ 83 | ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 84 | #define JFWRITE(file,buf,sizeofbuf) \ 85 | ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) 86 | -------------------------------------------------------------------------------- /src/libjpeg/jmemansi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemansi.c 3 | * 4 | * Copyright (C) 1992-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file provides a simple generic implementation of the system- 9 | * dependent portion of the JPEG memory manager. This implementation 10 | * assumes that you have the ANSI-standard library routine tmpfile(). 11 | * Also, the problem of determining the amount of memory available 12 | * is shoved onto the user. 13 | */ 14 | -------------------------------------------------------------------------------- /src/libjpeg/jmemname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemname.c 3 | * 4 | * Copyright (C) 1992-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file provides a generic implementation of the system-dependent 9 | * portion of the JPEG memory manager. This implementation assumes that 10 | * you must explicitly construct a name for each temp file. 11 | * Also, the problem of determining the amount of memory available 12 | * is shoved onto the user. 13 | */ 14 | 15 | #define JPEG_INTERNALS 16 | #include "jinclude.h" 17 | #include "jpeglib.h" 18 | #include "jmemsys.h" /* import the system-dependent declarations */ 19 | 20 | #ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ 21 | extern void * malloc JPP((size_t size)); 22 | extern void free JPP((void *ptr)); 23 | #endif 24 | 25 | #ifndef SEEK_SET /* pre-ANSI systems may not define this; */ 26 | #define SEEK_SET 0 /* if not, assume 0 is correct */ 27 | #endif 28 | 29 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ 30 | #define READ_BINARY "r" 31 | #define RW_BINARY "w+" 32 | #else 33 | #ifdef VMS /* VMS is very nonstandard */ 34 | #define READ_BINARY "rb", "ctx=stm" 35 | #define RW_BINARY "w+b", "ctx=stm" 36 | #else /* standard ANSI-compliant case */ 37 | #define READ_BINARY "rb" 38 | #define RW_BINARY "w+b" 39 | #endif 40 | #endif 41 | 42 | 43 | /* 44 | * Selection of a file name for a temporary file. 45 | * This is system-dependent! 46 | * 47 | * The code as given is suitable for most Unix systems, and it is easily 48 | * modified for most non-Unix systems. Some notes: 49 | * 1. The temp file is created in the directory named by TEMP_DIRECTORY. 50 | * The default value is /usr/tmp, which is the conventional place for 51 | * creating large temp files on Unix. On other systems you'll probably 52 | * want to change the file location. You can do this by editing the 53 | * #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h. 54 | * 55 | * 2. If you need to change the file name as well as its location, 56 | * you can override the TEMP_FILE_NAME macro. (Note that this is 57 | * actually a printf format string; it must contain %s and %d.) 58 | * Few people should need to do this. 59 | * 60 | * 3. mktemp() is used to ensure that multiple processes running 61 | * simultaneously won't select the same file names. If your system 62 | * doesn't have mktemp(), define NO_MKTEMP to do it the hard way. 63 | * (If you don't have , also define NO_ERRNO_H.) 64 | * 65 | * 4. You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c 66 | * will cause the temp files to be removed if you stop the program early. 67 | */ 68 | 69 | #ifndef TEMP_DIRECTORY /* can override from jconfig.h or Makefile */ 70 | #define TEMP_DIRECTORY "/usr/tmp/" /* recommended setting for Unix */ 71 | #endif 72 | 73 | static int next_file_num; /* to distinguish among several temp files */ 74 | 75 | #ifdef NO_MKTEMP 76 | 77 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ 78 | #define TEMP_FILE_NAME "%sJPG%03d.TMP" 79 | #endif 80 | 81 | #ifndef NO_ERRNO_H 82 | #endif 83 | 84 | /* ANSI C specifies that errno is a macro, but on older systems it's more 85 | * likely to be a plain int variable. And not all versions of errno.h 86 | * bother to declare it, so we have to in order to be most portable. Thus: 87 | */ 88 | #ifndef errno 89 | extern int errno; 90 | #endif 91 | 92 | 93 | LOCAL(void) 94 | select_file_name (char * fname) 95 | { 96 | FILE * tfile; 97 | 98 | /* Keep generating file names till we find one that's not in use */ 99 | for (;;) { 100 | next_file_num++; /* advance counter */ 101 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); 102 | if ((tfile = fopen(fname, READ_BINARY)) == NULL) { 103 | /* fopen could have failed for a reason other than the file not 104 | * being there; for example, file there but unreadable. 105 | * If isn't available, then we cannot test the cause. 106 | */ 107 | #ifdef ENOENT 108 | if (errno != ENOENT) 109 | continue; 110 | #endif 111 | break; 112 | } 113 | fclose(tfile); /* oops, it's there; close tfile & try again */ 114 | } 115 | } 116 | 117 | #else /* ! NO_MKTEMP */ 118 | 119 | /* Note that mktemp() requires the initial filename to end in six X's */ 120 | #ifndef TEMP_FILE_NAME /* can override from jconfig.h or Makefile */ 121 | #define TEMP_FILE_NAME "%sJPG%dXXXXXX" 122 | #endif 123 | 124 | LOCAL(void) 125 | select_file_name (char * fname) 126 | { 127 | next_file_num++; /* advance counter */ 128 | sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num); 129 | mktemp(fname); /* make sure file name is unique */ 130 | /* mktemp replaces the trailing XXXXXX with a unique string of characters */ 131 | } 132 | 133 | #endif /* NO_MKTEMP */ 134 | 135 | 136 | /* 137 | * Memory allocation and freeing are controlled by the regular library 138 | * routines malloc() and free(). 139 | */ 140 | 141 | GLOBAL(void *) 142 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) 143 | { 144 | return (void *) malloc(sizeofobject); 145 | } 146 | 147 | GLOBAL(void) 148 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) 149 | { 150 | free(object); 151 | } 152 | 153 | 154 | /* 155 | * "Large" objects are treated the same as "small" ones. 156 | * NB: although we include FAR keywords in the routine declarations, 157 | * this file won't actually work in 80x86 small/medium model; at least, 158 | * you probably won't be able to process useful-size images in only 64KB. 159 | */ 160 | 161 | GLOBAL(void FAR *) 162 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) 163 | { 164 | return (void FAR *) malloc(sizeofobject); 165 | } 166 | 167 | GLOBAL(void) 168 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) 169 | { 170 | free(object); 171 | } 172 | 173 | 174 | /* 175 | * This routine computes the total memory space available for allocation. 176 | * It's impossible to do this in a portable way; our current solution is 177 | * to make the user tell us (with a default value set at compile time). 178 | * If you can actually get the available space, it's a good idea to subtract 179 | * a slop factor of 5% or so. 180 | */ 181 | 182 | #ifndef DEFAULT_MAX_MEM /* so can override from makefile */ 183 | #define DEFAULT_MAX_MEM 1000000L /* default: one megabyte */ 184 | #endif 185 | 186 | GLOBAL(long) 187 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, 188 | long max_bytes_needed, long already_allocated) 189 | { 190 | return cinfo->mem->max_memory_to_use - already_allocated; 191 | } 192 | 193 | 194 | /* 195 | * Backing store (temporary file) management. 196 | * Backing store objects are only used when the value returned by 197 | * jpeg_mem_available is less than the total space needed. You can dispense 198 | * with these routines if you have plenty of virtual memory; see jmemnobs.c. 199 | */ 200 | 201 | 202 | METHODDEF(void) 203 | read_backing_store (j_common_ptr cinfo, backing_store_ptr info, 204 | void FAR * buffer_address, 205 | long file_offset, long byte_count) 206 | { 207 | if (fseek(info->temp_file, file_offset, SEEK_SET)) 208 | ERREXIT(cinfo, JERR_TFILE_SEEK); 209 | if (JFREAD(info->temp_file, buffer_address, byte_count) 210 | != (size_t) byte_count) 211 | ERREXIT(cinfo, JERR_TFILE_READ); 212 | } 213 | 214 | 215 | METHODDEF(void) 216 | write_backing_store (j_common_ptr cinfo, backing_store_ptr info, 217 | void FAR * buffer_address, 218 | long file_offset, long byte_count) 219 | { 220 | if (fseek(info->temp_file, file_offset, SEEK_SET)) 221 | ERREXIT(cinfo, JERR_TFILE_SEEK); 222 | if (JFWRITE(info->temp_file, buffer_address, byte_count) 223 | != (size_t) byte_count) 224 | ERREXIT(cinfo, JERR_TFILE_WRITE); 225 | } 226 | 227 | 228 | METHODDEF(void) 229 | close_backing_store (j_common_ptr cinfo, backing_store_ptr info) 230 | { 231 | fclose(info->temp_file); /* close the file */ 232 | unlink(info->temp_name); /* delete the file */ 233 | /* If your system doesn't have unlink(), use remove() instead. 234 | * remove() is the ANSI-standard name for this function, but if 235 | * your system was ANSI you'd be using jmemansi.c, right? 236 | */ 237 | TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name); 238 | } 239 | 240 | 241 | /* 242 | * Initial opening of a backing-store object. 243 | */ 244 | 245 | GLOBAL(void) 246 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, 247 | long total_bytes_needed) 248 | { 249 | select_file_name(info->temp_name); 250 | if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL) 251 | ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name); 252 | info->read_backing_store = read_backing_store; 253 | info->write_backing_store = write_backing_store; 254 | info->close_backing_store = close_backing_store; 255 | TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name); 256 | } 257 | 258 | 259 | /* 260 | * These routines take care of any system-dependent initialization and 261 | * cleanup required. 262 | */ 263 | 264 | GLOBAL(long) 265 | jpeg_mem_init (j_common_ptr cinfo) 266 | { 267 | next_file_num = 0; /* initialize temp file name generator */ 268 | return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ 269 | } 270 | 271 | GLOBAL(void) 272 | jpeg_mem_term (j_common_ptr cinfo) 273 | { 274 | /* no work */ 275 | } 276 | -------------------------------------------------------------------------------- /src/libjpeg/jmemnobs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemnobs.c 3 | * 4 | * Copyright (C) 1992-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file provides a really simple implementation of the system- 9 | * dependent portion of the JPEG memory manager. This implementation 10 | * assumes that no backing-store files are needed: all required space 11 | * can be obtained from malloc(). 12 | * This is very portable in the sense that it'll compile on almost anything, 13 | * but you'd better have lots of main memory (or virtual memory) if you want 14 | * to process big images. 15 | * Note that the max_memory_to_use option is ignored by this implementation. 16 | */ 17 | 18 | #define JPEG_INTERNALS 19 | #include "jinclude.h" 20 | #include "jpeglib.h" 21 | #include "jmemsys.h" /* import the system-dependent declarations */ 22 | 23 | #ifndef HAVE_STDLIB_H /* should declare malloc(),free() */ 24 | extern void * malloc JPP((size_t size)); 25 | extern void free JPP((void *ptr)); 26 | #endif 27 | 28 | 29 | /* 30 | * Memory allocation and freeing are controlled by the regular library 31 | * routines malloc() and free(). 32 | */ 33 | 34 | GLOBAL(void *) 35 | jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject) 36 | { 37 | return (void *) malloc(sizeofobject); 38 | } 39 | 40 | GLOBAL(void) 41 | jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject) 42 | { 43 | free(object); 44 | } 45 | 46 | 47 | /* 48 | * "Large" objects are treated the same as "small" ones. 49 | * NB: although we include FAR keywords in the routine declarations, 50 | * this file won't actually work in 80x86 small/medium model; at least, 51 | * you probably won't be able to process useful-size images in only 64KB. 52 | */ 53 | 54 | GLOBAL(void FAR *) 55 | jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject) 56 | { 57 | return (void FAR *) malloc(sizeofobject); 58 | } 59 | 60 | GLOBAL(void) 61 | jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject) 62 | { 63 | free(object); 64 | } 65 | 66 | 67 | /* 68 | * This routine computes the total memory space available for allocation. 69 | * Here we always say, "we got all you want bud!" 70 | */ 71 | 72 | GLOBAL(long) 73 | jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, 74 | long max_bytes_needed, long already_allocated) 75 | { 76 | return max_bytes_needed; 77 | } 78 | 79 | 80 | /* 81 | * Backing store (temporary file) management. 82 | * Since jpeg_mem_available always promised the moon, 83 | * this should never be called and we can just error out. 84 | */ 85 | 86 | GLOBAL(void) 87 | jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, 88 | long total_bytes_needed) 89 | { 90 | ERREXIT(cinfo, JERR_NO_BACKING_STORE); 91 | } 92 | 93 | 94 | /* 95 | * These routines take care of any system-dependent initialization and 96 | * cleanup required. Here, there isn't any. 97 | */ 98 | 99 | GLOBAL(long) 100 | jpeg_mem_init (j_common_ptr cinfo) 101 | { 102 | return 0; /* just set max_memory_to_use to 0 */ 103 | } 104 | 105 | GLOBAL(void) 106 | jpeg_mem_term (j_common_ptr cinfo) 107 | { 108 | /* no work */ 109 | } 110 | -------------------------------------------------------------------------------- /src/libjpeg/jmemsys.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jmemsys.h 3 | * 4 | * Copyright (C) 1992-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This include file defines the interface between the system-independent 9 | * and system-dependent portions of the JPEG memory manager. No other 10 | * modules need include it. (The system-independent portion is jmemmgr.c; 11 | * there are several different versions of the system-dependent portion.) 12 | * 13 | * This file works as-is for the system-dependent memory managers supplied 14 | * in the IJG distribution. You may need to modify it if you write a 15 | * custom memory manager. If system-dependent changes are needed in 16 | * this file, the best method is to #ifdef them based on a configuration 17 | * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR 18 | * and USE_MAC_MEMMGR. 19 | */ 20 | 21 | 22 | /* Short forms of external names for systems with brain-damaged linkers. */ 23 | 24 | #ifdef NEED_SHORT_EXTERNAL_NAMES 25 | #define jpeg_get_small jGetSmall 26 | #define jpeg_free_small jFreeSmall 27 | #define jpeg_get_large jGetLarge 28 | #define jpeg_free_large jFreeLarge 29 | #define jpeg_mem_available jMemAvail 30 | #define jpeg_open_backing_store jOpenBackStore 31 | #define jpeg_mem_init jMemInit 32 | #define jpeg_mem_term jMemTerm 33 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 34 | 35 | 36 | /* 37 | * These two functions are used to allocate and release small chunks of 38 | * memory. (Typically the total amount requested through jpeg_get_small is 39 | * no more than 20K or so; this will be requested in chunks of a few K each.) 40 | * Behavior should be the same as for the standard library functions malloc 41 | * and free; in particular, jpeg_get_small must return NULL on failure. 42 | * On most systems, these ARE malloc and free. jpeg_free_small is passed the 43 | * size of the object being freed, just in case it's needed. 44 | * On an 80x86 machine using small-data memory model, these manage near heap. 45 | */ 46 | 47 | EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject)); 48 | EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object, 49 | size_t sizeofobject)); 50 | 51 | /* 52 | * These two functions are used to allocate and release large chunks of 53 | * memory (up to the total free space designated by jpeg_mem_available). 54 | * The interface is the same as above, except that on an 80x86 machine, 55 | * far pointers are used. On most other machines these are identical to 56 | * the jpeg_get/free_small routines; but we keep them separate anyway, 57 | * in case a different allocation strategy is desirable for large chunks. 58 | */ 59 | 60 | EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo, 61 | size_t sizeofobject)); 62 | EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object, 63 | size_t sizeofobject)); 64 | 65 | /* 66 | * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may 67 | * be requested in a single call to jpeg_get_large (and jpeg_get_small for that 68 | * matter, but that case should never come into play). This macro is needed 69 | * to model the 64Kb-segment-size limit of far addressing on 80x86 machines. 70 | * On those machines, we expect that jconfig.h will provide a proper value. 71 | * On machines with 32-bit flat address spaces, any large constant may be used. 72 | * 73 | * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type 74 | * size_t and will be a multiple of sizeof(align_type). 75 | */ 76 | 77 | #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */ 78 | #define MAX_ALLOC_CHUNK 1000000000L 79 | #endif 80 | 81 | /* 82 | * This routine computes the total space still available for allocation by 83 | * jpeg_get_large. If more space than this is needed, backing store will be 84 | * used. NOTE: any memory already allocated must not be counted. 85 | * 86 | * There is a minimum space requirement, corresponding to the minimum 87 | * feasible buffer sizes; jmemmgr.c will request that much space even if 88 | * jpeg_mem_available returns zero. The maximum space needed, enough to hold 89 | * all working storage in memory, is also passed in case it is useful. 90 | * Finally, the total space already allocated is passed. If no better 91 | * method is available, cinfo->mem->max_memory_to_use - already_allocated 92 | * is often a suitable calculation. 93 | * 94 | * It is OK for jpeg_mem_available to underestimate the space available 95 | * (that'll just lead to more backing-store access than is really necessary). 96 | * However, an overestimate will lead to failure. Hence it's wise to subtract 97 | * a slop factor from the true available space. 5% should be enough. 98 | * 99 | * On machines with lots of virtual memory, any large constant may be returned. 100 | * Conversely, zero may be returned to always use the minimum amount of memory. 101 | */ 102 | 103 | EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo, 104 | long min_bytes_needed, 105 | long max_bytes_needed, 106 | long already_allocated)); 107 | 108 | 109 | /* 110 | * This structure holds whatever state is needed to access a single 111 | * backing-store object. The read/write/close method pointers are called 112 | * by jmemmgr.c to manipulate the backing-store object; all other fields 113 | * are private to the system-dependent backing store routines. 114 | */ 115 | 116 | #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */ 117 | 118 | 119 | #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */ 120 | 121 | typedef unsigned short XMSH; /* type of extended-memory handles */ 122 | typedef unsigned short EMSH; /* type of expanded-memory handles */ 123 | 124 | typedef union { 125 | short file_handle; /* DOS file handle if it's a temp file */ 126 | XMSH xms_handle; /* handle if it's a chunk of XMS */ 127 | EMSH ems_handle; /* handle if it's a chunk of EMS */ 128 | } handle_union; 129 | 130 | #endif /* USE_MSDOS_MEMMGR */ 131 | 132 | #ifdef USE_MAC_MEMMGR /* Mac-specific junk */ 133 | #include 134 | #endif /* USE_MAC_MEMMGR */ 135 | 136 | 137 | typedef struct backing_store_struct * backing_store_ptr; 138 | 139 | typedef struct backing_store_struct { 140 | /* Methods for reading/writing/closing this backing-store object */ 141 | JMETHOD(void, read_backing_store, (j_common_ptr cinfo, 142 | backing_store_ptr info, 143 | void FAR * buffer_address, 144 | long file_offset, long byte_count)); 145 | JMETHOD(void, write_backing_store, (j_common_ptr cinfo, 146 | backing_store_ptr info, 147 | void FAR * buffer_address, 148 | long file_offset, long byte_count)); 149 | JMETHOD(void, close_backing_store, (j_common_ptr cinfo, 150 | backing_store_ptr info)); 151 | 152 | /* Private fields for system-dependent backing-store management */ 153 | #ifdef USE_MSDOS_MEMMGR 154 | /* For the MS-DOS manager (jmemdos.c), we need: */ 155 | handle_union handle; /* reference to backing-store storage object */ 156 | char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ 157 | #else 158 | #ifdef USE_MAC_MEMMGR 159 | /* For the Mac manager (jmemmac.c), we need: */ 160 | short temp_file; /* file reference number to temp file */ 161 | FSSpec tempSpec; /* the FSSpec for the temp file */ 162 | char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */ 163 | #else 164 | /* For a typical implementation with temp files, we need: */ 165 | FILE * temp_file; /* stdio reference to temp file */ 166 | char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */ 167 | #endif 168 | #endif 169 | } backing_store_info; 170 | 171 | 172 | /* 173 | * Initial opening of a backing-store object. This must fill in the 174 | * read/write/close pointers in the object. The read/write routines 175 | * may take an error exit if the specified maximum file size is exceeded. 176 | * (If jpeg_mem_available always returns a large value, this routine can 177 | * just take an error exit.) 178 | */ 179 | 180 | EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo, 181 | backing_store_ptr info, 182 | long total_bytes_needed)); 183 | 184 | 185 | /* 186 | * These routines take care of any system-dependent initialization and 187 | * cleanup required. jpeg_mem_init will be called before anything is 188 | * allocated (and, therefore, nothing in cinfo is of use except the error 189 | * manager pointer). It should return a suitable default value for 190 | * max_memory_to_use; this may subsequently be overridden by the surrounding 191 | * application. (Note that max_memory_to_use is only important if 192 | * jpeg_mem_available chooses to consult it ... no one else will.) 193 | * jpeg_mem_term may assume that all requested memory has been freed and that 194 | * all opened backing-store objects have been closed. 195 | */ 196 | 197 | EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo)); 198 | EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo)); 199 | -------------------------------------------------------------------------------- /src/libjpeg/jmorecfg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jmorecfg.h 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains additional configuration options that customize the 9 | * JPEG software for special applications or support machine-dependent 10 | * optimizations. Most users will not need to touch this file. 11 | */ 12 | 13 | 14 | /* 15 | * Define BITS_IN_JSAMPLE as either 16 | * 8 for 8-bit sample values (the usual setting) 17 | * 12 for 12-bit sample values 18 | * Only 8 and 12 are legal data precisions for lossy JPEG according to the 19 | * JPEG standard, and the IJG code does not support anything else! 20 | * We do not support run-time selection of data precision, sorry. 21 | */ 22 | 23 | #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */ 24 | 25 | 26 | /* 27 | * Maximum number of components (color channels) allowed in JPEG image. 28 | * To meet the letter of the JPEG spec, set this to 255. However, darn 29 | * few applications need more than 4 channels (maybe 5 for CMYK + alpha 30 | * mask). We recommend 10 as a reasonable compromise; use 4 if you are 31 | * really short on memory. (Each allowed component costs a hundred or so 32 | * bytes of storage, whether actually used in an image or not.) 33 | */ 34 | 35 | #define MAX_COMPONENTS 10 /* maximum number of image components */ 36 | 37 | 38 | /* 39 | * Basic data types. 40 | * You may need to change these if you have a machine with unusual data 41 | * type sizes; for example, "char" not 8 bits, "short" not 16 bits, 42 | * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits, 43 | * but it had better be at least 16. 44 | */ 45 | 46 | /* Representation of a single sample (pixel element value). 47 | * We frequently allocate large arrays of these, so it's important to keep 48 | * them small. But if you have memory to burn and access to char or short 49 | * arrays is very slow on your hardware, you might want to change these. 50 | */ 51 | 52 | #if BITS_IN_JSAMPLE == 8 53 | /* JSAMPLE should be the smallest type that will hold the values 0..255. 54 | * You can use a signed char by having GETJSAMPLE mask it with 0xFF. 55 | */ 56 | 57 | #ifdef HAVE_UNSIGNED_CHAR 58 | 59 | typedef unsigned char JSAMPLE; 60 | #define GETJSAMPLE(value) ((int) (value)) 61 | 62 | #else /* not HAVE_UNSIGNED_CHAR */ 63 | 64 | typedef char JSAMPLE; 65 | #ifdef CHAR_IS_UNSIGNED 66 | #define GETJSAMPLE(value) ((int) (value)) 67 | #else 68 | #define GETJSAMPLE(value) ((int) (value) & 0xFF) 69 | #endif /* CHAR_IS_UNSIGNED */ 70 | 71 | #endif /* HAVE_UNSIGNED_CHAR */ 72 | 73 | #define MAXJSAMPLE 255 74 | #define CENTERJSAMPLE 128 75 | 76 | #endif /* BITS_IN_JSAMPLE == 8 */ 77 | 78 | 79 | #if BITS_IN_JSAMPLE == 12 80 | /* JSAMPLE should be the smallest type that will hold the values 0..4095. 81 | * On nearly all machines "short" will do nicely. 82 | */ 83 | 84 | typedef short JSAMPLE; 85 | #define GETJSAMPLE(value) ((int) (value)) 86 | 87 | #define MAXJSAMPLE 4095 88 | #define CENTERJSAMPLE 2048 89 | 90 | #endif /* BITS_IN_JSAMPLE == 12 */ 91 | 92 | 93 | /* Representation of a DCT frequency coefficient. 94 | * This should be a signed value of at least 16 bits; "short" is usually OK. 95 | * Again, we allocate large arrays of these, but you can change to int 96 | * if you have memory to burn and "short" is really slow. 97 | */ 98 | 99 | typedef short JCOEF; 100 | 101 | 102 | /* Compressed datastreams are represented as arrays of JOCTET. 103 | * These must be EXACTLY 8 bits wide, at least once they are written to 104 | * external storage. Note that when using the stdio data source/destination 105 | * managers, this is also the data type passed to fread/fwrite. 106 | */ 107 | 108 | #ifdef HAVE_UNSIGNED_CHAR 109 | 110 | typedef unsigned char JOCTET; 111 | #define GETJOCTET(value) (value) 112 | 113 | #else /* not HAVE_UNSIGNED_CHAR */ 114 | 115 | typedef char JOCTET; 116 | #ifdef CHAR_IS_UNSIGNED 117 | #define GETJOCTET(value) (value) 118 | #else 119 | #define GETJOCTET(value) ((value) & 0xFF) 120 | #endif /* CHAR_IS_UNSIGNED */ 121 | 122 | #endif /* HAVE_UNSIGNED_CHAR */ 123 | 124 | 125 | /* These typedefs are used for various table entries and so forth. 126 | * They must be at least as wide as specified; but making them too big 127 | * won't cost a huge amount of memory, so we don't provide special 128 | * extraction code like we did for JSAMPLE. (In other words, these 129 | * typedefs live at a different point on the speed/space tradeoff curve.) 130 | */ 131 | 132 | /* UINT8 must hold at least the values 0..255. */ 133 | 134 | #ifdef HAVE_UNSIGNED_CHAR 135 | typedef unsigned char UINT8; 136 | #else /* not HAVE_UNSIGNED_CHAR */ 137 | #ifdef CHAR_IS_UNSIGNED 138 | typedef char UINT8; 139 | #else /* not CHAR_IS_UNSIGNED */ 140 | typedef short UINT8; 141 | #endif /* CHAR_IS_UNSIGNED */ 142 | #endif /* HAVE_UNSIGNED_CHAR */ 143 | 144 | /* UINT16 must hold at least the values 0..65535. */ 145 | 146 | #ifdef HAVE_UNSIGNED_SHORT 147 | typedef unsigned short UINT16; 148 | #else /* not HAVE_UNSIGNED_SHORT */ 149 | typedef unsigned int UINT16; 150 | #endif /* HAVE_UNSIGNED_SHORT */ 151 | 152 | /* INT16 must hold at least the values -32768..32767. */ 153 | 154 | #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */ 155 | typedef short INT16; 156 | #endif 157 | 158 | /* INT32 must hold at least signed 32-bit values. */ 159 | 160 | #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */ 161 | typedef long INT32; 162 | #endif 163 | 164 | /* Datatype used for image dimensions. The JPEG standard only supports 165 | * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore 166 | * "unsigned int" is sufficient on all machines. However, if you need to 167 | * handle larger images and you don't mind deviating from the spec, you 168 | * can change this datatype. 169 | */ 170 | 171 | typedef unsigned int JDIMENSION; 172 | 173 | #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */ 174 | 175 | 176 | /* These macros are used in all function definitions and extern declarations. 177 | * You could modify them if you need to change function linkage conventions; 178 | * in particular, you'll need to do that to make the library a Windows DLL. 179 | * Another application is to make all functions global for use with debuggers 180 | * or code profilers that require it. 181 | */ 182 | 183 | /* a function called through method pointers: */ 184 | #define METHODDEF(type) static type 185 | /* a function used only in its module: */ 186 | #define LOCAL(type) static type 187 | /* a function referenced thru EXTERNs: */ 188 | #define GLOBAL(type) type 189 | /* a reference to a GLOBAL function: */ 190 | #define EXTERN(type) extern type 191 | 192 | 193 | /* This macro is used to declare a "method", that is, a function pointer. 194 | * We want to supply prototype parameters if the compiler can cope. 195 | * Note that the arglist parameter must be parenthesized! 196 | * Again, you can customize this if you need special linkage keywords. 197 | */ 198 | 199 | #ifdef HAVE_PROTOTYPES 200 | #define JMETHOD(type,methodname,arglist) type (*methodname) arglist 201 | #else 202 | #define JMETHOD(type,methodname,arglist) type (*methodname) () 203 | #endif 204 | 205 | 206 | /* Here is the pseudo-keyword for declaring pointers that must be "far" 207 | * on 80x86 machines. Most of the specialized coding for 80x86 is handled 208 | * by just saying "FAR *" where such a pointer is needed. In a few places 209 | * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol. 210 | */ 211 | 212 | #ifdef NEED_FAR_POINTERS 213 | #define FAR far 214 | #else 215 | #define FAR 216 | #endif 217 | 218 | 219 | /* 220 | * On a few systems, type boolean and/or its values FALSE, TRUE may appear 221 | * in standard header files. Or you may have conflicts with application- 222 | * specific header files that you want to include together with these files. 223 | * Defining HAVE_BOOLEAN before including jpeglib.h should make it work. 224 | */ 225 | 226 | #ifndef HAVE_BOOLEAN 227 | typedef int boolean; 228 | #endif 229 | #ifndef FALSE /* in case these macros already exist */ 230 | #define FALSE 0 /* values of boolean */ 231 | #endif 232 | #ifndef TRUE 233 | #define TRUE 1 234 | #endif 235 | 236 | 237 | /* 238 | * The remaining options affect code selection within the JPEG library, 239 | * but they don't need to be visible to most applications using the library. 240 | * To minimize application namespace pollution, the symbols won't be 241 | * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined. 242 | */ 243 | 244 | #ifdef JPEG_INTERNALS 245 | #define JPEG_INTERNAL_OPTIONS 246 | #endif 247 | 248 | #ifdef JPEG_INTERNAL_OPTIONS 249 | 250 | 251 | /* 252 | * These defines indicate whether to include various optional functions. 253 | * Undefining some of these symbols will produce a smaller but less capable 254 | * library. Note that you can leave certain source files out of the 255 | * compilation/linking process if you've #undef'd the corresponding symbols. 256 | * (You may HAVE to do that if your compiler doesn't like null source files.) 257 | */ 258 | 259 | /* Arithmetic coding is unsupported for legal reasons. Complaints to IBM. */ 260 | 261 | /* Capability options common to encoder and decoder: */ 262 | 263 | #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */ 264 | #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */ 265 | #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */ 266 | 267 | /* Encoder capability options: */ 268 | 269 | #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ 270 | #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ 271 | #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ 272 | #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */ 273 | /* Note: if you selected 12-bit data precision, it is dangerous to turn off 274 | * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit 275 | * precision, so jchuff.c normally uses entropy optimization to compute 276 | * usable tables for higher precision. If you don't want to do optimization, 277 | * you'll have to supply different default Huffman tables. 278 | * The exact same statements apply for progressive JPEG: the default tables 279 | * don't work for progressive mode. (This may get fixed, however.) 280 | */ 281 | #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */ 282 | 283 | /* Decoder capability options: */ 284 | 285 | #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */ 286 | #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */ 287 | #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/ 288 | #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */ 289 | #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */ 290 | #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */ 291 | #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */ 292 | #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */ 293 | #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */ 294 | #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */ 295 | 296 | /* more capability options later, no doubt */ 297 | 298 | 299 | /* 300 | * Ordering of RGB data in scanlines passed to or from the application. 301 | * If your application wants to deal with data in the order B,G,R, just 302 | * change these macros. You can also deal with formats such as R,G,B,X 303 | * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing 304 | * the offsets will also change the order in which colormap data is organized. 305 | * RESTRICTIONS: 306 | * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats. 307 | * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not 308 | * useful if you are using JPEG color spaces other than YCbCr or grayscale. 309 | * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE 310 | * is not 3 (they don't understand about dummy color components!). So you 311 | * can't use color quantization if you change that value. 312 | */ 313 | 314 | #define RGB_RED 0 /* Offset of Red in an RGB scanline element */ 315 | #define RGB_GREEN 1 /* Offset of Green */ 316 | #define RGB_BLUE 2 /* Offset of Blue */ 317 | #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */ 318 | 319 | 320 | /* Definitions for speed-related optimizations. */ 321 | 322 | 323 | /* If your compiler supports inline functions, define INLINE 324 | * as the inline keyword; otherwise define it as empty. 325 | */ 326 | 327 | #ifndef INLINE 328 | #ifdef __GNUC__ /* for instance, GNU C knows about inline */ 329 | #define INLINE __inline__ 330 | #endif 331 | #ifndef INLINE 332 | #define INLINE /* default is to define it as empty */ 333 | #endif 334 | #endif 335 | 336 | 337 | /* On some machines (notably 68000 series) "int" is 32 bits, but multiplying 338 | * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER 339 | * as short on such a machine. MULTIPLIER must be at least 16 bits wide. 340 | */ 341 | 342 | #ifndef MULTIPLIER 343 | #define MULTIPLIER int /* type for fastest integer multiply */ 344 | #endif 345 | 346 | 347 | /* FAST_FLOAT should be either float or double, whichever is done faster 348 | * by your compiler. (Note that this type is only used in the floating point 349 | * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.) 350 | * Typically, float is faster in ANSI C compilers, while double is faster in 351 | * pre-ANSI compilers (because they insist on converting to double anyway). 352 | * The code below therefore chooses float if we have ANSI-style prototypes. 353 | */ 354 | 355 | #ifndef FAST_FLOAT 356 | #ifdef HAVE_PROTOTYPES 357 | #define FAST_FLOAT float 358 | #else 359 | #define FAST_FLOAT double 360 | #endif 361 | #endif 362 | 363 | #endif /* JPEG_INTERNAL_OPTIONS */ 364 | -------------------------------------------------------------------------------- /src/libjpeg/jutils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jutils.c 3 | * 4 | * Copyright (C) 1991-1996, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains tables and miscellaneous utility routines needed 9 | * for both compression and decompression. 10 | * Note we prefix all global names with "j" to minimize conflicts with 11 | * a surrounding application. 12 | */ 13 | 14 | #define JPEG_INTERNALS 15 | #include "jinclude.h" 16 | #include "jpeglib.h" 17 | 18 | 19 | /* 20 | * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element 21 | * of a DCT block read in natural order (left to right, top to bottom). 22 | */ 23 | 24 | #if 0 /* This table is not actually needed in v6a */ 25 | 26 | const int jpeg_zigzag_order[DCTSIZE2] = { 27 | 0, 1, 5, 6, 14, 15, 27, 28, 28 | 2, 4, 7, 13, 16, 26, 29, 42, 29 | 3, 8, 12, 17, 25, 30, 41, 43, 30 | 9, 11, 18, 24, 31, 40, 44, 53, 31 | 10, 19, 23, 32, 39, 45, 52, 54, 32 | 20, 22, 33, 38, 46, 51, 55, 60, 33 | 21, 34, 37, 47, 50, 56, 59, 61, 34 | 35, 36, 48, 49, 57, 58, 62, 63 35 | }; 36 | 37 | #endif 38 | 39 | /* 40 | * jpeg_natural_order[i] is the natural-order position of the i'th element 41 | * of zigzag order. 42 | * 43 | * When reading corrupted data, the Huffman decoders could attempt 44 | * to reference an entry beyond the end of this array (if the decoded 45 | * zero run length reaches past the end of the block). To prevent 46 | * wild stores without adding an inner-loop test, we put some extra 47 | * "63"s after the real entries. This will cause the extra coefficient 48 | * to be stored in location 63 of the block, not somewhere random. 49 | * The worst case would be a run-length of 15, which means we need 16 50 | * fake entries. 51 | */ 52 | 53 | const int jpeg_natural_order[DCTSIZE2+16] = { 54 | 0, 1, 8, 16, 9, 2, 3, 10, 55 | 17, 24, 32, 25, 18, 11, 4, 5, 56 | 12, 19, 26, 33, 40, 48, 41, 34, 57 | 27, 20, 13, 6, 7, 14, 21, 28, 58 | 35, 42, 49, 56, 57, 50, 43, 36, 59 | 29, 22, 15, 23, 30, 37, 44, 51, 60 | 58, 59, 52, 45, 38, 31, 39, 46, 61 | 53, 60, 61, 54, 47, 55, 62, 63, 62 | 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */ 63 | 63, 63, 63, 63, 63, 63, 63, 63 64 | }; 65 | 66 | 67 | /* 68 | * Arithmetic utilities 69 | */ 70 | 71 | GLOBAL(long) 72 | jdiv_round_up (long a, long b) 73 | /* Compute a/b rounded up to next integer, ie, ceil(a/b) */ 74 | /* Assumes a >= 0, b > 0 */ 75 | { 76 | return (a + b - 1L) / b; 77 | } 78 | 79 | 80 | GLOBAL(long) 81 | jround_up (long a, long b) 82 | /* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */ 83 | /* Assumes a >= 0, b > 0 */ 84 | { 85 | a += b - 1L; 86 | return a - (a % b); 87 | } 88 | 89 | 90 | /* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays 91 | * and coefficient-block arrays. This won't work on 80x86 because the arrays 92 | * are FAR and we're assuming a small-pointer memory model. However, some 93 | * DOS compilers provide far-pointer versions of memcpy() and memset() even 94 | * in the small-model libraries. These will be used if USE_FMEM is defined. 95 | * Otherwise, the routines below do it the hard way. (The performance cost 96 | * is not all that great, because these routines aren't very heavily used.) 97 | */ 98 | 99 | #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */ 100 | #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size) 101 | #define FMEMZERO(target,size) MEMZERO(target,size) 102 | #else /* 80x86 case, define if we can */ 103 | #ifdef USE_FMEM 104 | #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size)) 105 | #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size)) 106 | #endif 107 | #endif 108 | 109 | 110 | GLOBAL(void) 111 | jcopy_sample_rows (JSAMPARRAY input_array, int source_row, 112 | JSAMPARRAY output_array, int dest_row, 113 | int num_rows, JDIMENSION num_cols) 114 | /* Copy some rows of samples from one place to another. 115 | * num_rows rows are copied from input_array[source_row++] 116 | * to output_array[dest_row++]; these areas may overlap for duplication. 117 | * The source and destination arrays must be at least as wide as num_cols. 118 | */ 119 | { 120 | register JSAMPROW inptr, outptr; 121 | #ifdef FMEMCOPY 122 | register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE)); 123 | #else 124 | register JDIMENSION count; 125 | #endif 126 | register int row; 127 | 128 | input_array += source_row; 129 | output_array += dest_row; 130 | 131 | for (row = num_rows; row > 0; row--) { 132 | inptr = *input_array++; 133 | outptr = *output_array++; 134 | #ifdef FMEMCOPY 135 | FMEMCOPY(outptr, inptr, count); 136 | #else 137 | for (count = num_cols; count > 0; count--) 138 | *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */ 139 | #endif 140 | } 141 | } 142 | 143 | 144 | GLOBAL(void) 145 | jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row, 146 | JDIMENSION num_blocks) 147 | /* Copy a row of coefficient blocks from one place to another. */ 148 | { 149 | #ifdef FMEMCOPY 150 | FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF))); 151 | #else 152 | register JCOEFPTR inptr, outptr; 153 | register long count; 154 | 155 | inptr = (JCOEFPTR) input_row; 156 | outptr = (JCOEFPTR) output_row; 157 | for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) { 158 | *outptr++ = *inptr++; 159 | } 160 | #endif 161 | } 162 | 163 | 164 | GLOBAL(void) 165 | jzero_far (void FAR * target, size_t bytestozero) 166 | /* Zero out a chunk of FAR memory. */ 167 | /* This might be sample-array data, block-array data, or alloc_large data. */ 168 | { 169 | #ifdef FMEMZERO 170 | FMEMZERO(target, bytestozero); 171 | #else 172 | register char FAR * ptr = (char FAR *) target; 173 | register size_t count; 174 | 175 | for (count = bytestozero; count > 0; count--) { 176 | *ptr++ = 0; 177 | } 178 | #endif 179 | } 180 | -------------------------------------------------------------------------------- /src/libjpeg/jversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jversion.h 3 | * 4 | * Copyright (C) 1991-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains software version identification. 9 | */ 10 | 11 | 12 | #define JVERSION "6b 27-Mar-1998" 13 | 14 | #define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane" 15 | -------------------------------------------------------------------------------- /src/media.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/media.c -------------------------------------------------------------------------------- /src/scene_data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/scene_data.c -------------------------------------------------------------------------------- /src/scene_select.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/scene_select.c -------------------------------------------------------------------------------- /src/scene_talk.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/scene_talk.c -------------------------------------------------------------------------------- /src/scene_title.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/scene_title.c -------------------------------------------------------------------------------- /src/script.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/script.c -------------------------------------------------------------------------------- /src/sprite.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/sprite.c -------------------------------------------------------------------------------- /src/tar_reader.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/tar_reader.c -------------------------------------------------------------------------------- /src/timer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/src/timer.c -------------------------------------------------------------------------------- /src/utils.c: -------------------------------------------------------------------------------- 1 | #include "kuro.h" 2 | 3 | 4 | double myatof(const char* sptr) 5 | { 6 | double temp = 10; 7 | BOOL ispnum = TRUE; 8 | double ans = 0; 9 | 10 | if(*sptr=='-') { 11 | ispnum=FALSE; 12 | sptr++; 13 | } 14 | else if(*sptr=='+') { 15 | sptr++; 16 | } 17 | while(*sptr!='\0') { 18 | if(*sptr=='.') { 19 | sptr++; 20 | break; 21 | } 22 | ans = ans * 10 + (*sptr - '0'); 23 | sptr++; 24 | } 25 | while(*sptr!='\0') { 26 | ans = ans + (*sptr - '0') / temp; 27 | temp *= 10; 28 | sptr++; 29 | } 30 | if(ispnum) 31 | return ans; 32 | else 33 | return -ans; 34 | } 35 | 36 | char * mystrdup(const char * src) { 37 | char * str = (char*)malloc(strlen(src)+1); 38 | strcpy(str,src); 39 | return str; 40 | } 41 | 42 | #ifdef ___NDLESS___ 43 | 44 | static unsigned int* p_contrast = (unsigned int*) 0x900F0020; 45 | 46 | void ContrastInc () { 47 | if( is_cx && (*p_contrast)< 225) 48 | (*p_contrast)++; 49 | else if( (!is_cx) && (*p_contrast) < 0xc0 ) 50 | (*p_contrast)++; 51 | } 52 | 53 | void ContrastDec () 54 | { 55 | if( is_cx && (*p_contrast)> 1 ) 56 | (*p_contrast)--; 57 | else if( (!is_cx) && (*p_contrast) >50 ) 58 | (*p_contrast)--; 59 | } 60 | 61 | #endif -------------------------------------------------------------------------------- /win32/KuroScripter.dsp: -------------------------------------------------------------------------------- 1 | # Microsoft Developer Studio Project File - Name="KuroScripter" - Package Owner=<4> 2 | # Microsoft Developer Studio Generated Build File, Format Version 6.00 3 | # ** DO NOT EDIT ** 4 | 5 | # TARGTYPE "Win32 (x86) Console Application" 0x0103 6 | 7 | CFG=KuroScripter - Win32 Debug 8 | !MESSAGE This is not a valid makefile. To build this project using NMAKE, 9 | !MESSAGE use the Export Makefile command and run 10 | !MESSAGE 11 | !MESSAGE NMAKE /f "KuroScripter.mak". 12 | !MESSAGE 13 | !MESSAGE You can specify a configuration when running NMAKE 14 | !MESSAGE by defining the macro CFG on the command line. For example: 15 | !MESSAGE 16 | !MESSAGE NMAKE /f "KuroScripter.mak" CFG="KuroScripter - Win32 Debug" 17 | !MESSAGE 18 | !MESSAGE Possible choices for configuration are: 19 | !MESSAGE 20 | !MESSAGE "KuroScripter - Win32 Release" (based on "Win32 (x86) Console Application") 21 | !MESSAGE "KuroScripter - Win32 Debug" (based on "Win32 (x86) Console Application") 22 | !MESSAGE 23 | 24 | # Begin Project 25 | # PROP AllowPerConfigDependencies 0 26 | # PROP Scc_ProjName "" 27 | # PROP Scc_LocalPath "" 28 | CPP=cl.exe 29 | RSC=rc.exe 30 | 31 | !IF "$(CFG)" == "KuroScripter - Win32 Release" 32 | 33 | # PROP BASE Use_MFC 0 34 | # PROP BASE Use_Debug_Libraries 0 35 | # PROP BASE Output_Dir "Release" 36 | # PROP BASE Intermediate_Dir "Release" 37 | # PROP BASE Target_Dir "" 38 | # PROP Use_MFC 0 39 | # PROP Use_Debug_Libraries 0 40 | # PROP Output_Dir "Release" 41 | # PROP Intermediate_Dir "Release" 42 | # PROP Target_Dir "" 43 | # ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 44 | # ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c 45 | # ADD BASE RSC /l 0x804 /d "NDEBUG" 46 | # ADD RSC /l 0x804 /d "NDEBUG" 47 | BSC32=bscmake.exe 48 | # ADD BASE BSC32 /nologo 49 | # ADD BSC32 /nologo 50 | LINK32=link.exe 51 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 52 | # ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 | 54 | !ELSEIF "$(CFG)" == "KuroScripter - Win32 Debug" 55 | 56 | # PROP BASE Use_MFC 0 57 | # PROP BASE Use_Debug_Libraries 1 58 | # PROP BASE Output_Dir "Debug" 59 | # PROP BASE Intermediate_Dir "Debug" 60 | # PROP BASE Target_Dir "" 61 | # PROP Use_MFC 0 62 | # PROP Use_Debug_Libraries 1 63 | # PROP Output_Dir "Debug" 64 | # PROP Intermediate_Dir "Debug" 65 | # PROP Ignore_Export_Lib 0 66 | # PROP Target_Dir "" 67 | # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 68 | # ADD CPP /nologo /MD /W3 /Gm /GX /ZI /Od /I "../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c 69 | # ADD BASE RSC /l 0x804 /d "_DEBUG" 70 | # ADD RSC /l 0x804 /d "_DEBUG" 71 | BSC32=bscmake.exe 72 | # ADD BASE BSC32 /nologo 73 | # ADD BSC32 /nologo 74 | LINK32=link.exe 75 | # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 76 | # ADD LINK32 SDL_image.lib SDL.lib SDLmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept 77 | 78 | !ENDIF 79 | 80 | # Begin Target 81 | 82 | # Name "KuroScripter - Win32 Release" 83 | # Name "KuroScripter - Win32 Debug" 84 | # Begin Group "Source Files" 85 | 86 | # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" 87 | # Begin Source File 88 | 89 | SOURCE=..\src\data.c 90 | # End Source File 91 | # Begin Source File 92 | 93 | SOURCE=..\src\dlist.c 94 | # End Source File 95 | # Begin Source File 96 | 97 | SOURCE=..\src\error.c 98 | # End Source File 99 | # Begin Source File 100 | 101 | SOURCE=..\src\font.c 102 | # End Source File 103 | # Begin Source File 104 | 105 | SOURCE=..\src\graph.c 106 | # End Source File 107 | # Begin Source File 108 | 109 | SOURCE=..\src\input.c 110 | # End Source File 111 | # Begin Source File 112 | 113 | SOURCE=..\src\kuro.c 114 | # End Source File 115 | # Begin Source File 116 | 117 | SOURCE=..\src\media.c 118 | # End Source File 119 | # Begin Source File 120 | 121 | SOURCE=..\src\oimg_jpeg.c 122 | # End Source File 123 | # Begin Source File 124 | 125 | SOURCE=..\src\rotozoom.c 126 | # End Source File 127 | # Begin Source File 128 | 129 | SOURCE=..\src\scene_data.c 130 | # End Source File 131 | # Begin Source File 132 | 133 | SOURCE=..\src\scene_select.c 134 | # End Source File 135 | # Begin Source File 136 | 137 | SOURCE=..\src\scene_talk.c 138 | # End Source File 139 | # Begin Source File 140 | 141 | SOURCE=..\src\scene_title.c 142 | # End Source File 143 | # Begin Source File 144 | 145 | SOURCE=..\src\script.c 146 | # End Source File 147 | # Begin Source File 148 | 149 | SOURCE=..\src\sprite.c 150 | # End Source File 151 | # Begin Source File 152 | 153 | SOURCE=..\src\tar_reader.c 154 | # End Source File 155 | # Begin Source File 156 | 157 | SOURCE=..\src\timer.c 158 | # End Source File 159 | # Begin Source File 160 | 161 | SOURCE=..\src\utils.c 162 | # End Source File 163 | # End Group 164 | # Begin Group "Header Files" 165 | 166 | # PROP Default_Filter "h;hpp;hxx;hm;inl" 167 | # Begin Source File 168 | 169 | SOURCE=..\include\data.h 170 | # End Source File 171 | # Begin Source File 172 | 173 | SOURCE=..\include\dlist.h 174 | # End Source File 175 | # Begin Source File 176 | 177 | SOURCE=..\include\error.h 178 | # End Source File 179 | # Begin Source File 180 | 181 | SOURCE=..\include\font.h 182 | # End Source File 183 | # Begin Source File 184 | 185 | SOURCE=..\include\graph.h 186 | # End Source File 187 | # Begin Source File 188 | 189 | SOURCE=..\include\input.h 190 | # End Source File 191 | # Begin Source File 192 | 193 | SOURCE=..\include\kuro.h 194 | # End Source File 195 | # Begin Source File 196 | 197 | SOURCE=..\include\media.h 198 | # End Source File 199 | # Begin Source File 200 | 201 | SOURCE=..\include\oimg_jpeg.h 202 | # End Source File 203 | # Begin Source File 204 | 205 | SOURCE=..\include\rotozoom.h 206 | # End Source File 207 | # Begin Source File 208 | 209 | SOURCE=..\include\scene.h 210 | # End Source File 211 | # Begin Source File 212 | 213 | SOURCE=..\include\script.h 214 | # End Source File 215 | # Begin Source File 216 | 217 | SOURCE=..\include\sprite.h 218 | # End Source File 219 | # Begin Source File 220 | 221 | SOURCE=..\include\tar_reader.h 222 | # End Source File 223 | # Begin Source File 224 | 225 | SOURCE=..\include\timer.h 226 | # End Source File 227 | # Begin Source File 228 | 229 | SOURCE=..\include\utils.h 230 | # End Source File 231 | # End Group 232 | # Begin Group "Resource Files" 233 | 234 | # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" 235 | # Begin Source File 236 | 237 | SOURCE=.\res\resource.rc 238 | # End Source File 239 | # End Group 240 | # End Target 241 | # End Project 242 | -------------------------------------------------------------------------------- /win32/KuroScripter.dsw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/win32/KuroScripter.dsw -------------------------------------------------------------------------------- /win32/KuroScripter.ncb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/win32/KuroScripter.ncb -------------------------------------------------------------------------------- /win32/KuroScripter.opt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/win32/KuroScripter.opt -------------------------------------------------------------------------------- /win32/KuroScripter.plg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
 4 | 

Build Log

5 |

6 | --------------------Configuration: KuroScripter - Win32 Debug-------------------- 7 |

8 |

Command Lines

9 | Creating temporary file "C:\Users\ADMINI~1\AppData\Local\Temp\RSPAA53.tmp" with contents 10 | [ 11 | /nologo /MD /W3 /Gm /GX /ZI /Od /I "../include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/KuroScripter.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c 12 | "D:\KuroScripter\KuroScripter\src\graph.c" 13 | ] 14 | Creating command line "cl.exe @C:\Users\ADMINI~1\AppData\Local\Temp\RSPAA53.tmp" 15 | Creating temporary file "C:\Users\ADMINI~1\AppData\Local\Temp\RSPAA54.tmp" with contents 16 | [ 17 | SDL_image.lib SDL.lib SDLmain.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/KuroScripter.pdb" /debug /machine:I386 /out:"Debug/KuroScripter.exe" /pdbtype:sept 18 | .\Debug\data.obj 19 | .\Debug\dlist.obj 20 | .\Debug\error.obj 21 | .\Debug\font.obj 22 | .\Debug\graph.obj 23 | .\Debug\input.obj 24 | .\Debug\kuro.obj 25 | .\Debug\media.obj 26 | .\Debug\oimg_jpeg.obj 27 | .\Debug\rotozoom.obj 28 | .\Debug\scene_data.obj 29 | .\Debug\scene_select.obj 30 | .\Debug\scene_talk.obj 31 | .\Debug\scene_title.obj 32 | .\Debug\script.obj 33 | .\Debug\sprite.obj 34 | .\Debug\tar_reader.obj 35 | .\Debug\timer.obj 36 | .\Debug\utils.obj 37 | .\Debug\resource.res 38 | ] 39 | Creating command line "link.exe @C:\Users\ADMINI~1\AppData\Local\Temp\RSPAA54.tmp" 40 |

Output Window

41 | Compiling... 42 | graph.c 43 | Linking... 44 | 45 | 46 | 47 |

Results

48 | KuroScripter.exe - 0 error(s), 0 warning(s) 49 |
50 | 51 | 52 | -------------------------------------------------------------------------------- /win32/res/krs_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/win32/res/krs_icon.png -------------------------------------------------------------------------------- /win32/res/krs_icon_win32.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/win32/res/krs_icon_win32.ico -------------------------------------------------------------------------------- /win32/res/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by resource.rc 4 | // 5 | #define IDI_ICON1 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /win32/res/resource.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/win32/res/resource.rc -------------------------------------------------------------------------------- /win32/resource.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnderainLovelace/KuroScripter/12695f6cf9c49af0df0da3d6855ff121c64033a9/win32/resource.aps --------------------------------------------------------------------------------